jamiedevine Posted June 2, 2014 Share Posted June 2, 2014 (edited) My client wants to run a promotion on their PrestaShop site that allows customers to use a voucher code to get money off certain products that only works once per customer. The voucher is set up and working but as part of the promotion we have also have an overlay that pops up after xxx seconds that lets the user know about the code and the promotion. The problem is this overlay should only appear if the customer has not already used the voucher code in the past, because each customer is only allowed to use it once there is no point in showing it to them again. In FrontController.php, within the display() method I'm trying to create a boolean variable (that is available in the footer) which will be true or false depending on if the user has already used the voucher for this promotion. I can then control whether the HTML for the overlay is output or not. How can I check if the customer has already used the voucher code? Edited June 3, 2014 by jamiedevine (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted June 3, 2014 Share Posted June 3, 2014 Hi. Do you know the ID or the code of the voucher? Regards.Robin.The CartExpert Team Link to comment Share on other sites More sharing options...
jamiedevine Posted June 3, 2014 Author Share Posted June 3, 2014 Hi, thanks for the reply. Yes, we can hard code the voucher ID in this case if we need to as it will not change. We also know the Id of the currently logged in customer by getting it through the context object. Link to comment Share on other sites More sharing options...
CartExpert.net Posted June 3, 2014 Share Posted June 3, 2014 Hi, What you can do is create a CartRule object using the ID and you check if it has been used by the customer with the usedByCustomer method. See CartRule.php line 331. Regards.Robin.The CartExpert Team Link to comment Share on other sites More sharing options...
jamiedevine Posted June 3, 2014 Author Share Posted June 3, 2014 Perfect - that's exactly what I was looking for. I thought there would be a method along those lines somewhere but I was looking in the Discount class. Thanks for your help! Link to comment Share on other sites More sharing options...
CartExpert.net Posted June 3, 2014 Share Posted June 3, 2014 Hi. Happy we could help. Please mark the topic [sOLVED] Regards.Robin.The CartExpert Team Link to comment Share on other sites More sharing options...
connectcase Posted November 28, 2014 Share Posted November 28, 2014 Can you guys share a little code? I need sort of the same thing; to show which vouchers have been used by current customer... Link to comment Share on other sites More sharing options...
hammerleit Posted February 24, 2016 Share Posted February 24, 2016 I'd also like to know the solution on this issue Link to comment Share on other sites More sharing options...
jamiedevine Posted February 24, 2016 Author Share Posted February 24, 2016 Sure, here is the code to do it: // $id_rule is the id of the voucher code $objCartRule = new CartRule($id_rule); // Will return true or false $objCartRule->usedByCustomer($id_customer); And to get all the rules a customer has used - place the following code in your CartRule override class (maybe this fits better in the Customer class, but whichever you think): /** * Get rules used by customer * @param $id_customer */ public static function getRulesUsedByCustomer($id_customer) { return Db::getInstance()->executeS(' SELECT DISTINCT id_cart_rule FROM `'._DB_PREFIX_.'order_cart_rule` ocr LEFT JOIN `'._DB_PREFIX_.'orders` o ON ocr.`id_order` = o.`id_order` AND o.`id_customer` = '.(int)$id_customer); } And then get a list of rule IDs the customer has used by doing this: $arrRuleIds = CartRule::getRulesUsedByCustomer($id_customer); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now