Author Topic: Link to the parent product  (Read 816 times)

Wtor22

  • Beginner
  • *
  • Posts: 1
  • A beginner
  • Skype Name: Wtor22
Link to the parent product
« 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

hazael

  • Jr. Member
  • **
  • Posts: 79
    • Bi┼╝uteria etniczna i orientalna
  • VirtueMart Version: 3.8.9
Re: Link to the parent product
« Reply #1 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"

Jumbo!

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 807
  • Full-stack Web Developer
    • www.virtueplanet.com
  • VirtueMart Version: Always latest
Re: Link to the parent product
« Reply #2 on: March 22, 2022, 17:15:28 pm »
You can use the following codes on the product details page.

Code: [Select]
<?php
if (!empty($this->product->product_parent_id))
{
$model         VmModel::getModel('product');
$parentProduct $model->getProduct($this->product->product_parent_idtruetruetrue1);

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