Romain Websenso Posted July 10, 2020 Share Posted July 10, 2020 Hi, I had a bug that I couldn't fix for quite some time and I finally found the source and patched it (fix at the end of post). I have this bug on Prestashop 1.7.3, I don't know if it's a bug on previous or next version but if it helps you save hours of debugging it's worth it! The bug is that sometimes customers didn't have any carrier listed in the checkout process. It's a bug really hard to reproduce! After reading one hundred time on the forum "You have to enable the carrier and and the country to the zone bla bla bla " (Thanks captain obvious...) I found someone talking about this bug happening when double clicking on the save button on the add address form. I tried it and there it was, THE BUG! Being able to reproduce I just needed to trace the execution in the code and check the database to solve it. The problem was prestashop is trying to update the id_address_delivery in cart_product using a where that is too restrictive (on our case where id_address_delivery = the_id_address_delivery that does not exist). The fix! In an override public_html\override\classes\Cart.php <?php class Cart extends CartCore { /** * Update the Address ID of the Cart * * @param int $id_address Current Address ID to change * @param int $id_address_new New Address ID */ public function updateAddressId($id_address, $id_address_new) { $to_update = false; if (!isset($this->id_address_invoice) || $this->id_address_invoice == $id_address) { $to_update = true; $this->id_address_invoice = $id_address_new; } if (!isset($this->id_address_delivery) || $this->id_address_delivery == $id_address) { $to_update = true; $this->id_address_delivery = $id_address_new; } if ($to_update) { $this->update(); } $sql = 'UPDATE `'._DB_PREFIX_.'cart_product` SET `id_address_delivery` = '.(int)$id_address_new.' WHERE `id_cart` = '.(int)$this->id; // AND `id_address_delivery` = '.(int)$id_address; Db::getInstance()->execute($sql); $sql = 'UPDATE `'._DB_PREFIX_.'customization` SET `id_address_delivery` = '.(int)$id_address_new.' WHERE `id_cart` = '.(int)$this->id; // AND `id_address_delivery` = '.(int)$id_address; Db::getInstance()->execute($sql); } } I hope it helps! 1 Link to comment Share on other sites More sharing options...
Rizzzle Posted January 5, 2021 Share Posted January 5, 2021 Hello my friend, Thank you for this. In Prestashop 1.7.4.4 I cant find the override file. Please could you help? Some of my customers are getting the same error. Link to comment Share on other sites More sharing options...
tomerg3 Posted January 6, 2021 Share Posted January 6, 2021 12 hours ago, Rizzzle said: Hello my friend, Thank you for this. In Prestashop 1.7.4.4 I cant find the override file. Please could you help? Some of my customers are getting the same error. Override files are files that you create yourself, and they override the built in class (to avoid having your changes deleted after a PrestaShop update. If you are not sure how to create an override file, a quick Google Search should help. Link to comment Share on other sites More sharing options...
hannes01 Posted January 11, 2021 Share Posted January 11, 2021 It solved it, thank you! Link to comment Share on other sites More sharing options...
Rizzzle Posted January 11, 2021 Share Posted January 11, 2021 On 1/6/2021 at 2:15 AM, tomerg3 said: Override files are files that you create yourself, and they override the built in class (to avoid having your changes deleted after a PrestaShop update. If you are not sure how to create an override file, a quick Google Search should help. Thank you for the reply. Super appreciated. Copy and paste the code into a text file using Notepaid, rename it as Cart.php and copy into the cart directory? Will Prestashop automatically detect this then? Thank you Link to comment Share on other sites More sharing options...
tomerg3 Posted January 12, 2021 Share Posted January 12, 2021 You may need to clear the cache in the Performance page 1 Link to comment Share on other sites More sharing options...
DARKF3D3 Posted June 24, 2021 Share Posted June 24, 2021 (edited) I confirm that this is a but caused by multiple clicks on address "save" button. From what i see last version of prestashop (PS1.7.7) isn't affected, in fact after the first click the button will be disabled to avoid additional clicks. What I'm wondering is if there's a way to "fix" the account where customer double clicked on the button, because after doing that, there's no way to have the carrier showed, also deleting all the addresses of the account, and adding new one. Edited June 25, 2021 by DARKF3D3 (see edit history) Link to comment Share on other sites More sharing options...
tuhingr Posted July 25, 2021 Share Posted July 25, 2021 Just make new one, hope resolve. Link to comment Share on other sites More sharing options...
Rizzzle Posted August 18, 2021 Share Posted August 18, 2021 On 6/24/2021 at 1:04 PM, DARKF3D3 said: I confirm that this is a but caused by multiple clicks on address "save" button. From what i see last version of prestashop (PS1.7.7) isn't affected, in fact after the first click the button will be disabled to avoid additional clicks. What I'm wondering is if there's a way to "fix" the account where customer double clicked on the button, because after doing that, there's no way to have the carrier showed, also deleting all the addresses of the account, and adding new one. This error is still here in Prestashop 1.7.7.5 . A customer has just emailed me saying they have this bug. Link to comment Share on other sites More sharing options...
axed84 Posted February 8, 2022 Share Posted February 8, 2022 (edited) Thanks for the fix. I spend too much time trying to understand where it came from, without results. Many thanks for the diagnostics, this have to be fixed by the Prestashop teams, it's a very important issue; many shop owner will be stuck trying to understand why it's not working. Solved my issue on 1.7.6.5. Edited February 8, 2022 by axed84 (see edit history) Link to comment Share on other sites More sharing options...
hugolin69 Posted April 4, 2022 Share Posted April 4, 2022 Hi everybody and thank you for this fix. I just wonder to know if this fix is safe. Why Prestashop was sending the old ID ? maybe to ensure a security hack no ? Also, there is an other bug with the same result, you can take a look at ;: https://github.com/PrestaShop/PrestaShop/issues/9932 https://github.com/PrestaShop/PrestaShop/pull/15399 https://github.com/PrestaShop/PrestaShop/issues/18100 Link to comment Share on other sites More sharing options...
MJ_C Posted October 10 Share Posted October 10 On 7/10/2020 at 8:49 AM, Romain Websenso said: Hi, I had a bug that I couldn't fix for quite some time and I finally found the source and patched it (fix at the end of post). I have this bug on Prestashop 1.7.3, I don't know if it's a bug on previous or next version but if it helps you save hours of debugging it's worth it! The bug is that sometimes customers didn't have any carrier listed in the checkout process. It's a bug really hard to reproduce! After reading one hundred time on the forum "You have to enable the carrier and and the country to the zone bla bla bla " (Thanks captain obvious...) I found someone talking about this bug happening when double clicking on the save button on the add address form. I tried it and there it was, THE BUG! Being able to reproduce I just needed to trace the execution in the code and check the database to solve it. The problem was prestashop is trying to update the id_address_delivery in cart_product using a where that is too restrictive (on our case where id_address_delivery = the_id_address_delivery that does not exist). The fix! In an override public_html\override\classes\Cart.php <?php class Cart extends CartCore { /** * Update the Address ID of the Cart * * @param int $id_address Current Address ID to change * @param int $id_address_new New Address ID */ public function updateAddressId($id_address, $id_address_new) { $to_update = false; if (!isset($this->id_address_invoice) || $this->id_address_invoice == $id_address) { $to_update = true; $this->id_address_invoice = $id_address_new; } if (!isset($this->id_address_delivery) || $this->id_address_delivery == $id_address) { $to_update = true; $this->id_address_delivery = $id_address_new; } if ($to_update) { $this->update(); } $sql = 'UPDATE `'._DB_PREFIX_.'cart_product` SET `id_address_delivery` = '.(int)$id_address_new.' WHERE `id_cart` = '.(int)$this->id; // AND `id_address_delivery` = '.(int)$id_address; Db::getInstance()->execute($sql); $sql = 'UPDATE `'._DB_PREFIX_.'customization` SET `id_address_delivery` = '.(int)$id_address_new.' WHERE `id_cart` = '.(int)$this->id; // AND `id_address_delivery` = '.(int)$id_address; Db::getInstance()->execute($sql); } } I hope it helps! Thank you so much. I had similar code from elsewhere that hadn't sorted the issue. Your code had slight differences and when applied, I tested by adding a new address and changing addresses etc. All worked fine after the code was applied. Thank you again. BTW I am using Prestahsop 1.7.6.7 Just as an addition, if anyone is looking for solutions to code, I would highly recommend an AI called Perplexity. When a friend mentioned it after I asked him about some code, he said try Perplexity. Tell it what you want as specifically as possible. Then with the results refine it to your needs. I asked it to write all sorts of Prestashop modules and PHP's and it's been great. The reason I say this is that despite asking for help in recent years in the forums, there is rarely a reply and sad to see Prestashop vanish. So, with Perplexity, at least it points and helps you in the right direction. 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