Jump to content

Fix for "Unfortunately, there are no carriers available for your delivery address"


Romain Websenso

Recommended Posts

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!

  • Thanks 1
Link to comment
Share on other sites

  • 5 months later...
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

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

  • 5 months later...

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 by DARKF3D3 (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
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

  • 5 months later...

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 by axed84 (see edit history)
Link to comment
Share on other sites

  • 1 month later...

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 ;:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...