VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: gallego.d on September 20, 2017, 21:34:27 PM

Title: Multi variant trouble, child not showing parent option in select
Post by: gallego.d on September 20, 2017, 21:34:27 PM
Hi, not sure if it's a migration issue or a bug,

the thing is that i've seen this on a couple of posts, only from previous versions, and suggested workarounds doesn't work,
having a J3.7.5 VM 3.2.4 multilanguage site, with previous products (with multivariants and child products from a J3.6.5 VM3.0.16), newly created multivariant products don't work as expected,

- previously the 'main' product had it's own price, images, etc, and the child created by using the multivariant had their own prices/ranges, images, etc., by entering the product the visitor can switch between products (by using two predefined ranges such as size and colour) , this still applies to older products with more complex multivariants,

- now, repeating the same process we end up with a product that, when selecting size, the parent option disappear from the select,
for example, for a product with a multivariant like this
book01 - A6 (this is the main product)
book02 - A5 (the child)
when the customer enters the book01, it can choose the A5 size, but once chosen it can never go back (select the original A6 option)

any help in troubleshooting / patching this issue would be much appreciated,
Title: Re: Multi variant trouble, child not showing parent option in select
Post by: Jordi B on November 22, 2017, 09:31:19 AM
Hi, Same problem in one dimension multivariant in new version VM 3.2.4.
When I select the child the main product can't be selected any more.
Have you solved it?

Title: Re: Multi variant trouble, child not showing parent option in select
Post by: Jordi B on November 22, 2017, 13:20:12 PM
Hi,
I find  the problem.
In the last version 3.2.4 in customfield.php sublayout the code for ignore in the select multivariant the products not published was changed from the old code:

$q = 'SELECT `virtuemart_product_id` FROM #__virtuemart_products WHERE product_parent_id = "'.$customfield->virtuemart_product_id.'" and ( published = "0" ';
if($stockhandle == 'disableit_children'){
$q .= ' OR (`product_in_stock` - `product_ordered`) <= "0"';
}
$q .= ');';
$db = JFactory::getDbo();
$db->setQuery($q);
$ignore = $db->loadColumn();
//vmdebug('my q '.$q,$ignore);

foreach($customfield->options as $product_id=>$variants){

if($ignore and in_array($product_id,$ignore)){
//vmdebug('$customfield->options Product to ignore, continue ',$product_id);
continue;
}



to the new code:

$q = 'SELECT `virtuemart_product_id` FROM #__virtuemart_products WHERE product_parent_id = "'.$customfield->virtuemart_product_id.'" and ( published = "1" ';
if($stockhandle == 'disableit_children'){
$q .= ' AND (`product_in_stock` - `product_ordered`) > "0" ';
}
$q .= ');';
$db = JFactory::getDbo();
$db->setQuery($q);
$avail = $db->loadColumn();
array_unshift($avail,$product->virtuemart_product_id);


foreach($customfield->options as $product_id=>$variants){
static $counter = 0;
if(!in_array($product_id,$avail)){
vmdebug('$customfield->options Product to ignore, continue ',$product_id);
continue;
}


This code isn't work on the child products because in $avail array never find the parent product id, and so in the child we can't select the parent option.
I've copied the sublayout to my template and I add the code:

array_unshift($avail,$product->product_parent_id);

so in $avail array we have always self product id, need when the product is the parent, and parent id, need  when product is  a child.
I don't know if this can affect other cases, but in my case work ok.
Title: Re: Multi variant trouble, child not showing parent option in select
Post by: GJC Web Design on November 23, 2017, 23:28:15 PM
is this not the bug fixed?

Changes in VirtueMart version 3.2.6

Very important fix for multivariants, which lost in some conditions the parent option, when changing to a child.
Title: Re: Multi variant trouble, child not showing parent option in select
Post by: Jordi B on November 27, 2017, 11:25:44 AM
Yes, in my case in VM 3.2.6 the issue was fixed.
Thanks