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.

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

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.

2

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

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

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?

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.