VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: razor7 on November 08, 2017, 13:02:17 PM

Title: Possible BUG in sublayouts/customfield.php
Post by: razor7 on November 08, 2017, 13:02:17 PM
Hi! I think I found a bug in components/com_virtuemart/sublayouts/customfield.php

In my case, I have all my products with multivariant custom field, all products have multivariant 3 childs so rendering the product details in the frontend gives me a selection box for those multivariant with four options.

After upgrading to VM 3.2.4, I noticed when rendering the parent product, I have four options as usual, but when rendering some of the childs (after selecting some of the dropdown options), I got just three options, leaving behind the parent, so I can choose only the three childs.

Looking into the code, I have found in sublayouts/customfield.php that line 97 which executes an array_unshift is wrong array_unshift($avail, $product->virtuemart_product_id);, this way you end up adding the current child product twice!, so for a fix, I changed this:

$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);

To this:
$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, $customfield->virtuemart_product_id);


The change on the array_unshift is to add $customfield->virtuemart_product_id  which seems to hold the product parent id. This way I have a dropdown to select all four products (parent and childs) as expected
Title: Re: Possible BUG in sublayouts/customfield.php
Post by: Milbo on November 08, 2017, 16:33:30 PM
thank you. Yes 100% right, this fix is already in the svn, just did not dare to make the new release. I am sorry I have to upload it asap.
Title: Re: Possible BUG in sublayouts/customfield.php
Post by: razor7 on November 09, 2017, 20:15:48 PM
Quote from: Milbo on November 08, 2017, 16:33:30 PM
thank you. Yes 100% right, this fix is already in the svn, just did not dare to make the new release. I am sorry I have to upload it asap.

Just wondering, do you plan to publish VM code in github? that way we can send pull request for things like this...
Title: Re: Possible BUG in sublayouts/customfield.php
Post by: Milbo on November 09, 2017, 20:45:12 PM
there is a svn, and when you would just use the web interface, you could download the updated file already.
Title: Re: Possible BUG in sublayouts/customfield.php
Post by: razor7 on November 28, 2017, 16:41:06 PM
Quote from: Milbo on November 09, 2017, 20:45:12 PM
there is a svn, and when you would just use the web interface, you could download the updated file already.

Yes, I mean, maybe with GitHub we can just send a Pill Request to the project for you to analize, that way, maybe, you got issues resolved by users. Just a thought...
Title: Re: Possible BUG in sublayouts/customfield.php
Post by: Milbo on November 29, 2017, 19:15:02 PM
you can also create a patch file with Git for svn and send it.