PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.21k stars 4.81k forks source link

stock_avalaible table should be cleaned after changing multishop parameter #28779

Open Max84 opened 2 years ago

Max84 commented 2 years ago

Prerequisites

Describe the bug and add screenshots

In a multishop context, if you change the share stock parameter into backoffice, old stock_avalaible lines are still in database. These lines aren't used anymore, I suggest deleting them onto stock parameter update in order to improve performance and keep database consistent.

I'll gibe an example just after.

image

Expected behavior

Unused stock_avalaible lines should be deleted.

Steps to reproduce

  1. Enable multishop.
  2. Disable stock sharing.
  3. Check stock_available table, for example product id 1, you'll see 2 lines, one for id_shop = 0 and another one for id_shop = 1. But the line with id_shop = 0. It should be deleted in order to improve performances.

PrestaShop version(s) where the bug happened

1.7.8.7, 1.7.7.8

PHP version(s) where the bug happened

No response

If your bug is related to a module, specify its name and its version

No response

Max84 commented 2 years ago

In order to help anybody with have some problem with inconsistent data, into webservice for example, or with performances, you can delete unused lines like this:

DELETE FROMps_stock_availableWHERE id_shop = XXXX

Just replace XXXX by the id which should be deleted, it should be "0" if you have just disabled stock sharing. Backup your database before!

florine2623 commented 2 years ago

Hello @Max84 ,

I dont have the exact same result as you :

Screenshot 2022-06-17 at 16 52 37 Screenshot 2022-06-17 at 16 52 28

I create my product ID = 20 in my shop id = 3. So it means that only the first line should be in the database, not the 2 others ?

Could you share how you create your different shops/ group shops ?

In my case, I have 1 group with 3 shops.

Thanks!

Max84 commented 2 years ago

Hi @florine2623,

It's not really the same step to reproduce:

  1. Install a new Prestashop with demo products
  2. Enable multishop
  3. Add a new shop into the same group, stock share is enable. Save this
  4. Check DB, for example product id x (without combination), you will see 1 line for this product into stock_available table, with id_shop = 0.
  5. Disable stock sharing
  6. Check DB, for example product id x (without combination), you will see 3 lines for this product into stock_available table, with id_shop = 0, id_shop = 1 and id_shop = 2. You shouldn't have a line with id_shop = 0.

Do you get it?

Best regards,

Max84 commented 2 years ago

Changing stock sharing parameter is the way to reproduce it. If you don't update stock sharing, you don't get this bug.

AureRita commented 2 years ago

Hi @Max84

Thank to have given us more details, I tried to reproduce your issue witth all your details, but I currently can't reproduce it, I follow your step as you can see in this video :

https://user-images.githubusercontent.com/100699445/174609966-894582ee-099b-4031-8649-a305a55eaf93.mp4

did I missed a details ?

Waiting for your feedback

Max84 commented 2 years ago

Hi @AureRita , @florine2623

I'm sorry, I think I've forgotten a step (updating product). Please, check my video (tested with the latest: 1.7.8.6):

https://user-images.githubusercontent.com/6622400/175035065-87f9e384-a169-485a-a3f7-a345e21bad1c.mp4

Max84 commented 2 years ago

maybe a better video: https://drive.google.com/file/d/1-TGDG3m2OO1lfwZxZ4snzCZEXDOojZno/view?usp=sharing

sLorenzini commented 2 years ago

hello @Max84,

Thank you for your last screenrecord.

I reproduce the issue with PrestaShop version 1.7.7.8 & 1.7.8.6. I'll add this to the backlog so it can be fixed.

Please be aware that some issues might take a very long time to be resolved.

If you fix the issue on your end, please contribute it back to the project. Remember that the more people contribute, the better PrestaShop becomes for everyone.

Thank you