Php – Magento Configurable Product Attributes

e-commercemagentoPHP

hey guys, having an issue with magento which i just cant seem to find a solution to.

i have tried many ways of getting a configurable products attributes (simple products) and listing them, now i have them listing from 2 ways but the way im working with is below

$confAttributes = @$_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);

$sizes = array(); foreach($confAttributes AS $atts){ //print '';//'<pre style="display:none;">'.print_r($atts).'</pre>'; if($atts['label'] == 'Size'){ foreach($atts['values'] AS $val){ $sizes[] = $val['store_label']; } } }

my only problem with this now is i need to only pull back the size attributes which are in stock – looked through mage files to find solution but just cant see anything – the result i need is done in config product php file but i cant access it from in the code where i need to list the size attribute.

any help would be great, thanks!

Best Answer

Solution: You can get easily all configurable(product) details page information on any other PHTML file by using following code: e.g.: in my case i'm getting details on catalog/product/list.phtml.

 <script src="<?php echo Mage::getBaseUrl('js') ?>varien/configurable.js" type="text/javascript"></script>
        <?php
        $temp = new Mage_Catalog_Block_Product_View_Type_Configurable();
        $temp->setData('product', $_product);                    
        $_attributes = Mage::helper('core')->decorateArray($temp->getAllowAttributes()); 
        ?>
        <?php if ($_product->isSaleable() && count($_attributes)):?>
            <?php foreach($_attributes as $_attribute): ?>
            <?php
                $prices = $_attribute->getPrices();
                foreach($prices as $price) {
                    echo $price['pricing_value'] . "<br/>";
                }
            ?>
            <?php endforeach; ?>
            <script type="text/javascript">
                var spConfig = new Product.Config(<?php echo $temp->getJsonConfig() ?>);
            </script>
        <?php endif;?>      

Thanks,