0

I am having a Product Id, which is a configurable product. For this product I am getting the options I can choose from like you can see below:

    $productAttributeOptions = $Product->getTypeInstance(true)->getConfigurableAttributesAsArray($Product);
    $attributeOptions = array();
    foreach ($productAttributeOptions as $productAttribute) {
        foreach ($productAttribute['values'] as $attribute) {
            $attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
        }
    }
    $product['options'] = $attributeOptions;

With that code I get something like that:

json format of the results of the code above

But now I want to get the assigned product Id of the options. So I want to know the product Id if you choose the color "Grey" and size "M" for instance.

2

You can use something like that :

$configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($product);
$simpleCollection = $configurable->getUsedProductCollection()
   ->addAttributeToSelect('*')
   ->addAttributeToFilter('color', array('eq'=>$color))
   ->addAttributeToFilter('size', array('eq'=>$size));

You should obtain a collection with a single product that correspond to you declination of the configurable.

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.