Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out master product of simple product?

Tags:

php

magento

How can I find out, if a simple product is part of a configurable product and then get the master product? I need this for the product listing.

Just found out:

$_product->loadParentProductIds();
$parentIds = $_product->getParentProductIds();
like image 211
Thomas Müller Avatar asked Dec 13 '22 21:12

Thomas Müller


2 Answers

Let's say that you have your simple product's Product ID.

To get all the parent configurable product IDs of this simple product, use the following code:-

<?php
$_product = Mage::getModel('catalog/product')->load(YOUR_SIMPLE_PRODUCT_ID);
$parentIdArray = $_product->loadParentProductIds()
                 ->getData('parent_product_ids');
if(!empty($parentIdArray)) {
    // currently in the master configurable product
    print_r($parentIdArray); // this prints all the parent product IDs using your simple product.
}
?>

I suppose this should get you going.

like image 167
Knowledge Craving Avatar answered Dec 23 '22 12:12

Knowledge Craving


For Magento 1.4.2 and above use the following method instead:

$configurable_product_model = Mage::getModel(‘catalog/product_type_configurable’);
$parentIdArray = $configurable_product_model->getParentIdsByChild($simple_product_id);
like image 43
brogr Avatar answered Dec 23 '22 13:12

brogr