Jump to content

Quantity not updating if product created by duplicating


europablue

Recommended Posts

I've discovered that for products that are created by duplicating an existing product (& then changing name & reference), product quantities are not displayed in the backoffice (catalog > products) or in the shop.

 

I am able to change stock levels in the Stock Management area, and it shows correctly there, and I even get a warning about existing physical stock when I try to delete a product.

 

There is no problem if I create a product from scratch (not by duplicating an existing product).

 

Any ideas & assistance will be greatly appreciated!

 

Thanks,

- Joel

Edited by europablue (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

 

 

I am able to change stock levels in the Stock Management area, and it shows correctly there, and I even get a warning about existing physical stock when I try to delete a product.

 

 

Same here!

But I can not even adjust the stock, it always says something like 'can not deduct from 0' while there are multiple items in the display.

Link to comment
Share on other sites

Hi, Sorry for not updating this post. I did a lot of looking into this and found some serious issues. With regard to this matter, it seems Prestashop stores product quantities in 2 different tables! Yes, I know, it's a problem. When a product is duplicated it leaves out a table. I don't remember the details exactly, and I forgot to document it properly. I will do that later today (hopefully). In the mean time, this is the query that fixes it:

UPDATE ps_stock_available, ps_stock
SET ps_stock_available.depends_on_stock = 1,
ps_stock_available.out_of_stock = 2,
ps_stock_available.quantity = ps_stock.physical_quantity
WHERE ps_stock_available.id_product = ps_stock.id_product

Bear in mind I have multistore & advanced stock management enabled.

 

 

Another issue is that form data isn't auto-trimmed, so trailing spaces are saved for crucial things like product reference, ISBN, etc. I fixed all this using PHP scripts as 3 tables need fixing, for example:

$sql = "SELECT id_product, reference
        FROM ps_product
        ORDER BY id_product";

$result = mysqli_query($link, $sql);

while ($row = mysqli_fetch_assoc($result)) {

    $id_product  = $row['id_product'];
    $reference = mysqli_real_escape_string($link, trim($row['reference']));

    $sql2 = "UPDATE ps_product
             SET reference = '$reference'
             WHERE id_product = $id_product";

    $result2 = mysqli_query($link, $sql2);

}



$sql = "SELECT id_stock, reference
        FROM ps_stock
        ORDER BY id_stock";

$result = mysqli_query($link, $sql);

while ($row = mysqli_fetch_assoc($result)) {

    $id_stock  = $row['id_stock'];
    $reference = mysqli_real_escape_string($link, trim($row['reference']));

    $sql2 = "UPDATE ps_stock
             SET reference = '$reference'
             WHERE id_stock = $id_stock";

    $result2 = mysqli_query($link, $sql2);

}



$sql = "SELECT id_product_attribute, reference
        FROM ps_product_attribute
        ORDER BY id_product_attribute";

$result = mysqli_query($link, $sql);

while ($row = mysqli_fetch_assoc($result)) {

    $id_product_attribute  = $row['id_product_attribute'];
    $reference = mysqli_real_escape_string($link, trim($row['reference']));

    $sql2 = "UPDATE ps_product_attribute
             SET reference = '$reference'
             WHERE id_product_attribute = $id_product_attribute";

    $result2 = mysqli_query($link, $sql2);

}

 

I figured this out through several forum posts on various related issues:

 

http://www.prestashop.com/forums/topic/1568[spam-filter]understanding-advanced-stock-management/page-2

 

http://www.prestashop.com/forums/topic/267979-prestashop-doesnt-update-stock-correctly/

 

http://www.prestashop.com/forums/topic/246543-change-products-qty-in-phpmyadmin-multistore/

 

http://www.prestashop.com/forums/topic/222884-1531-big-problem-with-product-quantity/

 

I hope this helps!

  • Like 2
Link to comment
Share on other sites

 

 

I hope this helps!

It sure does. Strange that none of the 'experts' have noticed this strange behaviors.

 

Not sure if your SQL solves the problem, I still have a lot of stock issues at the moment. So many issues that it is fair to say that the stock-management is useless.

Link to comment
Share on other sites

×
×
  • Create New...