Magento coupon codes - only one coupon / guest customer





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4















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.










share|improve this question




















  • 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


















4















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.










share|improve this question




















  • 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














4












4








4








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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










6 Answers
6






active

oldest

votes


















9














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.






share|improve this answer































    5














    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.






    share|improve this answer

































      2














      In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.






      share|improve this answer































        2














        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....






        share|improve this answer































          1














          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?






          share|improve this answer































            0














            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)






            share|improve this answer
























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              9














              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.






              share|improve this answer




























                9














                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.






                share|improve this answer


























                  9












                  9








                  9







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 14 '13 at 21:59









                  davidalgerdavidalger

                  7,07112547




                  7,07112547

























                      5














                      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.






                      share|improve this answer






























                        5














                        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.






                        share|improve this answer




























                          5












                          5








                          5







                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Apr 13 '17 at 12:55









                          Community

                          1




                          1










                          answered Sep 23 '13 at 10:38









                          PiTheNumberPiTheNumber

                          1,928104167




                          1,928104167























                              2














                              In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.






                              share|improve this answer




























                                2














                                In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.






                                share|improve this answer


























                                  2












                                  2








                                  2







                                  In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.






                                  share|improve this answer













                                  In the rule configuration remove the allowed customer group "Not Logged In", so only registered customers can use the code.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Sep 12 '13 at 21:27









                                  AmastyAmasty

                                  312




                                  312























                                      2














                                      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....






                                      share|improve this answer




























                                        2














                                        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....






                                        share|improve this answer


























                                          2












                                          2








                                          2







                                          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....






                                          share|improve this answer













                                          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....







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Aug 19 '14 at 8:36









                                          KenKen

                                          211




                                          211























                                              1














                                              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?






                                              share|improve this answer




























                                                1














                                                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?






                                                share|improve this answer


























                                                  1












                                                  1








                                                  1







                                                  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?






                                                  share|improve this answer













                                                  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?







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Feb 1 '16 at 12:41









                                                  EricEric

                                                  111




                                                  111























                                                      0














                                                      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)






                                                      share|improve this answer




























                                                        0














                                                        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)






                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0







                                                          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)






                                                          share|improve this answer













                                                          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)







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered 14 mins ago









                                                          mybinaryromancemybinaryromance

                                                          13111




                                                          13111






























                                                              draft saved

                                                              draft discarded




















































                                                              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.




                                                              draft saved


                                                              draft discarded














                                                              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





















































                                                              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







                                                              Popular posts from this blog

                                                              Last logged in always never, not logging

                                                              Iĥnotaksono

                                                              Colouring column values based on a specific condition. How could I do this?