Gets all simple products that belong to a “enabled” configurable product
-
11-12-2019 - |
質問
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.
解決
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.
他のヒント
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);
所属していません magento.stackexchange