PHP Magento Tips

How to Get All simple products Configuration Array from a Configurable Product in Magento

Rate this posting:
{[['']]}

In your magento Module, Sometimes you need all information about your simple product's Configuration from Configurable Product ID.

In your Magento Module's PHTML file write below code to achieve this.

<?php

    $_product           = $this->getProduct();

    $_product_id      = $this->getProduct()->getId();

    $_product_type  = $this->getProduct()->getTypeId();

    //output "simple" for simple product and "configurable" for configurable product

    $_product_name  = $this->getProduct()->getName();

    $_product_desc  = $this->getProduct()->getDescription();

    $_product_slash_desc  = addcslashes($_product_desc,"\\\'\"\n\r");

    // will solve new line issue to assign this variable to Javascript variable.

?>

    <?php if($_product->getTypeId() == "configurable"): ?>

        <?php $_configurable = $_product->getTypeInstance()->getUsedProductIds(); ?>

        <?php foreach ($_configurable as $_config): ?>

            <?php $_simpleproduct = Mage::getModel('catalog/product')->load($_config); ?>

            <?php

                echo "<pre>";

                print_r($_simpleproduct);

                echo "</pre>";

            ?>

        <?php endforeach; ?>

    <?php endif; ?>

After writing above code you will get all simple product's Configuration options in a single Array.
Tag : Magento
0 Comments On "How to Get All simple products Configuration Array from a Configurable Product in Magento"

Back To Top