Prestashop: BO - Orders page - Allow the creation of order when the address is considered as soft deleted.

Created on 21 Aug 2020  路  5Comments  路  Source: PrestaShop/PrestaShop

Describe the bug

In the BO => Orders => Add new Order page, Delivery and Invoice has the same address selected, when weupdate the delivery address and create the order, there is an error "The invoice address with id "2" cannot be used because it is deleted" because the invoice address is soft deleted

Expected behavior

Allow the creation of an order when the address is soft deleted

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to BO => Orders => Add a new order page
  2. search for "[email protected]" - a customer that already exist (!)
  3. add some products to the cart
  4. In the Address block, make sure that Delivery and Invoice has the same address selected, and the address already existed before (!)
  5. try to edit the delivery address and save
  6. see error "The invoice address with id "2" cannot be used because it is deleted"

(!) Basically this scenario needs to use a customer with adresses that existed before step 1

https://drive.google.com/file/d/1xN3T1yYdY-R8tTbFfvMqnGMnfsx02YVI/view?usp=sharing

Additional information

  • PrestaShop version: 1770beta2build1 / 177x
  • PHP version: 7.2
1.7.7.x Addresses BO Bug Fixed Major Must-have Order PR available Regression migration

Most helpful comment

Hi @khouloudbelguith,

regarding the second address not being updated this is the expected behaviour. The reason is that once an address has been associated with an Order it can never be changed any more because any update for future orders would also affect previous ones.

So when we update an address, we check if it has been associated yet, if it's not we can simply edit it regularly (like you first scenario in the video), since delivery and invoice address are the same both are updated (actually only one used twice).

In the second scenario however you create a cart with an associated address for delivery and invoice (let's say its ID is 2), when you edit the delivery address the Core detects that it is already associated to an order so it can't edit it. What it does instead is copy the existing address, apply the modification and reassign the cart's delivery address with the newly created address (with ID 3), while the former one (with ID 2) is marked as "deleted" (this avoids having 10 visible addresses per customer each times he changes it).

So at this point the cart has a new delivery address (with ID 3), but it still has the former one as invoice address (with ID 2) That's why the invoice address is not updated because it's not the same instance any more, and we can't assume that the merchant actually wanted to update both addresses at a time. He could however select the new address as the invoice address (it should be selectable in the list).

So far it's all happening as expected, however the last error you mentioned is troublesome because the "deleted" address can not be used in the cart. This one is not normal and we should probably allow a cart to use a deleted address.

Alternatively we could force the assignment of both cart's addresses to the new one but I'm afraid this would result in unexpected behaviour. Anyway this all should be validated with the @PrestaShop/prestashop-product-team

Thanks for the details anyway 馃槈

All 5 comments

Thanks for opening this issue! We will help you to keep its state consistent

Hi @khouloudbelguith,

regarding the second address not being updated this is the expected behaviour. The reason is that once an address has been associated with an Order it can never be changed any more because any update for future orders would also affect previous ones.

So when we update an address, we check if it has been associated yet, if it's not we can simply edit it regularly (like you first scenario in the video), since delivery and invoice address are the same both are updated (actually only one used twice).

In the second scenario however you create a cart with an associated address for delivery and invoice (let's say its ID is 2), when you edit the delivery address the Core detects that it is already associated to an order so it can't edit it. What it does instead is copy the existing address, apply the modification and reassign the cart's delivery address with the newly created address (with ID 3), while the former one (with ID 2) is marked as "deleted" (this avoids having 10 visible addresses per customer each times he changes it).

So at this point the cart has a new delivery address (with ID 3), but it still has the former one as invoice address (with ID 2) That's why the invoice address is not updated because it's not the same instance any more, and we can't assume that the merchant actually wanted to update both addresses at a time. He could however select the new address as the invoice address (it should be selectable in the list).

So far it's all happening as expected, however the last error you mentioned is troublesome because the "deleted" address can not be used in the cart. This one is not normal and we should probably allow a cart to use a deleted address.

Alternatively we could force the assignment of both cart's addresses to the new one but I'm afraid this would result in unexpected behaviour. Anyway this all should be validated with the @PrestaShop/prestashop-product-team

Thanks for the details anyway 馃槈

IMO We should be coherent between the add and the detail order page. In both pages, updating an address doesn't update the other address. As @jolelievre has said, it is the expected behavior but the error message is not relevant.
I back up @jolelievre's idea to allow the creation of order when the address is considered as deleted.

Fixed by #20734

Was this page helpful?
0 / 5 - 0 ratings