Author Topic: FIX - Shopper groups for Stockable Variants  (Read 3001 times)

atrus

  • Jr. Member
  • **
  • Posts: 127
FIX - Shopper groups for Stockable Variants
« 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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10070
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: FIX - Shopper groups for Stockable Variants
« Reply #1 on: July 11, 2013, 22:07:15 pm »
Please try the attached file

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

atrus

  • Jr. Member
  • **
  • Posts: 127
Re: FIX - Shopper groups for Stockable Variants
« Reply #2 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

atrus

  • Jr. Member
  • **
  • Posts: 127
Re: FIX - Shopper groups for Stockable Variants
« Reply #3 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):

Code: [Select]
// 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

  • Jr. Member
  • **
  • Posts: 127
Re: FIX - Shopper groups for Stockable Variants
« Reply #4 on: July 24, 2013, 10:51:02 am »
Hi Milbo,

Let me know if you agree with the code.

Rgrds,
Chris