Author Topic: [SOLVED] Getting parent product SKU (product page)  (Read 126 times)

EvanGR

  • Jr. Member
  • **
  • Posts: 363
[SOLVED] Getting parent product SKU (product page)
« 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):

Code: [Select]
$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


AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3276
  • VirtueMart Version: 3.8.4
Re: Getting parent product SKU (product page)
« Reply #1 on: October 16, 2020, 13:07:25 pm »
There could be a lot of reasons:

You could try:
Code: [Select]
$parentProduct = $productModel ->getProduct($product->product_parent_id, true, true, false);
See function arguments below:-

Quote
public function getProduct ($virtuemart_product_id = NULL, $front = TRUE, $withCalc = TRUE, $onlyPublished = TRUE, $quantity = 1,$virtuemart_shoppergroup_ids = 0) {
regards
A

Joomla 3.9.20
php 7.3

EvanGR

  • Jr. Member
  • **
  • Posts: 363
Re: Getting parent product SKU (product page)
« Reply #2 on: October 16, 2020, 13:49:34 pm »
This worked, thank you very much!

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3276
  • VirtueMart Version: 3.8.4
Re: [SOLVED] Getting parent product SKU (product page)
« Reply #3 on: October 16, 2020, 14:24:28 pm »
You are welcome  :)
regards
A

Joomla 3.9.20
php 7.3