You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Load product data with right prices based on shoppergroup

Started by JeremyAcy, September 01, 2015, 11:51:57 AM

Previous topic - Next topic


Hi, hope it's the right forum section for this question,

We developed a plugin that inserts VirtueMart products in a newsletter, but we have troubles getting the correct prices based on a specific shoppergroup  :'(

We're currently using this code:

$productId = 524;
$shoppergroup = array(2);

$vmProductModel = new VirtueMartModelProduct();
$product = $vmProductModel->getProduct($productId, false, true, false, 1, false, $shoppergroup);

$price = $product->product_price;
if($includeTax == 1 && !empty($product->prices['basePriceWithTax'])) $price = $product->prices['basePriceWithTax'];

But it does not seem to take the discount and rules into account for VM2 and VM3  :(

Do you have any API to load the product with the right prices? Ideally we would like to be able to get the price either with or without the tax.
Our script can be executed from the Front-end and the Back-end, and when it's executed there could be no user logged-in (executed with a cron task).

Thanks for any hint you could give us  ;D



To use the shoppergroup you need this "appendShopperGroups" before getting the product,

please use VmModel::getModel('product')
Should I fix your bug, please support the VirtueMart project and become a member
Extensions approved by the core team:


Thanks, I'll take a look at the "appendShopperGroups" and keep you informed ;)



I found my mistake in the previous post and removed the "false" parameter before adding the $shoppergroup parameter in this line:
$product = $vmProductModel->getProduct($productId, false, true, false, 1, false, $shoppergroup);

Now I get all the good prices with the good tax / discounts based on the shoppergroups I put in parameter except for one thing:
If I create a new "Tax & Calculation Rule" that applies -8% from the price for the Shopper group "Wholesale" for example, it won't be taken into account  :-\

Here is the code I use now:
$shoppergroups = array(2);

$user = new stdClass();
$user->guest = false;

$shopperModel = VmModel::getModel('ShopperGroup');
$shopperModel ->appendShopperGroups($shoppergroups,$user,false);

$vmProductModel = VmModel::getModel('product');
$product = $vmProductModel->getProduct(524, false, true, false, 1, $shoppergroups);

$price = $product->prices['product_price'];

Thanks for your help and patience,


Do you have any advise please? Shouldn't the getproduct function return the price by taking into account a global rule on the specified shoppergroup?



$shopperModel ->appendShopperGroups($shoppergroups,$user,false);

There is an inconsistency within the calculationhelper, which keeps its own shoppergroup ids. You may try to change them here, setShopperGroupIds.

Of course when you find a nice solution, I am interested.
Should I fix your bug, please support the VirtueMart project and become a member
Extensions approved by the core team:


Hello there,

I've used the following code to get the price of a product for a specific shoppergroup for some time in my extension:

$productId = 425;
$shopperGroupId = 3;

$vmProductModel = VmModel::getModel('product');
$product = $vmProductModel->getProduct($productId, false, true, false, 1, [$shopperGroupId]);

Depending on the VirtueMart version, the price will be in either $product->prices or $product->product_price. This is however no longer the case and $vmProductModel->getProduct will now ignore the provided shoppergroup IDs.
Is this a bug or has the method been changed to get the correct price for a specific shoppergroup?

This shoppergroup has this discount:

And on the product page, this price is displayed:

Thank you for any input, I'll continue searching but if someone has any clue on how to make it work with the latest version of VirtueMart that would be really appreciated