VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: atrus on July 11, 2013, 18:04:47 PM

Title: FIX - Shopper groups for Stockable Variants
Post by: atrus on July 11, 2013, 18:04:47 PM
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
Title: Re: FIX - Shopper groups for Stockable Variants
Post by: Milbo on July 11, 2013, 22:07:15 PM
Please try the attached file

[attachment cleanup by admin]
Title: Re: FIX - Shopper groups for Stockable Variants
Post by: atrus on July 12, 2013, 02:30:40 AM
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
Title: Re: FIX - Shopper groups for Stockable Variants
Post by: atrus on July 14, 2013, 14:01:24 PM
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]
Title: Re: FIX - Shopper groups for Stockable Variants
Post by: atrus on July 24, 2013, 10:51:02 AM
Hi Milbo,

Let me know if you agree with the code.

Rgrds,
Chris