Prestashop: [BOOM-4291] 500 Error adding address at checkout or via my account

Created on 22 Aug 2018  路  21Comments  路  Source: PrestaShop/PrestaShop

This issue has been migrated from the Forge. Read the original ticket here.

  • _Reporter:_ elpatron
  • _Created at:_ Sun, 12 Nov 2017 21:13:01 +0100

Hi on new client upgrade we had issue where new address caused 500 error..either at checkout or via 'my account' 'add address'.
We solved issue from this stackoverflow thread
https://stackoverflow.com/questions/42413535/prestashop-1-7-unable-to-save-order-address

This solved the issue.

original error info
account creation, add address 500 errors.

to replicate, create new account then add new address. I originally had this issue when trying to check out and adding address...
[PrestaShopException]

Property Address->id_country is empty.
at line 944 in file classes/ObjectModel.php
939. }
940.
941. $message = $this->validateField($field, $this->$field);
942. if ($message !== true) {
943. if ($die)

{

  1. throw new PrestaShopException($message);
  2. }


946. return $error_return ? $message : false;
947. }
948. }
949.

ObjectModelCore->validateFields - [line 272 - classes/ObjectModel.php]
ObjectModelCore->getFields - [line 683 - classes/ObjectModel.php]
ObjectModelCore->update - [line 202 - classes/Address.php] - [1 Arguments]
AddressCore->update - [line 219 - classes/Address.php]
AddressCore->delete - [line 73 - classes/form/CustomerAddressPersister.php]
CustomerAddressPersisterCore->save - [line 162 - classes/form/CustomerAddressForm.php] - [2 Arguments]
CustomerAddressFormCore->submit - [line 111 - classes/checkout/CheckoutAddressesStep.php]
CheckoutAddressesStepCore->handleRequest - [line 57 - classes/checkout/CheckoutProcess.php] - [1 Arguments]
CheckoutProcessCore->handleRequest - [line 201 - controllers/front/OrderController.php] - [1 Arguments]
OrderControllerCore->initContent - [line 205 - classes/controller/Controller.php]
ControllerCore->run - [line 379 - classes/Dispatcher.php]
DispatcherCore->dispatch - [line 28 - index.php]

  • How to reproduce the issue ?

add address via checkout or my account

1.7.2.2 1.7.4.2 1.7.6.0 Addresses Bug Countries FO Fixed International Major

Most helpful comment

Hi @colinegin,

Yes, I have the same issue with PS1.7.6.0.
https://drive.google.com/file/d/1v2TpEIWQezMQxVENnA069m0-oVzVejQD/view
image

Thanks!

All 21 comments

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ marion_francois
  • _Created at:_ Mon, 13 Nov 2017 16:55:22 +0100

Je reproduis l'erreur apr猫s avoir supprim茅 le champ "Country:name" du format de l'adresse

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ kbelous
  • _Created at:_ Tue, 14 Nov 2017 12:43:28 +0100

It looks like the error in the classes/Address.php line 305 function isUsed
I believe the following lines should be added to that function:
if(empty($this->id))

{ return false; }

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ salma.moakhar
  • _Created at:_ Tue, 14 Nov 2017 18:18:55 +0100

Hi el patron,

I manage to reproduce the issue with the last version : 1.7.2.4.
We will see how to fix it.

Best regards, Salma

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ elpatron
  • _Created at:_ Tue, 14 Nov 2017 18:26:30 +0100

thanks Salma!

I used fix from stackovervlow but it may not be most elegant way to fix. I am happy to change client shop to your fix when ready.

Way to kick it's butt! We try to report more to help as we do client upgrades....

el

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ nickzampieri
  • _Created at:_ Wed, 15 Nov 2017 17:22:48 +0100

As per Kostyantyn Bilous:
If ps_orders table contains records with id_address_delivery = 0 or id_address_invoice = 0 then any new registered user unable to add new address into their account.
It looks like the error in the classes/Address.php line 305 function isUsed
I believe the following lines should be added to that function:
if(empty($this->id))

{ return false; }

So although you closed down BOOM-4299 as a duplicate, it seems like there are two solutions here within two different files.

In my case, I am seeing exactly the same issue as described in BOOM-4299. Adding a new address when ps_order table contains a 0 in the two fields, you cannot add new address into their account.

Kostyantyn Bilous, can you paste the whole classes/Address.php IsUsed() function with your fix so that I can test as well? When you say add these two lines, I am not 100% sure where to add those two lines. Right now, IsUsed() looks like this in both my 1.7.1.2 and 1.7.2.0 installations where I am having this problem.:

/**

  • Check if Address is used (at least one order placed)
    *
  • @return int Order count for this Address
    */
    public function isUsed() { $result = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(`id_order`) AS used FROM `'._DB_PREFIX_.'orders` WHERE `id_address_delivery` = '.(int)$this->id.' OR `id_address_invoice` = '.(int)$this->id); return $result > 0 ? (int)$result : false; }

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ nickzampieri
  • _Created at:_ Wed, 15 Nov 2017 17:34:50 +0100

As additional information, the fix on https://stackoverflow.com/questions/42413535/prestashop-1-7-unable-to-save-order-address by updating the classes\form\CustomerAddressPersister.php file with a simple 1 line to add seemed to do the trick for me:

$address->id_customer = $this->customer->id;
$address->save(); // <-- Add this

Scroll down to hocklai8's answer near the bottom of the page

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ kbelous
  • _Created at:_ Wed, 15 Nov 2017 22:32:13 +0100

/**

  • Check if Address is used (at least one order placed)
    *
  • @return int Order count for this Address
    */
    public function isUsed()
    {
    if(empty($this->id)) { return false; }

    $result = (int)Db::getInstance(PS_USE_SQL_SLAVE)->getValue('
    SELECT COUNT(`id_order`) AS used
    FROM `'.DB_PREFIX.'orders`
    WHERE `id_address_delivery` = '.(int)$this->id.'
    OR `id_address_invoice` = '.(int)$this->id);

return $result > 0 ? (int)$result : false;
}

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ marion_francois
  • _Created at:_ Tue, 19 Dec 2017 16:55:19 +0100

The problem is that we have the possibility in the address format of the country to remove the "mandatory" fields

Required fields are: firstname, lastname,聽address1,聽city and Country:name

This is the wanted behavior

We should check when adding or editing a country if required fields are removed in the address format

If a required field is removed, we should display an error message "The %name% field is required"

Louise Bonnard peux-tu confirmer pour l'ajout de ces chaines ?

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ louise bonnard
  • _Created at:_ Thu, 28 Dec 2017 18:07:15 +0100

Yes, alors je propose聽The %name% field is required. You can manage it here:%link%., c'est bon de ton c么t茅 ?

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ marion_francois
  • _Created at:_ Thu, 28 Dec 2017 18:19:14 +0100

Oui, nickel merci

This comment has been migrated from the Forge. Read the original comment here.

  • _Author:_ louise bonnard
  • _Created at:_ Fri, 5 Jan 2018 16:05:27 +0100

... avec les bons noms de domaines, cela donne :

The %name% field is required. You can manage it here:%link%.
1.7.x/Admin/Notifications/Error

Does this issue have any solution? Have the same issue and need help!

Hi @Assalea,

Sorry not yet.
There are some major issues to solve before this one.
So, it will probably not solved right now.
But PrestaShop is an open source project, so it can be solved before if someone submits a pull request to solve it.

Best regards, Khouloud

Do you know When you can have a look on it?

Hi There,

I have also the same problem is there a solution yet for the 500 error.....

@aliasali could you try this fix, and tell if it solved your issue? https://github.com/PrestaShop/PrestaShop/pull/10373

Hello @khouloudbelguith do you still reproduce this issue ?

Hi @colinegin,

Yes, I have the same issue with PS1.7.6.0.
https://drive.google.com/file/d/1v2TpEIWQezMQxVENnA069m0-oVzVejQD/view
image

Thanks!

@marionf , @colinegin

The issue here is that we have mandatory fields in the address table (id_country, firstname, lastname, etc...) and if we remove one of those in the address format in back office, then the form will fail at submit or even at display.

This page might be being migrated, I'll check that and inform those who are migrating the page, if the page is not being migrated I'll fix it.

Ok so I checked with @matks and I will fix it in the core, sending back an error message when we try to remove a mandatory field from the address format in back office.

Go to DB and see table required_fields, may be these field stay there, ande delete

Was this page helpful?
0 / 5 - 0 ratings