1

i have configurable product made from different atrributes like : color , size, fabric

now i wrote code below to get all simple product from configurable products

$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($this->getProduct());
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

foreach($simple_collection as $simple_product){
    echo "<tr><td>". $simple_product->getName() ."</td><td>".$simple_product->getSku()."</td><td>".Mage::helper('core')->currency($simple_product->getPrice())."</td><td>".$simple_product->getQty()."</td></tr>";
}

1:now i want to get all atributes from which configurable product is made and there respective value for simple products, ie value of color, size and fabric for all products

2:qty show blank why ??

3
  • you have to again load the product and then you can display all attribute of that product
    – Keyul Shah
    Nov 11, 2014 at 7:26
  • 2
    @KeyulShah while this is true performance/ best practice wise you should never load a whole object in a loop. Use a propper collection instead
    – Sander Mangel
    Nov 11, 2014 at 7:27
  • @SanderMangel I agree with you.
    – Keyul Shah
    Nov 11, 2014 at 7:30

1 Answer 1

1

load config product:

   $currentProduct = Mage::getModel('catalog/product_type_configurable')->setProduct($this->getProduct());;

    $products = array();

        $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();

getting all all simple products

    $allProducts = $conf->getTypeInstance(true)
            ->getUsedProducts(null, $conf);

    foreach ($allProducts as $product) {
        $products[] =  $product;
    }
        getting all configurable attribute of that products
        $AllowAttributes=$conf->getTypeInstance(true)
            ->getConfigurableAttributes($conf);

Getting config attribute for this product by attribute value id and label

    foreach ($products as $product) {
       foreach ($AllowAttributes as $attribute) {

            $productAttribute   = $attribute->getProductAttribute();
            $productAttributeId = $productAttribute->getId();
            $attributeValue     = $product->getData($productAttribute->getAttributeCode());
            /* Simple Product data */

            /* getting option text value */
            if ($productAttribute->usesSource()) {
                 $MYabel = $productAttribute->getSource()->getOptionText($attributeValue );
            }else{
                 $MYabel='';
            }


        }
    }

Your Answer

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

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