News:

Support the VirtueMart project and become a member

Main Menu

Possible BUG in sublayouts/customfield.php

Started by razor7, November 08, 2017, 13:02:17 PM

Previous topic - Next topic

razor7

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
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

razor7

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...
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Milbo

there is a svn, and when you would just use the web interface, you could download the updated file already.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

razor7

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...
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

Milbo

you can also create a patch file with Git for svn and send it.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/