1

I used following code:

$productCollection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')
        ->setFlag('require_stock_items', true)
        ->setFlag('product_children', true);

But how can only select simple products that belongs to an enabled configurable product (status = 'enabled'). Above code don't care about parent product's status. I need most efficient way to do it as I have thousands of products in my store.

2 Answers 2

2

Please using the follow code:

$configurable= Mage::getModel('catalog/product_type_configurable')->collection();
$simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

This will give you all simple product array belong to configurable product. For enable make sure to

addAttributeToSelect

enalble product or status having yes. Hope this will help you.

0
if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
        echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
endif;

second code Use with set product filter

$productCollection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')
            ->setFlag('require_stock_items', true)
            ->setFlag('product_children', true)     
            ->setProductFilter($this->getProduct($_product))      
            ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.