Make a coupon valid for one month from the date of registering
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I want to make a coupon time bound if a user registers on the website I will send him a coupon e.g. : CHJU20
that will be valid for only one month from the date of registering.
It should not apply after 1 month. Now if a new customer registers the same should happen with him too
magento-1.9
add a comment |
I want to make a coupon time bound if a user registers on the website I will send him a coupon e.g. : CHJU20
that will be valid for only one month from the date of registering.
It should not apply after 1 month. Now if a new customer registers the same should happen with him too
magento-1.9
add a comment |
I want to make a coupon time bound if a user registers on the website I will send him a coupon e.g. : CHJU20
that will be valid for only one month from the date of registering.
It should not apply after 1 month. Now if a new customer registers the same should happen with him too
magento-1.9
I want to make a coupon time bound if a user registers on the website I will send him a coupon e.g. : CHJU20
that will be valid for only one month from the date of registering.
It should not apply after 1 month. Now if a new customer registers the same should happen with him too
magento-1.9
magento-1.9
edited 18 mins ago
Magedev2301
1159
1159
asked Oct 17 '17 at 10:30
Faizan59Faizan59
64
64
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I have created coupon code programmatically.
First of all you need to create shopping cart price rule in Magento Admin >> Promotions >> Shopping Cart Price Rules
Make sure coupon code should be auto generated. So you must have to select Use Auto Generation
as per below screen shot.
Then you can use below code.
<?php
$rule = Mage::getModel('salesrule/rule')->load(1); //1 = ID of coupon
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count' => 1,
'format' => 'alphanumeric',
'prefix' => 'A', // if you require
'suffix' => 'B', // if you require
'length' => 6,
'from_date' => '18/11/2017',
'to_date' => '12/12/2017', // if require end date
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setLength(!empty($parameters['length']) ? (int) $parameters['length'] : 6);
$generator->setPrefix(!empty($parameters['prefix']) ? $parameters['prefix'] : '');
$generator->setSuffix(!empty($parameters['suffix']) ? $parameters['suffix'] : '');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes = $code;
}
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
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%2f197599%2fmake-a-coupon-valid-for-one-month-from-the-date-of-registering%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
I have created coupon code programmatically.
First of all you need to create shopping cart price rule in Magento Admin >> Promotions >> Shopping Cart Price Rules
Make sure coupon code should be auto generated. So you must have to select Use Auto Generation
as per below screen shot.
Then you can use below code.
<?php
$rule = Mage::getModel('salesrule/rule')->load(1); //1 = ID of coupon
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count' => 1,
'format' => 'alphanumeric',
'prefix' => 'A', // if you require
'suffix' => 'B', // if you require
'length' => 6,
'from_date' => '18/11/2017',
'to_date' => '12/12/2017', // if require end date
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setLength(!empty($parameters['length']) ? (int) $parameters['length'] : 6);
$generator->setPrefix(!empty($parameters['prefix']) ? $parameters['prefix'] : '');
$generator->setSuffix(!empty($parameters['suffix']) ? $parameters['suffix'] : '');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes = $code;
}
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
add a comment |
I have created coupon code programmatically.
First of all you need to create shopping cart price rule in Magento Admin >> Promotions >> Shopping Cart Price Rules
Make sure coupon code should be auto generated. So you must have to select Use Auto Generation
as per below screen shot.
Then you can use below code.
<?php
$rule = Mage::getModel('salesrule/rule')->load(1); //1 = ID of coupon
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count' => 1,
'format' => 'alphanumeric',
'prefix' => 'A', // if you require
'suffix' => 'B', // if you require
'length' => 6,
'from_date' => '18/11/2017',
'to_date' => '12/12/2017', // if require end date
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setLength(!empty($parameters['length']) ? (int) $parameters['length'] : 6);
$generator->setPrefix(!empty($parameters['prefix']) ? $parameters['prefix'] : '');
$generator->setSuffix(!empty($parameters['suffix']) ? $parameters['suffix'] : '');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes = $code;
}
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
add a comment |
I have created coupon code programmatically.
First of all you need to create shopping cart price rule in Magento Admin >> Promotions >> Shopping Cart Price Rules
Make sure coupon code should be auto generated. So you must have to select Use Auto Generation
as per below screen shot.
Then you can use below code.
<?php
$rule = Mage::getModel('salesrule/rule')->load(1); //1 = ID of coupon
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count' => 1,
'format' => 'alphanumeric',
'prefix' => 'A', // if you require
'suffix' => 'B', // if you require
'length' => 6,
'from_date' => '18/11/2017',
'to_date' => '12/12/2017', // if require end date
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setLength(!empty($parameters['length']) ? (int) $parameters['length'] : 6);
$generator->setPrefix(!empty($parameters['prefix']) ? $parameters['prefix'] : '');
$generator->setSuffix(!empty($parameters['suffix']) ? $parameters['suffix'] : '');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes = $code;
}
I have created coupon code programmatically.
First of all you need to create shopping cart price rule in Magento Admin >> Promotions >> Shopping Cart Price Rules
Make sure coupon code should be auto generated. So you must have to select Use Auto Generation
as per below screen shot.
Then you can use below code.
<?php
$rule = Mage::getModel('salesrule/rule')->load(1); //1 = ID of coupon
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$parameters = array(
'count' => 1,
'format' => 'alphanumeric',
'prefix' => 'A', // if you require
'suffix' => 'B', // if you require
'length' => 6,
'from_date' => '18/11/2017',
'to_date' => '12/12/2017', // if require end date
);
if( !empty($parameters['format']) ){
switch( strtolower($parameters['format']) ){
case 'alphanumeric':
case 'alphanum':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC );
break;
case 'alphabetical':
case 'alpha':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL );
break;
case 'numeric':
case 'num':
$generator->setFormat( Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC );
break;
}
}
$generator->setLength(!empty($parameters['length']) ? (int) $parameters['length'] : 6);
$generator->setPrefix(!empty($parameters['prefix']) ? $parameters['prefix'] : '');
$generator->setSuffix(!empty($parameters['suffix']) ? $parameters['suffix'] : '');
$rule->setCouponCodeGenerator($generator);
$rule->setCouponType( Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO );
// Get as many coupons as you required
$count = !empty($parameters['count'])? (int) $parameters['count'] : 1;
$codes = array();
for( $i = 0; $i < $count; $i++ ){
$coupon = $rule->acquireCoupon();
$code = $coupon->getCode();
$codes = $code;
}
edited Oct 18 '17 at 6:17
answered Oct 18 '17 at 5:06
user26415
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
add a comment |
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
In which file i have to write this code.
– Faizan59
Oct 22 '17 at 6:57
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
And this coupon code is valid for one month from the date of registering ?
– Faizan59
Oct 22 '17 at 6:58
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
You need to create Observer on customer registration success. like : ka.lpe.sh/2014/08/21/… magento.stackexchange.com/questions/69067/…
– user26415
Oct 23 '17 at 5:25
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%2f197599%2fmake-a-coupon-valid-for-one-month-from-the-date-of-registering%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