0

I want to get all in stock attributes in configurable products. I have got some code stack overflow, but these are showing non stock product also,

My code:

$configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
                $simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions('qty', array("gt" => 1));
                /* -------- Add this  ------- */
                $simpleCollection->getSelect()->join('cataloginventory_stock_status', 'cataloginventory_stock_status.product_id = e.entity_id', array('stock_status'));
                $simpleCollection->getSelect()->where("`cataloginventory_stock_status`.`stock_status` = 1");

                $productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
                $attributeOptions = array();
                foreach ($productAttributeOptions as $productAttribute) {

                foreach ($productAttribute['values'] as $attribute) {
                $attributeOptions[$productAttribute['label']][] = 
                array('id' => $attribute['value_index'],
                'label' => $attribute['label'],
                'mainId' => $productAttribute['attribute_id'] );
                }

                }
                print_r($attributeOptions);

its show all options but need only in stock attributes. please help

  • Please review it magento.stackexchange.com/a/95752 – Shorabh Aug 10 '18 at 9:08
  • @ShorabhKumarGupta your suggested answer is not correct, i am looking for only configurable attributes but it's qty most be more then 1 . – Shiv Singh Aug 11 '18 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.