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!
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.