Qamar Zaman Posted October 14, 2023 Share Posted October 14, 2023 <pre> public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } return parent::install() && $this->registerHook('actionValidateOrder'); } public function hookActionValidateOrder($params){ $email = $couponCode = ''; $order = $params['order']; $email = ($order->id_customer == 0 && $order->guest_email) ? $order->guest_email : ''; PrestaShopLogger::addLog("Existing email and coupon found. 11"); // Get the email ID of a guest if applicable if(empty($email)){ return true; } PrestaShopLogger::addLog("Existing email and coupon found. 12"); $cart = new Cart($order->id_cart); // Get applied cart rules (coupons) $appliedCartRules = $cart->getCartRules(); foreach ($appliedCartRules as $appliedCartRule) { $couponCode = $appliedCartRule['code']; // Use $couponCode as needed } // Check if the cart has a voucher (coupon) applied if (empty($couponCode)){ return true; } PrestaShopLogger::addLog("Existing email and coupon found. 14"); if ($this->existsInDatabase($email, $couponCode)){ $errorMessage = 'Coupon already used!'; throw new PrestaShopException($errorMessage); }else{ PrestaShopLogger::addLog("Existing email and coupon found. 15"); $this->saveToDatabase($email, $couponCode); } return true; } </pre> I have this code, other 2 functions for checking and savetoDatabase are also fine. But i am not sure why this function is never called, never create a log. Can someone please help me. Link to comment Share on other sites More sharing options...
Zohaib-fk Posted October 14, 2023 Share Posted October 14, 2023 You can check PS documentation about the hook on below link https://devdocs.prestashop-project.org/8/modules/concepts/hooks/list-of-hooks/actionvalidateorder/ In PrestaShop, the actionValidateOrder hook is a powerful hook that is triggered when an order is validated or confirmed by a customer. It is a crucial point in the order processing workflow and allows you to perform various actions or modifications when an order is successfully placed by a customer. It's essential to thoroughly test your module and the actionValidateOrder hook implementation to ensure it behaves as expected when orders are validated. By using the actionValidateOrder hook in your PrestaShop module, you can extend and customize the order processing flow, allowing you to integrate with external systems, handle additional order-related tasks, and enhance the functionality of your e-commerce store. Link to comment Share on other sites More sharing options...
Qamar Zaman Posted October 15, 2023 Author Share Posted October 15, 2023 i try to put a single line log in it, but nothing work, seems that its never called. Can someone help find whats wrong. I have checked the documentation already. Nothing works for me. 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