Prestashop: [BOOM-5955] Strange behavior after editing a carrier

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

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

  • _Reporter:_ khouloud.belguith
  • _Created at:_ Wed, 11 Jul 2018 18:04:33 +0200

Hi,

After a fresh install PS1.7.4.0, navigate to the BO => IMPROVE => Shipping => Carriers, by default, we have two addresses, for the first one which id=2.
Try to edit this carrier, then click on save without changing any files, the id of this carrier will be changed.
In fact, after editing any carrier, a new carrier is created in the Database.

Best regards, Khouloud

  • How to reproduce the issue ?

1-Fresh Install 1.7.4.0


2-Navigate to BO => IMPROVE => Shipping => Carriers


3-Edit a carrier

1.7.4.0 1.7.6.0 1.7.6.1 Bug Carriers Minor PR available Shipping To Do

All 16 comments

The same for me on 1.7.3.4
After editing a carrier the carrier is copied to a new ID, the old one is set to deleted in the database. Every now and then the ranges are not copied correctly and I receive an "overlapping ranges" error for the new carrier and it's not editable anymore.

I confirm the bug still exists in 1.7.4.2 and on develop branch: when I edit a carrier, it does not edit, it actually clones the carrier with updated informations. The original is not deleted in the database but does not appear in the listing.

Hi,

The issue is added to our bug roadmap, but not fixed yet.

Best regards, Khouloud

Not sure it's a bug. In order to duplicate you need to get the data and perform an INSERT which syntax is really different from an UPDATE. Also, the fact there is a delete flag in the table demonstrate the use of the flag.
I think the idea was to save old value. Eg a customer ask for a product on day 1, so the shipping cost and all other values are computed using the carrier data of day 1. On day 2 you change the carrier in the backoffice. When the user came back on day 3 he must get back carrier's data of day 1 and not the updated of day 2.
What the system must do is:
If update of carrier data check if the carrier has been used.

  • If yes, create a copy in order to save old value and set the delete flag to 1 in order to be able to use the data in statistics but not for new orders.
  • If no, simply perform an update
    Must be a bit complicated as you can update the carrier itself but also the ranges for the price.
    Maybe changing the carrier id field type to smallint or mediumint would be nice. Actully it's an int, meaning you can have 4 billions carriers....

Hi, I'm on 1.7.5.1. I'm here because I'm using PrestaShop web services and found their behavior strange. Perhaps it can help you to understand the problem.

I tried to rename carrier twice that way: carrier_name -> carrier_name1 -> carrier_name.

And then I faced with that the api call /api/filter[name]=[carrier_name] returns two similar carriers (with different id's of course)

@HolyWalley. Some think it's a bug, but I think it's not. In fact, when you edit a carrier, Prestashop read data from this carrier, show you the form to edit the data, and when you confirm, Prestashop create a new record with the data you updated and then update the previous record ("old" one) to set it as "deleted" (so just set a flag).
So in the DB you have the old version of your carrier with the flag "deleted" and the new version in an other record. Really this is far too complicated to be considered as a "bug". So why do we have that? I think it's a feature, with a link to stat and with "historical data". With that, as the carrier is linked with the basket, your old basket stay linked with the data of the carrier at the time of this basket. With a full update of carrier data rather than this "copy", you would have old basket linked with the new data of carrier which is a non sense.
On the other end, there is a bug in the way Prestashop call the carrier module when it display them: if you have eg 4 carriers (1-2-3-4) you will see Prestshop call them in this order: 1234234344.

@ANSB Perhaps you are right. I haven't noticed that previous carriers have deleted flag active. In my case, I can use an additional filter /api/filter[name]=[carrier_name]&filter[deleted]=[0] and it will work. Thanks anyway.

Same issue with PS1.7.6.1

Hi, as indicated by @ANSD in his great comment above (https://github.com/PrestaShop/PrestaShop/issues/9592#issuecomment-508716896) this is not a bug. The "when I edit a carrier it actually duplicates it" is a feature. It might have been badly implemented, but this issue is not relevant.

If you have a specific issue related to this, please describe it accurately. For example I think https://github.com/PrestaShop/PrestaShop/issues/9592#issuecomment-415105822 (overlapping ranges with deleted carriers) is one. It might be fixed by https://github.com/PrestaShop/PrestaShop/pull/15615.

For information only: some modules use the carrier id, so after each update, they dont't work properly, until you update the carrier on the module config.

Hi, I'm on 1.7.6.5.
After editing a carrier the carrier is copied to a new ID, the old one is not set to deleted in the database. so, it's showing me both carrier, the new and the old, Every now and then the ranges are not copied to new ID and also changes are not saved in the old new, it's not editable anymore.

Hi, I'm on 1.7.6.5.
After editing a carrier the carrier is copied to a new ID, the old one is not set to deleted in the database. so, it's showing me both carrier, the new and the old, Every now and then the ranges are not copied to new ID and also changes are not saved in the old new, it's not editable anymore.

See my previous comment. The "carrier" is linked to what the client purchase.
Let's imaging "carrier 1" as phone number 1111111111. In January John purchase good on your shop, and "carrier 1"
is used.
In February, "carrier 1" change phone number which became 2222222. Problem: if you have a look at John's purchase (done in January) as it's still linked to "carrier 1" you'll see phone number as 2222222 when in fact at the date of the purchase the phone was 111111111.
To avoid that, there is no way to edit the carrier: if you change the phone number (eg) of "carrier 1", prestashop will in fact create a copy and so you'll get "carrier 2". So you'll stay with "carrier 1 -> phone number 11111111" and get "carrier 2 -> phone number 22222222" and so the purchase of January will stay linked to a carrier (number 1) with phone number 111111111 as it was at the time of the purchase.

yes but as you say, I will get "carrier 2" with updated changed, but in my case, carrier 2 does not have any ranges, changes for range are not saved in the carrier 2. even some values from old entry are also not carried out to new carrier.
Please check following screenshots.
Before edit -
Carrier1

After edit -
NewCarrier

yes but as you say, I will get "carrier 2" with updated changed, but in my case, carrier 2 does not have any ranges, changes for range are not saved in the carrier 2. even some values from old entry are also not carried out to new carrier.

So this means all data are not correctly duplicated (on va dire 莽a comme 莽a) in the new one. That's a different problem. Maybe have a look in the code. But really, the code is ugly....

Yes, all data are not duplicated in the new one.

Was this page helpful?
0 / 5 - 0 ratings