0

i want to show color swatches from products id ( product object)

i tried below code

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

gives output like

Array
(
    [0] => Array
        (
            [id] => 2
            [label] => Filter Name
            [use_default] => 0
            [position] => 0
            [values] => Array
                (
                    [0] => Array
                        (
                            [product_super_attribute_id] => 2
                            [value_index] => 220
                            [label] => Topaz
                            [default_label] => DEF
                            [store_label] => DEF
                            [is_percent] => 0
                            [pricing_value] => 210.0000
                            [use_default_value] => 1
                            [value_id] => 1
                        )

                    [1] => Array
                        (
                            [product_super_attribute_id] => 2
                            [value_index] => 217
                            [label] => Quartz
                            [default_label] => ABC
                            [store_label] => ABC
                            [is_percent] => 0
                            [pricing_value] => 195.0000
                            [use_default_value] => 1
                            [value_id] => 2
                        )
                )

            [attribute_id] => 1171
            [attribute_code] => filter1name
            [frontend_label] => Filter Name
            [store_label] => Filter Name
        )

)

i want product is also with each value array option , how can i get that

  • which form of value array option do you want ? – sandip Dec 31 '16 at 16:19
0
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

$attributeOptions = array();

foreach ($productAttributeOptions as $productAttribute) {
    $configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($product);
    $simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

    foreach($simpleCollection as $simple){
        $simple_product = Mage::getModel('catalog/product')->load($simple->getId())->addAttributeToSelect($productAttribute['attribute_code']);
        $attributeOptions[$productAttribute['label'][$simple->getId()]=$simple_product->getData($productAttribute['attribute_code']."_value");
    }
}

Print $attributeOptions array

| improve this answer | |

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.