phinq1910 Posted February 15, 2017 Share Posted February 15, 2017 I have ceated test module with prestashop and have a question, please explain for me 1, Regis hook actioncartsave $this->registerHook('actionCartSave') 2, When I print string in hookActionCartSave function, public function hookActionCartSave() { //return false; if (!$this->active || !Validate::isLoadedObject($this->context->cart) || !Tools::getIsset('id_product')) return false; print_r('expression'); return false; } 3, it display double result, why? expressionexpression{"products":[{"id":1,"link":"http:\/\/localhost\/ps16c\/index.php?id_product=1&controller=product#\/size-s\/color-orange","quantity":3,"image":"http:\/\/localhost\/ps16c\/img\/p\/1\/1-home_default.jpg","image_cart":"http:\/\/localhost\/ps16c\/img\/p\/1\/1-cart_default.jpg","priceByLine":"$49.53","name":"Faded Short Sleeves T-shirt","price":"$49.53","price_float":49.53,"idCombination":1,"idAddressDelivery":5,"is_gift":false,"hasAttributes":true,"attributes":"S, Orange","hasCustomizedDatas":false,"customizedDatas":[]}],"discounts":[],"shippingCost":"$7.00","shippingCostFloat":7,"wrappingCost":"$0.00","nbTotalProducts":3,"total":"$56.53","productTotal":"$49.53","freeShipping":"$0.00","freeShippingFloat":0,"free_ship":false,"isVirtualCart":false,"hasError":false,"crossSelling":""} Please help me Thank you very much Link to comment Share on other sites More sharing options...
joseantgv Posted February 15, 2017 Share Posted February 15, 2017 I have ceated test module with prestashop and have a question, please explain for me 1, Regis hook actioncartsave $this->registerHook('actionCartSave') 2, When I print string in hookActionCartSave function, public function hookActionCartSave() { //return false; if (!$this->active || !Validate::isLoadedObject($this->context->cart) || !Tools::getIsset('id_product')) return false; print_r('expression'); return false; } 3, it display double result, why? expressionexpression{"products":[{"id":1,"link":"http:\/\/localhost\/ps16c\/index.php?id_product=1&controller=product#\/size-s\/color-orange","quantity":3,"image":"http:\/\/localhost\/ps16c\/img\/p\/1\/1-home_default.jpg","image_cart":"http:\/\/localhost\/ps16c\/img\/p\/1\/1-cart_default.jpg","priceByLine":"$49.53","name":"Faded Short Sleeves T-shirt","price":"$49.53","price_float":49.53,"idCombination":1,"idAddressDelivery":5,"is_gift":false,"hasAttributes":true,"attributes":"S, Orange","hasCustomizedDatas":false,"customizedDatas":[]}],"discounts":[],"shippingCost":"$7.00","shippingCostFloat":7,"wrappingCost":"$0.00","nbTotalProducts":3,"total":"$56.53","productTotal":"$49.53","freeShipping":"$0.00","freeShippingFloat":0,"free_ship":false,"isVirtualCart":false,"hasError":false,"crossSelling":""} Please help me Thank you very much It seems as if it was called twice. Use "debug_backtrace" function to check it. 1 Link to comment Share on other sites More sharing options...
phinq1910 Posted February 15, 2017 Author Share Posted February 15, 2017 I put var_dump(debug_backtrace()); it only display my module called (display double result) array(9) { [0]=> array(7) { ["file"]=> string(38) "D:\Xampp\htdocs\ps16c\classes\Hook.php" ["line"]=> int(587) ["function"]=> string(18) "hookActionCartSave" ["class"]=> string(15) "testmodule" ["object"]=> Wellcome your idea Thanks Link to comment Share on other sites More sharing options...
joseantgv Posted February 15, 2017 Share Posted February 15, 2017 I put var_dump(debug_backtrace()); it only display my module called (display double result) array(9) { [0]=> array(7) { ["file"]=> string(38) "D:\Xampp\htdocs\ps16c\classes\Hook.php" ["line"]=> int(587) ["function"]=> string(18) "hookActionCartSave" ["class"]=> string(15) "testmodule" ["object"]=> Wellcome your idea Thanks Could you paste the full trace? Link to comment Share on other sites More sharing options...
phinq1910 Posted February 15, 2017 Author Share Posted February 15, 2017 Yes, please check the below link https://drive.google.com/file/d/0B5Q3dn8S8lg8NXAwX3pfQ1RYdm8/view Thank you Link to comment Share on other sites More sharing options...
phinq1910 Posted February 16, 2017 Author Share Posted February 16, 2017 I think because presta system call 2 times hookActionCartSave public function add($autodate = true, $null_values = false) { if (!$this->id_lang) { $this->id_lang = Configuration::get('PS_LANG_DEFAULT'); } if (!$this->id_shop) { $this->id_shop = Context::getContext()->shop->id; } $return = parent::add($autodate, $null_values); Hook::exec('actionCartSave'); return $return; } public function update($null_values = false) { if (isset(self::$_nbProducts[$this->id])) { unset(self::$_nbProducts[$this->id]); } if (isset(self::$_totalWeight[$this->id])) { unset(self::$_totalWeight[$this->id]); } $this->_products = null; $return = parent::update($null_values); Hook::exec('actionCartSave'); return $return; } So is it problem of presa? Thank you Link to comment Share on other sites More sharing options...
joseantgv Posted February 16, 2017 Share Posted February 16, 2017 I think because presta system call 2 times hookActionCartSave public function add($autodate = true, $null_values = false) { if (!$this->id_lang) { $this->id_lang = Configuration::get('PS_LANG_DEFAULT'); } if (!$this->id_shop) { $this->id_shop = Context::getContext()->shop->id; } $return = parent::add($autodate, $null_values); Hook::exec('actionCartSave'); return $return; } public function update($null_values = false) { if (isset(self::$_nbProducts[$this->id])) { unset(self::$_nbProducts[$this->id]); } if (isset(self::$_totalWeight[$this->id])) { unset(self::$_totalWeight[$this->id]); } $this->_products = null; $return = parent::update($null_values); Hook::exec('actionCartSave'); return $return; } So is it problem of presa? Thank you Are you adding a product to the cart from your module? Link to comment Share on other sites More sharing options...
phinq1910 Posted February 16, 2017 Author Share Posted February 16, 2017 No, I click Add to cart on detail product of presta 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