Hello,
VM 4.2.4, Joomla 4.4.3, PHP 8.0
I need your help. How do I select the lowest price of a child in the product template?
Something like $this->product->getChildren($this->product->virtuemart_product_id)->price;
$min = min(.....);
Best regards
Andrej
Do you mean the lowest price of a product? or do you mean of all variants organised as children the lowest price first?
Something likes this...
$product = $this->product;
$productModel = VmModel::getModel('product');
$calculator = clone calculationHelper::getInstance();
$children = $productModel->getProductChildIds($product->virtuemart_product_id);
$cheapestPrice = $product->prices;
foreach ($children as $child)
{
$child = $productModel->getProduct($child);
if (!$child->published)
{
continue;
}
$childPrices = $calculator->getProductPrices($child, true, 1);
if (!empty($childPrices['product_price']) && (is_null($product->prices['product_price']) || $product->prices['product_price'] > $childPrices['product_price']))
{
$cheapestPrice = $childPrices;
}
}
echo $cheapestPrice['product_price'];
We have only an hidden config, to determine if the product should choose the highest entered price, or lowest entered price. This handles just the case, if your product has more than one price.
But your function looks quite correct, if you want the lowest price of all variants organised as children.
Hello,
thank you all for your reply.
Quote from: Dud3 on May 07, 2024, 16:34:35 PMI've slightly added your code and it works ;-)
Best regards
Andrej