VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: Wtor22 on November 13, 2021, 23:16:38 PM

Title: Link to the parent product
Post by: Wtor22 on November 13, 2021, 23:16:38 PM
Hello.
There was a need to create a link to the parent product on the child product page.
I really hope for help
Title: Re: Link to the parent product
Post by: hazael on March 22, 2022, 16:29:02 PM
Old topic, but let me write back:

if product is parent, change "virtuemart_product_id" to "product_parent_id"
Title: Re: Link to the parent product
Post by: Jumbo! on March 22, 2022, 17:15:28 PM
You can use the following codes on the product details page.

<?php
if (!empty($this->product->product_parent_id))
{
$model         = VmModel::getModel('product');
$parentProduct = $model->getProduct($this->product->product_parent_id, true, true, true, 1);

if ($parentProduct->virtuemart_product_id > 0)
{
echo 'Go back to Parent Product: <a href="' . JRoute::_($parentProduct->link) . '">' . $parentProduct->product_name . '</a>';
}
}
?>