VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: EvanGR on October 16, 2020, 10:22:57 AM

Title: [SOLVED] Getting parent product SKU (product page)
Post by: EvanGR on October 16, 2020, 10:22:57 AM
I am trying to get the SKU for the parent product, in a product page.
I do the following in the default.php (product page):

$parentProductId = $product->product_parent_id;
// $parentProductId is now 12434, good so far

$productModel = VmModel::getModel('Product');
$parentProduct = $productModel->getProduct($parentProductId);
print_r($parentProduct);
// this prints nothing


Can anyone spot the problem?

Thanks

Title: Re: Getting parent product SKU (product page)
Post by: AH on October 16, 2020, 13:07:25 PM
There could be a lot of reasons:

You could try:
$parentProduct = $productModel ->getProduct($product->product_parent_id, true, true, false);

See function arguments below:-

Quotepublic function getProduct ($virtuemart_product_id = NULL, $front = TRUE, $withCalc = TRUE, $onlyPublished = TRUE, $quantity = 1,$virtuemart_shoppergroup_ids = 0) {
Title: Re: Getting parent product SKU (product page)
Post by: EvanGR on October 16, 2020, 13:49:34 PM
This worked, thank you very much!
Title: Re: [SOLVED] Getting parent product SKU (product page)
Post by: AH on October 16, 2020, 14:24:28 PM
You are welcome  :)