Prestashop 1.7.5.0
I have at least one customer who got one of their previously used addresses removed from DB
That address was used in the history of the orders. Its id is 1946. The actual address ID that customer use is 1949. So in the order history both id of the addresses has been used. But first one is absent. I don't know why, maybe I removed it, I don't quite remember.
So when I try to open the customer's profile in the BO I see 500 error page. If I enable the debugging I see:
[PrestaShopException]
Invalid address #1946
at line 472 in file classes/Address.php
467. // if an id_address has been specified retrieve the address
468. if ($id_address) {
469. $address = new Address((int) $id_address);
470. //print_r( (int)$address );
471. if (!Validate::isLoadedObject($address)) {
472. throw new PrestaShopException('Invalid address #' . (int) $id_address);
473. }
474. } elseif ($with_geoloc && isset($context->customer->geoloc_id_country)) {
475. $address = new Address();
476. $address->id_country = (int) $context->customer->geoloc_id_country;
477. $address->id_state = (int) $context->customer->id_state;
If I comment line 472 I can view and work with costomer's profile.
472. //throw new PrestaShopException('Invalid address #' . (int) $id_address);
I believe there should be some warning or error message instead of the error page.
In the FO the customer can view the order history normally.
PrestaShop version: 1.7.5.0
PHP version: 7.2
Hi @LedCloud,
I created an address for a customer with id_address = 7, I created two orders with this address( one with status accepted & the other with status "Awaiting check payment", I added some products to the cart, I did not complete my order.
Then, I deleted this address from the Database, when I try to go to the FO => Account page => there is no error, in the FO => OrderHistory => OK.
But, I have an issue in the BO => Orders => Shopping cart page

Which is normal behavior, because an address is deleted from the Database.
Thanks!
Addresses should not be deleted from DB directly, there is a flag deleted in each row to determin whether address is deleted or not.
The addresses can be deleted not only by running sql request derectly to DB but the addressed could be deleted also from the BO Addresses Controller.
So I insist there should be a message while viewing the customer's profile, not a 500 page.
Besides, the address could be deleted long time ago, before 1.7.5.0. With nowadays behavoir the admin cannot access the customer's profile at all.
Addresses should not be deleted from DB directly, there is a flag
deletedin each row to determin whether address is deleted or not.
yes, they shouldn't, but they could be deleted.
Instead of throwing an exception there should be a warning message.
@LedCloud, about deleting addresses which causing a problem, is fixed with this PR: https://github.com/PrestaShop/PrestaShop/pull/11416, fixed in the PS1.7.5.0.
Thanks!
Okay. But what fixed? After updating to 1.7.5.0 there will be not such problem, right?
But how about that I already have it?
Yes, I can fix it with raw sql quest, (I speak about this current case) but I don't think it's a common way and it could be recommended to all users of prestashop. Besides how can I know when it happens again?
I believe there should be a warning message. Not even an error because it doesn't break BO working.
@LedCloud, In your case you deleted the address from the database & not from the BO, so the issue occurs, is it?
Thanks!
@LedCloud, In your case you deleted the address from the database & not from the BO, so the issue occurs, is it?
Thanks!
I'm sure I didn't deleted it with the raw sql request. Perhaps it was done by me in BO. Less probably user did that. I use prestashop since 1.5.some version and I don't know when the address was deleted.
@LedCloud, In my case, I did not manage to reproduce the issue with PS1.7.5.0 / 1.7.5.1 when I deleted an address from the BO => Customers => Addresses page.
Thanks!
You don't understand me. Most of people don't start using prestashop since 1.7.5.0. They upgrade to it. And if they as me have such problem, no matter how they got it, they will see only 500 page without explanation and without the fix to the DB structure.
Why not to replace the throunging exception to the message?
Besides if the address doesn't exists, everything works either for BO or FO.
It's not a critical error to stop working.
@LedCloud, I tried with PS1.7.4.4, I deleted an address when I already have an abandoned cart.
I have an issue in the Shopping cart page as described in this issue: https://github.com/PrestaShop/PrestaShop/issues/9782
I made an upgrade from 1.7.4.4 to PS1.7.5.0 with the 1-click upgrade v4.5.1. => OK.
I try to login to BO => Shopping cart page, I always have the same issue,

There is something missing in the database.
@marionf, @colinegin what do you think, is it possible to replace the throwing exception to a message as suggested by @LedCloud?
Thanks!
Well... I found the trick to fix this issue, but I'm not sure I do all completely right.
class/Address.php line 471
if (!Validate::isLoadedObject($address)) {
$address->id = (int) $id_address;
$address->delete();
//throw new PrestaShopException('Invalid address #' . (int) $id_address);
}
Instead of throwing an exception we set the id of the address that is absent to the inner field of the Address class and after that we can correct the DB. Address->delete() do what we want.
But since the default behaivoir now doesn't set the id of the object if that one doesn't exists, I'm not sure this is a correct way.
That's why I don't want to do the pull request.
Hello,
I've just reviewed your problem with the core team, you're right, the fix has been implemented on 1.7.5.0, but this does not fix the issue for stores which have already deleted addresses and upgrade to the last version. We need to handle the case when the address has already been deleted.
@PrestaShop/prestashop-core-developers @eternoendless what do you think would be the best way to handle it ?
Any news @PrestaShop/prestashop-core-developers ?
@colinegin We should provide a upgrade script to find all deleted addresses, wdyt?
Any news with this issue?
@norbertlaza Actually the bug is not in the roadmap. But if you want to create a PR for this, we could add it to the next release. We are always to external contributions. Thanks :hugs:
Same problem en version 1.7.6.7.
I麓m not ptogrammer, can anybody tell me what to do?
[PrestaShopException]
Invalid address #1361
at line 529 in file classes/Address.php
AddressCore::initialize - [line 198 - classes/tax/Tax.php] - [1 Arguments]
TaxCore::getProductEcotaxRate - [line 753 - classes/Cart.php] - [1 Arguments]
CartCore->getProducts - [line 1936 - classes/Cart.php]
CartCore->getOrderTotal - [line 1851 - classes/Cart.php] - [2 Arguments]
CartCore::getTotalCart - [line 896 - controllers/admin/AdminCartsController.php] - [3 Arguments]
AdminCartsControllerCore->getOrderTotalUsingTaxCalculationMethod - [line 363 - classes/helper/HelperList.php] - [2 Arguments]
HelperListCore->displayListContent - [line 187 - classes/helper/HelperList.php]
HelperListCore->generateList - [line 957 - controllers/admin/AdminCartsController.php] - [2 Arguments]
AdminCartsControllerCore->renderList - [line 2130 - classes/controller/AdminController.php]
AdminControllerCore->initContent - [line 292 - classes/controller/Controller.php]
ControllerCore->run - [line 515 - classes/Dispatcher.php]
DispatcherCore->dispatch - [line 97 - admin/index.php]