Magento coupon codes - only one coupon / guest customer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm using magento 1.7 and I have the following issue with coupon codes.
I've set up a cart rule which uses a coupon code. I want customers to be able to use this coupon only once, so I set up Uses per Customer to 1. For logged in customers the rule works, and they can use the coupon only once for an order, if they try to place another order using the same coupon code they get an error, which is the correct behaviour.
The problem is that I need GUEST (NOT LOGGED IN) customers to use the same coupon code, and for them the rule for 1 use per customer doesn't work. I've tested it and I can place an unlimited number of orders using the same coupon code. Is there any way to check if a guest customer has already placed an order using a coupon code? Any help will be greatly appreaciated.
Thanks.
magento-1.7 coupon
add a comment |
I'm using magento 1.7 and I have the following issue with coupon codes.
I've set up a cart rule which uses a coupon code. I want customers to be able to use this coupon only once, so I set up Uses per Customer to 1. For logged in customers the rule works, and they can use the coupon only once for an order, if they try to place another order using the same coupon code they get an error, which is the correct behaviour.
The problem is that I need GUEST (NOT LOGGED IN) customers to use the same coupon code, and for them the rule for 1 use per customer doesn't work. I've tested it and I can place an unlimited number of orders using the same coupon code. Is there any way to check if a guest customer has already placed an order using a coupon code? Any help will be greatly appreaciated.
Thanks.
magento-1.7 coupon
1
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20
add a comment |
I'm using magento 1.7 and I have the following issue with coupon codes.
I've set up a cart rule which uses a coupon code. I want customers to be able to use this coupon only once, so I set up Uses per Customer to 1. For logged in customers the rule works, and they can use the coupon only once for an order, if they try to place another order using the same coupon code they get an error, which is the correct behaviour.
The problem is that I need GUEST (NOT LOGGED IN) customers to use the same coupon code, and for them the rule for 1 use per customer doesn't work. I've tested it and I can place an unlimited number of orders using the same coupon code. Is there any way to check if a guest customer has already placed an order using a coupon code? Any help will be greatly appreaciated.
Thanks.
magento-1.7 coupon
I'm using magento 1.7 and I have the following issue with coupon codes.
I've set up a cart rule which uses a coupon code. I want customers to be able to use this coupon only once, so I set up Uses per Customer to 1. For logged in customers the rule works, and they can use the coupon only once for an order, if they try to place another order using the same coupon code they get an error, which is the correct behaviour.
The problem is that I need GUEST (NOT LOGGED IN) customers to use the same coupon code, and for them the rule for 1 use per customer doesn't work. I've tested it and I can place an unlimited number of orders using the same coupon code. Is there any way to check if a guest customer has already placed an order using a coupon code? Any help will be greatly appreaciated.
Thanks.
magento-1.7 coupon
magento-1.7 coupon
edited Jun 14 '13 at 18:51
Marius♦
168k28324694
168k28324694
asked Jun 14 '13 at 18:49
Clain AlexandruClain Alexandru
31124
31124
1
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20
add a comment |
1
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20
1
1
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20
add a comment |
6 Answers
6
active
oldest
votes
The only way to solve this problem is to either require users to create a customer account prior to using this coupon or implement custom logic to validate against billing and/or shipping information to try and accomplish the same thing. Anything else would be unreliably flakey. Checking for orders placed with the same info is already pretty flaky, complicated, but doable.
My recommendation is simply not to do this and require users to login. If you have a coupon and give the customer a message telling them they need to login or create an account to use it, they will do that to save a few bucks.
add a comment |
davidalger is right. Another solution would be to "Use Auto Generation" and give out custom codes that are only usable once (Uses per Coupon). This would work even for "Not Logged In" users.
add a comment |
In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.
add a comment |
Don't think this is possible...
The definition of a guest is that we do not know his identity, so how can we determine whether he has already used the code?
So its either we allowed "not logged in customers" to use it or we don't, don't think there is another way, at least not for Magento....
add a comment |
I've seen many sites validate based on a combination of Shipping Address, Email Address, and Phone number to determine if you are a repeat customer. The 5% or less of people who would be able to circumvent that when ordering a physical product that needs a delivery address would be very small, and so it is worth implementing. A 100% perfect solution is not required here at the cost of forcing all users to create accounts. Does anyone know of a Magento extension for this?
add a comment |
One possibility of achieving this would be to create a custom module with an event observer on 'controller_action_postdispatch_checkout_onepage_saveBilling'-event. In your module's config.xml under the global/events node put this:
<controller_action_postdispatch_checkout_onepage_saveBilling><!-- when a billing address is saved check for double discounts -->
<observers>
<yourmodule_observer_check_double_discount>
<type>singleton</type>
<class>namespace_yourmodule/observer</class>
<method>checkForDoubleDiscount</method>
</yourmodule_observer_check_double_discount>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
When a customer saves the billing address you might apply your custom validation logic in your event observer like this:
public function checkForDoubleDiscount($observer) {
$sess = Mage::getSingleton('checkout/session');
$quote = $sess->getQuote();
//check if quote has discount
$coupon_code = $quote->getCouponCode();
if($coupon_code){
//check if email address is set
if($email = $quote->getCustomerEmail()) {
//get salesrule
$coupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
//check if usage limit exists
if($maxuse = $rule->getUsesPerCustomer()) {
//get all orders of the customer
$order = Mage::getModel('sales/order');
$collection = $order->getCollection()
->addAttributeToFilter('customer_email',array('like'=>$email))
->addAttributeToFilter('coupon_code',array('like'=>$coupon_code));
//if max usage is reached, remove rule from quote
if($maxuse <= $collection->count()) {
$quote->setCouponCode('')->collectTotals()->save();
$message = Mage::helper('namespace_yourmodule');->__('Coupon Code %s has been cancelled, the usage limit has been reached', $coupon_code);
$result = array();
$result['error'] = '-1';
$result['message'] = $message;
print Mage::helper('core')->jsonEncode($result); exit;
break;
}
}
}
}
}
}
Please note: The above code requires the creation of a custom module, you can find a LOT of sources on how to do that on Google. You might as well use other Magento events or a more detailed, maybe address based validation which might better suit your needs, this is just a basic example way of how to do it by simply validating an email address. I also suggest to implement a strtolower-like conversion of the coupon codes or something like that because query results might change with the use of letter cases in the code (Magento treats 'AABB' and 'aabb' coupon codes similar, but your database might not)
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%2f4785%2fmagento-coupon-codes-only-one-coupon-guest-customer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
The only way to solve this problem is to either require users to create a customer account prior to using this coupon or implement custom logic to validate against billing and/or shipping information to try and accomplish the same thing. Anything else would be unreliably flakey. Checking for orders placed with the same info is already pretty flaky, complicated, but doable.
My recommendation is simply not to do this and require users to login. If you have a coupon and give the customer a message telling them they need to login or create an account to use it, they will do that to save a few bucks.
add a comment |
The only way to solve this problem is to either require users to create a customer account prior to using this coupon or implement custom logic to validate against billing and/or shipping information to try and accomplish the same thing. Anything else would be unreliably flakey. Checking for orders placed with the same info is already pretty flaky, complicated, but doable.
My recommendation is simply not to do this and require users to login. If you have a coupon and give the customer a message telling them they need to login or create an account to use it, they will do that to save a few bucks.
add a comment |
The only way to solve this problem is to either require users to create a customer account prior to using this coupon or implement custom logic to validate against billing and/or shipping information to try and accomplish the same thing. Anything else would be unreliably flakey. Checking for orders placed with the same info is already pretty flaky, complicated, but doable.
My recommendation is simply not to do this and require users to login. If you have a coupon and give the customer a message telling them they need to login or create an account to use it, they will do that to save a few bucks.
The only way to solve this problem is to either require users to create a customer account prior to using this coupon or implement custom logic to validate against billing and/or shipping information to try and accomplish the same thing. Anything else would be unreliably flakey. Checking for orders placed with the same info is already pretty flaky, complicated, but doable.
My recommendation is simply not to do this and require users to login. If you have a coupon and give the customer a message telling them they need to login or create an account to use it, they will do that to save a few bucks.
answered Jun 14 '13 at 21:59
davidalgerdavidalger
7,07112547
7,07112547
add a comment |
add a comment |
davidalger is right. Another solution would be to "Use Auto Generation" and give out custom codes that are only usable once (Uses per Coupon). This would work even for "Not Logged In" users.
add a comment |
davidalger is right. Another solution would be to "Use Auto Generation" and give out custom codes that are only usable once (Uses per Coupon). This would work even for "Not Logged In" users.
add a comment |
davidalger is right. Another solution would be to "Use Auto Generation" and give out custom codes that are only usable once (Uses per Coupon). This would work even for "Not Logged In" users.
davidalger is right. Another solution would be to "Use Auto Generation" and give out custom codes that are only usable once (Uses per Coupon). This would work even for "Not Logged In" users.
edited Apr 13 '17 at 12:55
Community♦
1
1
answered Sep 23 '13 at 10:38
PiTheNumberPiTheNumber
1,928104167
1,928104167
add a comment |
add a comment |
In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.
add a comment |
In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.
add a comment |
In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.
In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.
answered Sep 12 '13 at 21:27
AmastyAmasty
312
312
add a comment |
add a comment |
Don't think this is possible...
The definition of a guest is that we do not know his identity, so how can we determine whether he has already used the code?
So its either we allowed "not logged in customers" to use it or we don't, don't think there is another way, at least not for Magento....
add a comment |
Don't think this is possible...
The definition of a guest is that we do not know his identity, so how can we determine whether he has already used the code?
So its either we allowed "not logged in customers" to use it or we don't, don't think there is another way, at least not for Magento....
add a comment |
Don't think this is possible...
The definition of a guest is that we do not know his identity, so how can we determine whether he has already used the code?
So its either we allowed "not logged in customers" to use it or we don't, don't think there is another way, at least not for Magento....
Don't think this is possible...
The definition of a guest is that we do not know his identity, so how can we determine whether he has already used the code?
So its either we allowed "not logged in customers" to use it or we don't, don't think there is another way, at least not for Magento....
answered Aug 19 '14 at 8:36
KenKen
211
211
add a comment |
add a comment |
I've seen many sites validate based on a combination of Shipping Address, Email Address, and Phone number to determine if you are a repeat customer. The 5% or less of people who would be able to circumvent that when ordering a physical product that needs a delivery address would be very small, and so it is worth implementing. A 100% perfect solution is not required here at the cost of forcing all users to create accounts. Does anyone know of a Magento extension for this?
add a comment |
I've seen many sites validate based on a combination of Shipping Address, Email Address, and Phone number to determine if you are a repeat customer. The 5% or less of people who would be able to circumvent that when ordering a physical product that needs a delivery address would be very small, and so it is worth implementing. A 100% perfect solution is not required here at the cost of forcing all users to create accounts. Does anyone know of a Magento extension for this?
add a comment |
I've seen many sites validate based on a combination of Shipping Address, Email Address, and Phone number to determine if you are a repeat customer. The 5% or less of people who would be able to circumvent that when ordering a physical product that needs a delivery address would be very small, and so it is worth implementing. A 100% perfect solution is not required here at the cost of forcing all users to create accounts. Does anyone know of a Magento extension for this?
I've seen many sites validate based on a combination of Shipping Address, Email Address, and Phone number to determine if you are a repeat customer. The 5% or less of people who would be able to circumvent that when ordering a physical product that needs a delivery address would be very small, and so it is worth implementing. A 100% perfect solution is not required here at the cost of forcing all users to create accounts. Does anyone know of a Magento extension for this?
answered Feb 1 '16 at 12:41
EricEric
111
111
add a comment |
add a comment |
One possibility of achieving this would be to create a custom module with an event observer on 'controller_action_postdispatch_checkout_onepage_saveBilling'-event. In your module's config.xml under the global/events node put this:
<controller_action_postdispatch_checkout_onepage_saveBilling><!-- when a billing address is saved check for double discounts -->
<observers>
<yourmodule_observer_check_double_discount>
<type>singleton</type>
<class>namespace_yourmodule/observer</class>
<method>checkForDoubleDiscount</method>
</yourmodule_observer_check_double_discount>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
When a customer saves the billing address you might apply your custom validation logic in your event observer like this:
public function checkForDoubleDiscount($observer) {
$sess = Mage::getSingleton('checkout/session');
$quote = $sess->getQuote();
//check if quote has discount
$coupon_code = $quote->getCouponCode();
if($coupon_code){
//check if email address is set
if($email = $quote->getCustomerEmail()) {
//get salesrule
$coupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
//check if usage limit exists
if($maxuse = $rule->getUsesPerCustomer()) {
//get all orders of the customer
$order = Mage::getModel('sales/order');
$collection = $order->getCollection()
->addAttributeToFilter('customer_email',array('like'=>$email))
->addAttributeToFilter('coupon_code',array('like'=>$coupon_code));
//if max usage is reached, remove rule from quote
if($maxuse <= $collection->count()) {
$quote->setCouponCode('')->collectTotals()->save();
$message = Mage::helper('namespace_yourmodule');->__('Coupon Code %s has been cancelled, the usage limit has been reached', $coupon_code);
$result = array();
$result['error'] = '-1';
$result['message'] = $message;
print Mage::helper('core')->jsonEncode($result); exit;
break;
}
}
}
}
}
}
Please note: The above code requires the creation of a custom module, you can find a LOT of sources on how to do that on Google. You might as well use other Magento events or a more detailed, maybe address based validation which might better suit your needs, this is just a basic example way of how to do it by simply validating an email address. I also suggest to implement a strtolower-like conversion of the coupon codes or something like that because query results might change with the use of letter cases in the code (Magento treats 'AABB' and 'aabb' coupon codes similar, but your database might not)
add a comment |
One possibility of achieving this would be to create a custom module with an event observer on 'controller_action_postdispatch_checkout_onepage_saveBilling'-event. In your module's config.xml under the global/events node put this:
<controller_action_postdispatch_checkout_onepage_saveBilling><!-- when a billing address is saved check for double discounts -->
<observers>
<yourmodule_observer_check_double_discount>
<type>singleton</type>
<class>namespace_yourmodule/observer</class>
<method>checkForDoubleDiscount</method>
</yourmodule_observer_check_double_discount>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
When a customer saves the billing address you might apply your custom validation logic in your event observer like this:
public function checkForDoubleDiscount($observer) {
$sess = Mage::getSingleton('checkout/session');
$quote = $sess->getQuote();
//check if quote has discount
$coupon_code = $quote->getCouponCode();
if($coupon_code){
//check if email address is set
if($email = $quote->getCustomerEmail()) {
//get salesrule
$coupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
//check if usage limit exists
if($maxuse = $rule->getUsesPerCustomer()) {
//get all orders of the customer
$order = Mage::getModel('sales/order');
$collection = $order->getCollection()
->addAttributeToFilter('customer_email',array('like'=>$email))
->addAttributeToFilter('coupon_code',array('like'=>$coupon_code));
//if max usage is reached, remove rule from quote
if($maxuse <= $collection->count()) {
$quote->setCouponCode('')->collectTotals()->save();
$message = Mage::helper('namespace_yourmodule');->__('Coupon Code %s has been cancelled, the usage limit has been reached', $coupon_code);
$result = array();
$result['error'] = '-1';
$result['message'] = $message;
print Mage::helper('core')->jsonEncode($result); exit;
break;
}
}
}
}
}
}
Please note: The above code requires the creation of a custom module, you can find a LOT of sources on how to do that on Google. You might as well use other Magento events or a more detailed, maybe address based validation which might better suit your needs, this is just a basic example way of how to do it by simply validating an email address. I also suggest to implement a strtolower-like conversion of the coupon codes or something like that because query results might change with the use of letter cases in the code (Magento treats 'AABB' and 'aabb' coupon codes similar, but your database might not)
add a comment |
One possibility of achieving this would be to create a custom module with an event observer on 'controller_action_postdispatch_checkout_onepage_saveBilling'-event. In your module's config.xml under the global/events node put this:
<controller_action_postdispatch_checkout_onepage_saveBilling><!-- when a billing address is saved check for double discounts -->
<observers>
<yourmodule_observer_check_double_discount>
<type>singleton</type>
<class>namespace_yourmodule/observer</class>
<method>checkForDoubleDiscount</method>
</yourmodule_observer_check_double_discount>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
When a customer saves the billing address you might apply your custom validation logic in your event observer like this:
public function checkForDoubleDiscount($observer) {
$sess = Mage::getSingleton('checkout/session');
$quote = $sess->getQuote();
//check if quote has discount
$coupon_code = $quote->getCouponCode();
if($coupon_code){
//check if email address is set
if($email = $quote->getCustomerEmail()) {
//get salesrule
$coupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
//check if usage limit exists
if($maxuse = $rule->getUsesPerCustomer()) {
//get all orders of the customer
$order = Mage::getModel('sales/order');
$collection = $order->getCollection()
->addAttributeToFilter('customer_email',array('like'=>$email))
->addAttributeToFilter('coupon_code',array('like'=>$coupon_code));
//if max usage is reached, remove rule from quote
if($maxuse <= $collection->count()) {
$quote->setCouponCode('')->collectTotals()->save();
$message = Mage::helper('namespace_yourmodule');->__('Coupon Code %s has been cancelled, the usage limit has been reached', $coupon_code);
$result = array();
$result['error'] = '-1';
$result['message'] = $message;
print Mage::helper('core')->jsonEncode($result); exit;
break;
}
}
}
}
}
}
Please note: The above code requires the creation of a custom module, you can find a LOT of sources on how to do that on Google. You might as well use other Magento events or a more detailed, maybe address based validation which might better suit your needs, this is just a basic example way of how to do it by simply validating an email address. I also suggest to implement a strtolower-like conversion of the coupon codes or something like that because query results might change with the use of letter cases in the code (Magento treats 'AABB' and 'aabb' coupon codes similar, but your database might not)
One possibility of achieving this would be to create a custom module with an event observer on 'controller_action_postdispatch_checkout_onepage_saveBilling'-event. In your module's config.xml under the global/events node put this:
<controller_action_postdispatch_checkout_onepage_saveBilling><!-- when a billing address is saved check for double discounts -->
<observers>
<yourmodule_observer_check_double_discount>
<type>singleton</type>
<class>namespace_yourmodule/observer</class>
<method>checkForDoubleDiscount</method>
</yourmodule_observer_check_double_discount>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
When a customer saves the billing address you might apply your custom validation logic in your event observer like this:
public function checkForDoubleDiscount($observer) {
$sess = Mage::getSingleton('checkout/session');
$quote = $sess->getQuote();
//check if quote has discount
$coupon_code = $quote->getCouponCode();
if($coupon_code){
//check if email address is set
if($email = $quote->getCustomerEmail()) {
//get salesrule
$coupon = Mage::getModel('salesrule/coupon')->load($coupon_code, 'code');
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
//check if usage limit exists
if($maxuse = $rule->getUsesPerCustomer()) {
//get all orders of the customer
$order = Mage::getModel('sales/order');
$collection = $order->getCollection()
->addAttributeToFilter('customer_email',array('like'=>$email))
->addAttributeToFilter('coupon_code',array('like'=>$coupon_code));
//if max usage is reached, remove rule from quote
if($maxuse <= $collection->count()) {
$quote->setCouponCode('')->collectTotals()->save();
$message = Mage::helper('namespace_yourmodule');->__('Coupon Code %s has been cancelled, the usage limit has been reached', $coupon_code);
$result = array();
$result['error'] = '-1';
$result['message'] = $message;
print Mage::helper('core')->jsonEncode($result); exit;
break;
}
}
}
}
}
}
Please note: The above code requires the creation of a custom module, you can find a LOT of sources on how to do that on Google. You might as well use other Magento events or a more detailed, maybe address based validation which might better suit your needs, this is just a basic example way of how to do it by simply validating an email address. I also suggest to implement a strtolower-like conversion of the coupon codes or something like that because query results might change with the use of letter cases in the code (Magento treats 'AABB' and 'aabb' coupon codes similar, but your database might not)
answered 14 mins ago
mybinaryromancemybinaryromance
13111
13111
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%2f4785%2fmagento-coupon-codes-only-one-coupon-guest-customer%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
1
Question is easy: How to identify a guest? Answer: There is no identification. One time per customer means: I register ten accounts and can use the coupon ten times. Don't allow the account for guests is the easiest way everything else is hacky and bad for the customer.
– Fabian Blechschmidt
Jun 14 '13 at 22:14
@FabianBlechschmidt the answer would be: email address, just like it is required, used (and bypassed per your suggestion) for logged in users.
– Jan Tomka
Jun 5 '14 at 6:26
My experience is, people are creating dozends of mail addresses to get a 10€ discount. So if you ask me, it is not worth the implementation time.
– Fabian Blechschmidt
Jun 5 '14 at 12:54
@Fabian+Jan Maybe not the definite solution. But email address stops another large % of users ... and in the end it is a better solution than no solution. SO I would vote for a (minimal) match on email ... it is the most we can do
– snh_nl
Nov 19 '14 at 20:20