Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong quantities showing in BO for products with combinations #12814

Open
Tracked by #19846
oskarna opened this issue Mar 7, 2019 · 20 comments
Open
Tracked by #19846

Wrong quantities showing in BO for products with combinations #12814

oskarna opened this issue Mar 7, 2019 · 20 comments
Labels
8.1.x Branch BO Category: Back Office Bug Type: Bug Combinations Product type: issue about products with combinations Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification New Products Page Label: Which BO under menu is concerned Ready Status: Issue is ready to be worked on Topwatchers Backlog prioritization: issue reported & followed by +6 people Verified The issue has been reproduced

Comments

@oskarna
Copy link

oskarna commented Mar 7, 2019

I noticed out that Prestashop is calculating wrong quantities in a certain case for products with quantities. After several tests I have found out how is it happening.

This issue is quite problematic for shops, that decided to control their quantities by prestashop's BO, instead of inventory managemenet software etc. I know this type of software COULD help, but this is Prestashop bug that should be fixed anyway.

How to achieve it?

Simple description

  1. Create combinations for product.
  2. Customer makes order.
  3. Delete combinations from product.
  4. Create again combinations for product.
  5. Order cancelled.
  6. Overall quantity showed in BO products list is calculated wrong.

Detailed description

1.) We have product XYZ with size combinations:
S, M, L, XL.
in database inside table pr_stock_available they have id_product_attribute:
120, 121, 122, 123

2.) Customer is making order for 5 pieces of M size.

3.) Now we are deleting size M from product XYZ only. We are deleting it because we need to make it not appear, because for e.g. this size for product XYZ it is temporary not avaible for some reason.

4.) We are adding size M back to our product XYZ (we decided to put it in offer again).
If we take a look in database now - id_product_attribute for new "size M" have different ID than before. So we have again sizes:
S, M, L, XL,
but in database their IDs are:
120, 4117, 122, 123.

5.) Our customer from pt. 2 is returning product (5 pieces). We are changing order status for cancelled - quantity is returned back to combination with ID 121.

Now we can make another look in database.
Combination with ID 121 is recreated back and now for our product XYZ we have 5 combinations:
120, 121, 122, 123, 4117
Our old "size M" combination have id 121 with quantity that is equal 5.

Now in BO we can edit combinations of our product like this:
size S = quantity 0
size M = quantity 0
size L = quantity 0
size XL = quantity 0

In moment that we hit "save" button, prestashop is calculating overall quantity (that is show in BO products list):
0+0+0+0+5= 5 pieces
but in backoffice we can clearly see in combinations tab that they are set for 0.

We can set product for "simple product" and set quantity to "0". Unfortunately after we generate combinations - after we hit "save" button - quantity is calculated wrong way again.

Half-solutions?

Half-solutions that we have tried are listed below. But in cases A and B it is hard to precisely determine when we have to fix our product. It may be a while before we find it out.

A.) You can manually change quantity of invisible combination in database.
This soultion is not acceptable for shop that have dozens of orders per day.

B.) We could create custom "cancelled" status for orders, that is not returning quantites back. Sadly it is not good solution for shop with huge amount of orders.

C.) We could (in front) hide combinations that have quantity 0 and never delete them in BO. It will not work for shops that are using option for products on request:
Availability preferences -> Behavior when out of stock -> Allow orders

info

PrestaShop version: tested at 1.7.5, 1.7.4.4, 1.7.4.2, 1.7.3.1
PHP version: 7.0.32, 7.2.11

@khouloudbelguith
Copy link
Contributor

Hi @oskarna,

Thanks for your report.
Yes, I have the same behavior after following your steps.
After canceling the order, in the Product list page, we have a different quantity
image
image
Which is normal behavior.
I think the solution is the worst solution you are making because combinations are incrementally created.
So when you create a new combination, a new id will be created.

About this solution:

We could (in front) hide combinations that have quantity 0 and never delete them in BO

I think, it is the best solution to ovoid your problem.

It will not work for shops

Yes, you are right, we are aware of this issue, it is added to our debug roadmap.
It is reported in this ticket: #9667
Thanks to check & feedback.

@khouloudbelguith khouloudbelguith added BO Category: Back Office NMI Status: issue needs more information Combinations Product type: issue about products with combinations 1.7.5.1 Affects versions labels Mar 7, 2019
@ghost
Copy link

ghost commented Mar 7, 2019

I came here with a similar problem and I see that something is wrong with the quantity of products (stocks) in Prestashop when quantities are decreased manualy instead of automatic (via orders).

I have weird problem with store that was updated successfuly from 1.7.3.3 to 1.7.4.2 and 1.7.5.1.
Upgrades was always flawless (database is consistent) but some day customer says that disabled products (sold one) get back to live with available quantities... WTF...

Also i found that product quantity in BO product list show 2 (1 quantity per two sizes) but Stocks are emptied... HOW? It's very unpleasant issue ;/
geox
Looks like somewhere quantities are added +1. Is there a way to get rid of it?

@ghost
Copy link

ghost commented Mar 7, 2019

@oskarna try to not decrease quantities manualy but make an order from the front (like regular customer). One of my friend use Prestashop as PoS system. When something is sold in local store then his employee use his customer account to make an order.

@oskarna
Copy link
Author

oskarna commented Mar 7, 2019

@PrestaShark
As I described in my post - this value is in database, but it is not visible in backoffice.

Check table "pr_stock_available". Sort products by ID and You will see combination with quantity larger than zero. You can edit it and problem will be solved.

@khouloudbelguith
Copy link
Contributor

@oskarna, can I close the issue? it is a duplicate of #9667?
Is it? it is the only solution that exists.
THanks!

@oskarna
Copy link
Author

oskarna commented Mar 8, 2019

It is different situation, @khouloudbelguith

@khouloudbelguith
Copy link
Contributor

@oskarna,

I have the same behavior described by @oskarna.
After canceling the order, in the Product list page, we have a different quantity
image
image

In fact when we delete the combination with id_product_attribute = 201 
In the table ps_stock_available the column where id_product_attribute = 201 is deleted.
But when we cancel the order, this column is recreated in the table ps_stock_available

Before the suppression of the combination
image
After the suppression of the combination
image

After canceling the order
image

@marionf, what do you think?
Thanks!

@khouloudbelguith khouloudbelguith added TBR Status: issue to be reproduced Stocks Label: Which BO under menu is concerned Bug Type: Bug Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification and removed NMI Status: issue needs more information labels Mar 8, 2019
@marionf marionf added Ready Status: Issue is ready to be worked on and removed TBR Status: issue to be reproduced labels Mar 8, 2019
@marionf marionf removed their assignment Mar 8, 2019
@marionf marionf added the 1.7.6.0 Affects versions label Jun 10, 2019
@neich78
Copy link

neich78 commented Apr 29, 2020

Have a similar problem. Products with 4 combinations and different stock in each one. Stock does not match quantity shown in Catalog summary.
Please check product ID=3. Stock in combinations 103, but stock in summary = 335.

Captura de pantalla 2020-04-29 a las 11 26 54
Captura de pantalla 2020-04-29 a las 11 30 07

Prestashop 1.7.6.4

@jonpontet
Copy link

This is "still" outstanding right ?

Be great to get this "minor" bug that has large ramifications for so many ...fixed !

I see a lot of chatter but very little movement :(

@masiorama
Copy link

Experiencing the same issue on 1.7.7.4.

@masiorama
Copy link

In my case the issue is related to the cancellation of 2 product combinations with still 2 and 3 stocks, which led to a total of 5 available even if the "published" combinations were 0 (non available). I fixed the numbers on database and it was sorted for my specific case, but I guess that some sort of check on the stock quantity should be taken in consideration when a combination erase has been triggered.

@ocio87
Copy link

ocio87 commented Mar 8, 2022

Hello,

I present the same problem. Removing a combination does not remove the stock, nor does it remove the id_product_attribute.

https://drive.google.com/file/d/11RBnPRE92TnHw7Akqxyc-lk5jX6nKFZ0/view?usp=sharing

Php 7.4
Prestashop 1.7.8.2

@Mauro207
Copy link

I have the same problem on version 1.7.8.5. The quantities shown in the product list are incorrect.
Screen1

Where the total quantities between the combinations equals 1, I am shown 2 in the BO
Screen2

Repeated error in other products. Can I somehow fix it or am I waiting for a new update?

@prestashop-issue-bot prestashop-issue-bot bot added the Topwatchers Backlog prioritization: issue reported & followed by +6 people label Apr 27, 2022
@webstartconsulting
Copy link

We are the same problem at version 1.7.8.7 Not fixed yet? Any update?

@sketchypl
Copy link

any update? bump topic, i've the same problem

@MatShir
Copy link
Contributor

MatShir commented Jul 4, 2023

For this issue, why not to hide unavailable combination ? 🤔
The feature is available on the Product Setting "Display unavailable attributes on the product sheet".

@kpodemski
Copy link
Contributor

@MatShir also, probably to be validated on the new product list in 8.1

@MatShir MatShir added the New Products Page Label: Which BO under menu is concerned label Aug 21, 2023
@MatShir
Copy link
Contributor

MatShir commented Aug 21, 2023

Still present on the new product page. We have a workaround (we can hide the attribute out of stocks) for the FO until someone make a contribution on this issue

@KodeToad
Copy link

KodeToad commented Sep 6, 2023

This issue is still present in PS 8.1.1.

My analysis suggests that the rows in ps_stock_available are not being removed for combinations when the parent product is not removed also.
My experience is that after creating new combinations and removing old combinations for a product without removing the product, the old rows in this table remain with the quantities they had when they were removed with BO. These are then incorrectly added to the total quantity on the summary list pages.
It could be that this table was relying on cascade delete which is not functioning in this case.
The delete function in classes/Combination.php returns false if the parent::delete function is false without removing the relevant lines.

I can find affected lines with this sql:
select * from ps_stock_available psa WHERE psa.id_product_attribute <> 0 and NOT EXISTS (select pa.id_product_attribute from ps_product_attribute pa where psa.id_product = pa.id_product and pa.id_product_attribute = psa.id_product_attribute);

I'd like to know if just removing the offending lines in ps_stock_available will be enough or are there other rows which need to be tidied up as well? It looks as if ps_stock_available records where id_product_attribute = 0 need to be updated too.

@hibatallahAouadni hibatallahAouadni added Verified The issue has been reproduced 8.1.x Branch and removed 1.7.5.1 Affects versions 1.7.6.0 Affects versions labels Sep 14, 2023
@dmarczewski
Copy link

Has anyone found a solution to this problem yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.1.x Branch BO Category: Back Office Bug Type: Bug Combinations Product type: issue about products with combinations Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification New Products Page Label: Which BO under menu is concerned Ready Status: Issue is ready to be worked on Topwatchers Backlog prioritization: issue reported & followed by +6 people Verified The issue has been reproduced
Projects
None yet
Development

No branches or pull requests