Magento 2: How to Apply Coupon Code based on Product Custom Option
I want to create coupon code for specific product and custom option
E.g.
Sku: Test1
Custom Option:
Name: Demo Custom Option
Option Type: Field
I want to apply the coupon code if customer have enter the name, if not filled customer will not allow to apply the coupon.
magento2 custom-options coupon coupon-codes promotions
add a comment |
I want to create coupon code for specific product and custom option
E.g.
Sku: Test1
Custom Option:
Name: Demo Custom Option
Option Type: Field
I want to apply the coupon code if customer have enter the name, if not filled customer will not allow to apply the coupon.
magento2 custom-options coupon coupon-codes promotions
add a comment |
I want to create coupon code for specific product and custom option
E.g.
Sku: Test1
Custom Option:
Name: Demo Custom Option
Option Type: Field
I want to apply the coupon code if customer have enter the name, if not filled customer will not allow to apply the coupon.
magento2 custom-options coupon coupon-codes promotions
I want to create coupon code for specific product and custom option
E.g.
Sku: Test1
Custom Option:
Name: Demo Custom Option
Option Type: Field
I want to apply the coupon code if customer have enter the name, if not filled customer will not allow to apply the coupon.
magento2 custom-options coupon coupon-codes promotions
magento2 custom-options coupon coupon-codes promotions
asked 3 hours ago
Ashish Viradiya
497219
497219
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The solution is to use a plugin on MagentoQuoteModelCouponManagement
on the set
method:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelCouponManagement">
<plugin name="checkout_coupon_apply"
type="VendorModulePluginCheckoutCouponApply"/>
</type>
</config>
Create plugin:
<?php
namespace VendorModulePlugin;
class CheckoutCouponApply {
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
/**
* Quote repository.
*
* @var MagentoQuoteApiCartRepositoryInterface
*/
protected $quoteRepository;
/**
* Constructs a coupon read service object.
*
* @param MagentoQuoteApiCartRepositoryInterface $quoteRepository Quote repository.
*/
public function __construct(
MagentoQuoteApiCartRepositoryInterface $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
foreach ($this->quoteRepository->getAllItems() as $value) {
// Do what you need to do
// throw new CouldNotSaveException(__('You will not allow to use coupon code'));
}
}
}
}
add a comment |
You can create coupon code via backend.
Steps : Login to backend -> Menu -> Marketing -> Cart Price Rule ->
Add New Rule
Under that Form you will find conditions section, Under That section you can add conditions based on your criteria.
You will see Attribute Drop-down Under Condition section.
If your Attribute not there then, you need to follow step,
Backend Login -> Menu -> Stores -> Products (Attribute section) ->
search your attribute - > Click on that Row
Under that page you will find storefront properties, in that change the value of Use for Promo Rule Conditions to YES .
Run php bin/magento c:f command via Terminal.
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
|
show 2 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256698%2fmagento-2-how-to-apply-coupon-code-based-on-product-custom-option%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The solution is to use a plugin on MagentoQuoteModelCouponManagement
on the set
method:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelCouponManagement">
<plugin name="checkout_coupon_apply"
type="VendorModulePluginCheckoutCouponApply"/>
</type>
</config>
Create plugin:
<?php
namespace VendorModulePlugin;
class CheckoutCouponApply {
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
/**
* Quote repository.
*
* @var MagentoQuoteApiCartRepositoryInterface
*/
protected $quoteRepository;
/**
* Constructs a coupon read service object.
*
* @param MagentoQuoteApiCartRepositoryInterface $quoteRepository Quote repository.
*/
public function __construct(
MagentoQuoteApiCartRepositoryInterface $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
foreach ($this->quoteRepository->getAllItems() as $value) {
// Do what you need to do
// throw new CouldNotSaveException(__('You will not allow to use coupon code'));
}
}
}
}
add a comment |
The solution is to use a plugin on MagentoQuoteModelCouponManagement
on the set
method:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelCouponManagement">
<plugin name="checkout_coupon_apply"
type="VendorModulePluginCheckoutCouponApply"/>
</type>
</config>
Create plugin:
<?php
namespace VendorModulePlugin;
class CheckoutCouponApply {
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
/**
* Quote repository.
*
* @var MagentoQuoteApiCartRepositoryInterface
*/
protected $quoteRepository;
/**
* Constructs a coupon read service object.
*
* @param MagentoQuoteApiCartRepositoryInterface $quoteRepository Quote repository.
*/
public function __construct(
MagentoQuoteApiCartRepositoryInterface $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
foreach ($this->quoteRepository->getAllItems() as $value) {
// Do what you need to do
// throw new CouldNotSaveException(__('You will not allow to use coupon code'));
}
}
}
}
add a comment |
The solution is to use a plugin on MagentoQuoteModelCouponManagement
on the set
method:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelCouponManagement">
<plugin name="checkout_coupon_apply"
type="VendorModulePluginCheckoutCouponApply"/>
</type>
</config>
Create plugin:
<?php
namespace VendorModulePlugin;
class CheckoutCouponApply {
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
/**
* Quote repository.
*
* @var MagentoQuoteApiCartRepositoryInterface
*/
protected $quoteRepository;
/**
* Constructs a coupon read service object.
*
* @param MagentoQuoteApiCartRepositoryInterface $quoteRepository Quote repository.
*/
public function __construct(
MagentoQuoteApiCartRepositoryInterface $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
foreach ($this->quoteRepository->getAllItems() as $value) {
// Do what you need to do
// throw new CouldNotSaveException(__('You will not allow to use coupon code'));
}
}
}
}
The solution is to use a plugin on MagentoQuoteModelCouponManagement
on the set
method:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoQuoteModelCouponManagement">
<plugin name="checkout_coupon_apply"
type="VendorModulePluginCheckoutCouponApply"/>
</type>
</config>
Create plugin:
<?php
namespace VendorModulePlugin;
class CheckoutCouponApply {
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
/**
* Quote repository.
*
* @var MagentoQuoteApiCartRepositoryInterface
*/
protected $quoteRepository;
/**
* Constructs a coupon read service object.
*
* @param MagentoQuoteApiCartRepositoryInterface $quoteRepository Quote repository.
*/
public function __construct(
MagentoQuoteApiCartRepositoryInterface $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function beforeSet(CouponManagement $subject, $cartId, $couponCode)
{
foreach ($this->quoteRepository->getAllItems() as $value) {
// Do what you need to do
// throw new CouldNotSaveException(__('You will not allow to use coupon code'));
}
}
}
}
answered 1 hour ago
Ashish Viradiya
497219
497219
add a comment |
add a comment |
You can create coupon code via backend.
Steps : Login to backend -> Menu -> Marketing -> Cart Price Rule ->
Add New Rule
Under that Form you will find conditions section, Under That section you can add conditions based on your criteria.
You will see Attribute Drop-down Under Condition section.
If your Attribute not there then, you need to follow step,
Backend Login -> Menu -> Stores -> Products (Attribute section) ->
search your attribute - > Click on that Row
Under that page you will find storefront properties, in that change the value of Use for Promo Rule Conditions to YES .
Run php bin/magento c:f command via Terminal.
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
|
show 2 more comments
You can create coupon code via backend.
Steps : Login to backend -> Menu -> Marketing -> Cart Price Rule ->
Add New Rule
Under that Form you will find conditions section, Under That section you can add conditions based on your criteria.
You will see Attribute Drop-down Under Condition section.
If your Attribute not there then, you need to follow step,
Backend Login -> Menu -> Stores -> Products (Attribute section) ->
search your attribute - > Click on that Row
Under that page you will find storefront properties, in that change the value of Use for Promo Rule Conditions to YES .
Run php bin/magento c:f command via Terminal.
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
|
show 2 more comments
You can create coupon code via backend.
Steps : Login to backend -> Menu -> Marketing -> Cart Price Rule ->
Add New Rule
Under that Form you will find conditions section, Under That section you can add conditions based on your criteria.
You will see Attribute Drop-down Under Condition section.
If your Attribute not there then, you need to follow step,
Backend Login -> Menu -> Stores -> Products (Attribute section) ->
search your attribute - > Click on that Row
Under that page you will find storefront properties, in that change the value of Use for Promo Rule Conditions to YES .
Run php bin/magento c:f command via Terminal.
You can create coupon code via backend.
Steps : Login to backend -> Menu -> Marketing -> Cart Price Rule ->
Add New Rule
Under that Form you will find conditions section, Under That section you can add conditions based on your criteria.
You will see Attribute Drop-down Under Condition section.
If your Attribute not there then, you need to follow step,
Backend Login -> Menu -> Stores -> Products (Attribute section) ->
search your attribute - > Click on that Row
Under that page you will find storefront properties, in that change the value of Use for Promo Rule Conditions to YES .
Run php bin/magento c:f command via Terminal.
answered 2 hours ago
Nauman m. Mansuri
1367
1367
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
|
show 2 more comments
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
How can i check condition for specific product custom option?
– Ashish Viradiya
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
Specify your conditions under Condition section in Add new rule page.
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
check this image ibb.co/598Dzgd
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
click on product Attribute combinations -> ibb.co/LJ5qnfG
– Nauman m. Mansuri
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
I am talking about Product Customizable Options.
– Ashish Viradiya
2 hours ago
|
show 2 more comments
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256698%2fmagento-2-how-to-apply-coupon-code-based-on-product-custom-option%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown