Magento 2: How to Apply Coupon Code based on Product Customizable Option
Clash Royale CLAN TAG#URR8PPP
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
edited Jan 7 at 10:02
Ashish Viradiya
asked Jan 4 at 5:45
Ashish ViradiyaAshish Viradiya
558420
558420
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.
add a comment |
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-customizable-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 Jan 4 at 7:10
Ashish ViradiyaAshish Viradiya
558420
558420
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.
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.
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.
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 Jan 4 at 6:02
Nauman m. MansuriNauman m. Mansuri
1968
1968
add a comment |
add a comment |
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.
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-customizable-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