News:

Support the VirtueMart project and become a member

Main Menu

FIX - Shopper groups for Stockable Variants

Started by atrus, July 11, 2013, 18:04:47 PM

Previous topic - Next topic

atrus

As you know, stockable Variants in 2.0.21b (haven't checked 2.0.22 yet) don't support shopper groups.

Go to  /plugins/vmcustom/stockable/stockable.php around line 622:

FIND

$db->setQuery('SELECT `product_price` FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_id`="' . (int)$selected . '"');

CHANGE IT TO

$db->setQuery('SELECT `product_price` FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_id`="' . (int)$selected . '" AND `virtuemart_shoppergroup_id`=???');

Where ??? should be the current shopper group of the visitor. Maybe someone could help to fill this in.

Rgrds

Milbo

Please try the attached file

[attachment cleanup by admin]
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

atrus

Hi Milbo,

Just tried the file with VM2.0.22. I am getting:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 512 bytes) in .../public_html/libraries/joomla/base/object.php on line 120

Rgrds,
Chris

atrus

#3
Milbo, pls see below the fix for the problem:

In /plugins/vmcustom/stockable/stockable.php, add the following after the } else { on Line 626 (VM2.0.22):

// Get the user details

$usermodel = VmModel::getModel ('user');
$currentVMuser = $usermodel->getCurrentUser ();

$db = JFactory::getDbo();

if (is_array($currentVMuser->shopper_groups)) $shgroup = $currentVMuser->shopper_groups[0];

else $shgroup = $currentVMuser->shopper_groups;

$query = $db->getQuery(true)

->select($db->qn('product_price'))

->from($db->qn('#__virtuemart_product_prices'))

->where($db->qn('virtuemart_product_id').' = '.(int)$selected)

->where($db->qn('virtuemart_shoppergroup_id').' = '.$shgroup);

$db->setQuery($query);

// $db->setQuery('SELECT `product_price` FROM `#__virtuemart_product_prices` WHERE `virtuemart_product_id`="' . (int)$selected);

$price = $db->loadResult();

if (empty($price))

{

// Check for price to show to all

$query->clear('where')

->where($db->qn('virtuemart_product_id').' = '.(int)$selected)
->where('('.$db->qn('virtuemart_shoppergroup_id').' = 0 OR '.$db->qn('virtuemart_shoppergroup_id').' = NULL)');

$db->setQuery($query);

$price = $db->loadResult();

}

if (!empty($price)) $product->product_price = (float)$price;


Just note that above fix works only if the user is assigned to 1 group, not multiple shopper groups.

Pls see attached correct file.

Regards,
Chris

[attachment cleanup by admin]

atrus

Hi Milbo,

Let me know if you agree with the code.

Rgrds,
Chris