17

I need to get the parent configurable product from a simple product, even if the parent product is marked as disabled. I also need to get the status of the configurable product (enabled or disabled).

Right now I'm getting the parent product like this:

$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
if (isset($parentIds[0])) {
    $product = Mage::getModel('catalog/product')->load($parentIds[0]);
}

This works perfectly unless the configurable product has been disabled, where the $parentIds array is empty. I need to get the configurable product even if it's disabled, and also determine if the configurable product is enabled/disabled.

Any help would be appreciated!

gregdev
  • 1,863
  • 3
  • 23
  • 28

1 Answers1

34

I've done a little digging around, and I can't seem to reproduce your issue.

When I call getParentIdsByChild() on a simple with a disabled configurable, I still get the parent product ID.

$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
      ->getParentIdsByChild(14412);
var_dump($parentIds);

Gives me:

array(1) {
  [0]=>
  string(5) "14446"
}

14446 has a status of disabled. I've also tried it as in stock and out of stock.

Looking at the actual function on the resource file

Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable::getParentIdsByChild()

I can see that it looks in the table catalog_product_super_link which doesn't have any fields for status, and therefore should always return the parent ID, if the product link exists.

Neil Aitken
  • 7,856
  • 3
  • 41
  • 40
  • Hi, thanks a lot for your effort! I'll do a little bit of research on my end to see what else could be causing this - I assumed that the problem was caused by the product being disabled as this seemed to be a common element, but perhaps I've missed something. – gregdev Feb 09 '12 at 05:52
  • +1 I was able to get both disabled and enabled product Ids from this. – Joshua Pack Jul 26 '13 at 15:22