Magento get configurable product from simple product even if config product is disabled

30,560

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.

Share:
30,560

Related videos on Youtube

gregdev
Author by

gregdev

Web and Android App developer

Updated on July 09, 2022

Comments

  • gregdev
    gregdev almost 2 years

    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
    gregdev over 12 years
    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.
  • Joshua Pack
    Joshua Pack almost 11 years
    +1 I was able to get both disabled and enabled product Ids from this.