magento 2 generate coupon code based on a rule programmaticallyMagento free shipping coupon breaking other coupons (and itself)Create Magento Coupon via APICreating a single random Magento couponDeleting a large number of Magento coupons (shopping cart price rules) programaticallyProgrammatically create auto generated coupon codes in Magento?Couldnot create a coupon code programmaticallyMagento: Stop coupon code automatically applyingMagento Promotion Rule Coupon Code is not ValidMagento Coupon code is getting applied but not showing reduced amount in totalHow we get welcome email with coupon code
Sum and average calculator
German equivalent to "going down the rabbit hole"
How do I get my neighbour to stop disturbing with loud music?
Quick Tilepaint Puzzles: Corridors and Corners
Using font to highlight a god's speech in dialogue
Are spot colors limited and why CMYK mix is not treated same as spot color mix?
How to save money by shopping at a variety of grocery stores?
How does the search space affect the speed of an ILP solver?
Why haven't the British protested Brexit as ardently as the Hong Kong protesters?
Can you use Apple Care+ without any checks (bringing just MacBook)?
Tikz: Draw simplified BLE-Stack
In what language did Túrin converse with Mím?
Calculate Landau's function
Break down the phrase "shitsurei shinakereba naranaindesu"
The correct way of compute indicator function in Mathematica
Heuristic argument for the Riemann Hypothesis
How to Flip Rotation from Positive to Negative?
Can two aircraft be allowed to stay on the same runway at the same time?
How can I portray a character with no fear of death, without them sounding utterly bored?
How were US credit cards verified in-store in the 1980's?
Which is the correct version of Mussorgsky's Pictures at an Exhibition?
What's the origin of the concept of alternate dimensions/realities?
Why doesn't Starship have four landing legs?
I failed to respond to a potential advisor
magento 2 generate coupon code based on a rule programmatically
Magento free shipping coupon breaking other coupons (and itself)Create Magento Coupon via APICreating a single random Magento couponDeleting a large number of Magento coupons (shopping cart price rules) programaticallyProgrammatically create auto generated coupon codes in Magento?Couldnot create a coupon code programmaticallyMagento: Stop coupon code automatically applyingMagento Promotion Rule Coupon Code is not ValidMagento Coupon code is getting applied but not showing reduced amount in totalHow we get welcome email with coupon code
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a rule created in Magento 2, e.g. 10% OFF, this rule uses auto generated coupon code, instead of a pre-assigned code.
I'd like to know how I can generate codes based on the rule programmatically.
NOTE: This is not about creating a new rule programmatically. I want to generate codes based on a existing rule, so I can add more codes when needed but doesn't have to create a new rule every time, e.g. when a customer subscribes our mailing list, I can execute the code to generate a new code under the same rule and send it to the subscriber.
I found this post, but this is about creating a new rule;
https://magento.stackexchange.com/questions/207311/magento2-2-programmatically-create-coupon
I found the solution for Magento 1:
https://mage2-blog.com/magento-1-programmatically-create-promotion-coupon-codes/
Thanks
magento magento2
add a comment |
I have a rule created in Magento 2, e.g. 10% OFF, this rule uses auto generated coupon code, instead of a pre-assigned code.
I'd like to know how I can generate codes based on the rule programmatically.
NOTE: This is not about creating a new rule programmatically. I want to generate codes based on a existing rule, so I can add more codes when needed but doesn't have to create a new rule every time, e.g. when a customer subscribes our mailing list, I can execute the code to generate a new code under the same rule and send it to the subscriber.
I found this post, but this is about creating a new rule;
https://magento.stackexchange.com/questions/207311/magento2-2-programmatically-create-coupon
I found the solution for Magento 1:
https://mage2-blog.com/magento-1-programmatically-create-promotion-coupon-codes/
Thanks
magento magento2
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35
add a comment |
I have a rule created in Magento 2, e.g. 10% OFF, this rule uses auto generated coupon code, instead of a pre-assigned code.
I'd like to know how I can generate codes based on the rule programmatically.
NOTE: This is not about creating a new rule programmatically. I want to generate codes based on a existing rule, so I can add more codes when needed but doesn't have to create a new rule every time, e.g. when a customer subscribes our mailing list, I can execute the code to generate a new code under the same rule and send it to the subscriber.
I found this post, but this is about creating a new rule;
https://magento.stackexchange.com/questions/207311/magento2-2-programmatically-create-coupon
I found the solution for Magento 1:
https://mage2-blog.com/magento-1-programmatically-create-promotion-coupon-codes/
Thanks
magento magento2
I have a rule created in Magento 2, e.g. 10% OFF, this rule uses auto generated coupon code, instead of a pre-assigned code.
I'd like to know how I can generate codes based on the rule programmatically.
NOTE: This is not about creating a new rule programmatically. I want to generate codes based on a existing rule, so I can add more codes when needed but doesn't have to create a new rule every time, e.g. when a customer subscribes our mailing list, I can execute the code to generate a new code under the same rule and send it to the subscriber.
I found this post, but this is about creating a new rule;
https://magento.stackexchange.com/questions/207311/magento2-2-programmatically-create-coupon
I found the solution for Magento 1:
https://mage2-blog.com/magento-1-programmatically-create-promotion-coupon-codes/
Thanks
magento magento2
magento magento2
asked Mar 27 at 23:20
JerryJerry
162 bronze badges
162 bronze badges
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35
add a comment |
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35
add a comment |
1 Answer
1
active
oldest
votes
It is actually easier than I thought. Code below worked for me:
$couponGenerator = $objectManager->create('MagentoSalesRuleModelCouponGenerator');
$data = array(
'rule_id' => $rule->getId(),
'qty' => '1',
'length' => '12',
'format' => 'alphanum',
'prefix' => 'pre',
'suffix' => 'suf',
);
$codes = $couponGenerator->generateCodes($data);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f55387944%2fmagento-2-generate-coupon-code-based-on-a-rule-programmatically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is actually easier than I thought. Code below worked for me:
$couponGenerator = $objectManager->create('MagentoSalesRuleModelCouponGenerator');
$data = array(
'rule_id' => $rule->getId(),
'qty' => '1',
'length' => '12',
'format' => 'alphanum',
'prefix' => 'pre',
'suffix' => 'suf',
);
$codes = $couponGenerator->generateCodes($data);
add a comment |
It is actually easier than I thought. Code below worked for me:
$couponGenerator = $objectManager->create('MagentoSalesRuleModelCouponGenerator');
$data = array(
'rule_id' => $rule->getId(),
'qty' => '1',
'length' => '12',
'format' => 'alphanum',
'prefix' => 'pre',
'suffix' => 'suf',
);
$codes = $couponGenerator->generateCodes($data);
add a comment |
It is actually easier than I thought. Code below worked for me:
$couponGenerator = $objectManager->create('MagentoSalesRuleModelCouponGenerator');
$data = array(
'rule_id' => $rule->getId(),
'qty' => '1',
'length' => '12',
'format' => 'alphanum',
'prefix' => 'pre',
'suffix' => 'suf',
);
$codes = $couponGenerator->generateCodes($data);
It is actually easier than I thought. Code below worked for me:
$couponGenerator = $objectManager->create('MagentoSalesRuleModelCouponGenerator');
$data = array(
'rule_id' => $rule->getId(),
'qty' => '1',
'length' => '12',
'format' => 'alphanum',
'prefix' => 'pre',
'suffix' => 'suf',
);
$codes = $couponGenerator->generateCodes($data);
answered Mar 29 at 22:15
JerryJerry
162 bronze badges
162 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55387944%2fmagento-2-generate-coupon-code-based-on-a-rule-programmatically%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
Right now you've kind of given us a spec, some possibly related code, and asked us to do your coding - and that's not how this site works. You need to digest the links you've provided and then present us with the code that you want to try, letting us know what is and isn't working and how you want it to work. We can then help you fix your code.
– Enigmativity
Mar 27 at 23:35