Forums / Bug Reports / While editing product, Product Qty Units displays as 1 if it is 0 on the database

While editing product, Product Qty Units displays as 1 if it is 0 on the database

Started by mohirl on 10 Aug 2012, 3:29 AM · Views: 795

Results 1 to 3 of 3
10 Aug 2012, 3:29 AM
#1
mohirl avatar

mohirl

New Zenner

Join Date:
Aug 2012
Posts:
5
Plugin Contributions:
0

While editing product, Product Qty Units displays as 1 if it is 0 on the database

If the 'Product Qty Units:' field (database field products.products_quantity_order_units) is set to zero for a product, an error is displayed when adding the product to the cart :

Please update your order.
The item: <item name here> ... Quantity Units errors -
You ordered a total of: 1 Units: 0

While editing an existing product, if the field value is 0, it will be displayed as 1.
(line 378 in admin/includes/modules/product/collect_info.php, and other versions of collect_info.php for other product types).

<td class="main"><?php echo TEXT_PRODUCTS_QUANTITY_UNITS_RETAIL; ?></td>
<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . [B]zen_draw_input_field('products_quantity_order_units', ($pInfo->products_quantity_order_units == 0 ? 1 : $pInfo->products_quantity_order_units))[/B]; ?></td>

This is presumably because the same code is used when setting up new products, and it's desirable to default the field to 1 to prevent this issue happening.
It might also make sense, whenever existing products are edited, to set the field to 1 if it's 0 when the product is saved, to prevent the cart error happening.
But the way it works at the moment, it's masking the issue by displaying different data to what's in the database:
if you do somehow end up with this field set to 0 for some products, and are getting the cart error, checking the product details in admin would lead you to believe that the problem must lie elsewhere.

The code is somewhat incorrect as it is: $pInfo->products_quantity_order_units is a string, not an integer. For new products, it will be an empty string at this point, so evaluates as 0, and hence the field gets set to 1.
If it's an existing product with zero value, the same happens, which is where the problem lies.

It would make more sense to change this line to handle 3 conditions:
if $pInfo->products_quantity_order_units = "" (new product), default the field to 1
if $pInfo->products_quantity_order_units = "0", display as 0, with a warning message that it should always be at least 1
Otherwise display the current value.

Either that or change the value from 0 to 1, but when actually writing the record, not when displaying it.

The same also applies to 'Product Qty Minimum:', but this doesn't cause an issue, since it doesn't matter whether the minimum quantity is 0 or 1 (although it does allow you to add 0 items to your cart).

10 Aug 2012, 4:14 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: While editing product, Product Qty Units displays as 1 if it is 0 on the database

Mohirl:

If the 'Product Qty Units:' field (database field products.products_quantity_order_units) is set to zero for a product, an error is displayed when adding the product to the cart
By what process did you arrive at a situation where the field is set to zero for an existing product?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

10 Aug 2012, 7:46 AM
#3
mohirl avatar

mohirl

New Zenner

Join Date:
Aug 2012
Posts:
5
Plugin Contributions:
0

Re: While editing product, Product Qty Units displays as 1 if it is 0 on the database

Initially, by not having a clue what I was doing when populating the fields for a product import with EasyPopulate :smile:

But it's also possible to do it through the admin - simply change the field from 1 to 0 when creating or editing a product.