Get all saleable simple products from configurable product

The following function just gets all saleable (if saleable check is enabled in the Magento configuration) child products from a configurable product:

/**
 * Get saleable simple products from configurable parent product
 *
 * @var Mage_Catalog_Model_Product_Type_Configurable $oParentProduct
 * @return array of Mage_Catalog_Model_Product(Mage_Catalog_Model_Product_Type_Simple)
 */
public function getAllowedProducts($oParentProduct)
{
    $aProducts = [];
    $bSkipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
    $oAllProducts = $oParentProduct
        ->getTypeInstance(true)
        ->getUsedProducts(null, $oParentProduct);
    foreach ($oAllProducts as $oProduct) {
        if ($oProduct->isSaleable() || $bSkipSaleableCheck) {
            $aProducts[] = $oProduct;
        }
    }

    return $aProducts;

}

 

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.