Description:
Products which have multiple prices and are discounted have a random retail price chosen as the comparison price, resulting in very strange discount numbers. This also affects the price shown in the main product configuration page.
Versions affected:
I have checked both VM114 and VM115, both are affected.
Offending code:
ps_product->get_retail_price()
$q = "SELECT product_price,product_currency,price_quantity_start,price_quantity_end
FROM #__{vm}_product_price
WHERE product_id='$product_id' AND
shopper_group_id='$default_shopper_group_id'";
$db->query($q);
if ($db->next_record()) {
$price_info["product_price"]= $db->f("product_price");
$price_info["product_currency"]=$db->f("product_currency");
$price_info["price_quantity_start"]=$db->f("price_quantity_start"); // added alatak
$price_info["price_quantity_end"]=$db->f("price_quantity_end");// added alatak
}
else {
$price_info["product_price"]= "";
$price_info["product_currency"] = $_SESSION['vendor_currency'];
$price_info["price_quantity_start"]=$db->f("price_quantity_start"); // added alatak
$price_info["price_quantity_end"]=$db->f("price_quantity_end");// added alatak
}
return $price_info;
The code grabs the first result. That resulting price ultimately depends on the order by which the administrator entered prices.
Fix:
Sort the results from highest to lowest, so the first price (and therefore the resulting retail price) is the highest possible retail price:
$q = "
SELECT
product_price,product_currency,price_quantity_start,price_quantity_end
FROM
#__{vm}_product_price
WHERE
product_id='$product_id'
AND
shopper_group_id='$default_shopper_group_id'
ORDER BY
product_price DESC";
I have used this fix for a client with hundres of products, most of which have volume pricing. No issues with the fix reported so far.