Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento get simple product's custom attribute value of a configurable product

If you want to get simple product's custom attribute value of a configurable product, like Color is your custom dropdown attribute of simple product and if you want to display available color of a configurable product on your category OR product list page or product details page, you can try following solution.

<?php 
  $simpleCollection = "";
  if($_product->getTypeId() == "configurable"){
     $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
     $simpleCollection = $conf->getUsedProductCollection()->addAttributeToSelect('*');
     
     foreach($simpleCollection as $simpleProduct){
            $optLbl = $simpleProduct->getAttributeText('color');
            echo $simpleProduct->getId()." ".$simpleProduct->getSku()." ".$optLbl."<br>";
     }
   }
?>

Please support us, Like us on Facebook.

  1. Great. Works fine.
    Thanks...

    ReplyDelete
  2. Thanks for sharing this information.It was very nice blog to learn about
    magento

    ReplyDelete

 

Copyright @ 2017 HKBlog.