VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: gap on February 12, 2021, 17:23:21 PM

Title: Multivariant Stock handle bug (don't show product if no stock)
Post by: gap on February 12, 2021, 17:23:21 PM
VirtueMart 3.6.2 10159
Multivariant products have a bug in case you select "don't show product if there is no stock" by the child product. If you had 1 pc of the item and someone bought it then you cannot select the attribute and it gives an error message.
For example if you have 2 dropdowns, one for colors (red, blue) and one for sizes L-M-S, and you ran out of red-L then it will still load the red L combination into dropboxes but you cannot select Red-L, it will show a mistake.
Currently it's the only solution if you turn off the child product. If you DELETE the child product you will get more headache as VM doesn't update the variable's database field and the deleted product will be still contained by the multivariation that will give you more errors. I had to manually edit the mysql database field of this multivariant and remove the deleted product.

I read the current update descriptions and they were not corrected as far as I know.
Title: Re: Multivariant Stock handle bug (don't show product if no stock)
Post by: Jörgen on February 12, 2021, 18:31:41 PM
VM 3.6.2 is 1,5 years old, there have been over 300 bug fixes since them. Please try the latest version on a test site and see if You can replicate the error.

Jörgen @ Kreativ Fotografi
Title: Re: Multivariant Stock handle bug (don't show product if no stock)
Post by: gap on February 27, 2021, 16:51:33 PM
Hi Jörgen,

After updating to VirtueMart 3.8.8 10472 the problem is still present.
Title: Re: Multivariant Stock handle bug (don't show product if no stock)
Post by: gap on November 13, 2021, 16:27:37 PM
Hi again,

This issue is still present. Newer version hasn't brought a solution.
Can anyone tell me how to fix that the plugin shall check first if
- "don't show product if no stock" is ON
and
- child product has 0 stock
then it shall not load it in multivariant dropdowns?
Title: Re: Multivariant Stock handle bug (don't show product if no stock)
Post by: gap on November 14, 2021, 18:19:20 PM
There is a part in customfield.php that should make a filtering but it doesn't make the job.
children products: "don't show product if no stock"
If parent product has "don't show if there is no stock of the child", the situation is a bit better.
example:
dropdown1: color
dropdown2: size

Let's say red "XL" size is out of stock and would disappear.
If you go to a product that is "red" in this case the XL won't load in the dropdown2. Fine.
But if you change to "green" and XL and then you want to change to red, the dropdown2 won't reload and remains on "XL" and it gives a js error.
If parent product has NOT "don't show if there is no stock of the child", the XL will always load in the dropdown2.

I couldn't figure out how to fix this code. Can you help?

case 'C':
                    $html = '';

                    $dropdowns = array();

                    if(isset($customfield->options->{$product->virtuemart_product_id})){
                        $productSelection = $customfield->options->{$product->virtuemart_product_id};
                    } else {
                        $productSelection = false;
                    }
                    $stockhandle = VmConfig::get('stockhandle_products', false) && $product->product_stockhandle ? $product->product_stockhandle : VmConfig::get('stockhandle','none');


                    $extra = ' and ( published = "1" ';
                    if($stockhandle == 'disableit_children'){
                        $extra .= ' AND (`product_in_stock` - `product_ordered`) > "0" ';
                    }
                    $extra .= ')';


                    $productModel = VmModel::getModel ('product');
                    $avail = $productModel->getProductChildIds($customfield->virtuemart_product_id, $extra);
                    if(!in_array($customfield->virtuemart_product_id,$avail)){
                        array_unshift($avail,$customfield->virtuemart_product_id);
                    }