0
votes

How do I get the saleable product attributes (attribute values of associated simple products that are enabled, have stock, ...) for a given configurable product?

Thanks in advance

1
limex, are you want options values or attribute labelAmit Bera
@AmitBera: I need the attrite structur. The same as I get with getConfigurableAttributes in Marius's answer. But only those that are sellable.limex

1 Answers

1
votes

You can get the valid simple products associated to a configurable one like this:

$products = array();
$allProducts = $mainProduct->getTypeInstance(true)
    ->getUsedProducts(null, $mainProduct);
foreach ($allProducts as $product) {
    if ($product->isSaleable()) {
        $products[] = $product;
    }
}

and you can get the configurable attributes for the configurable product like this:

$attributes = $mainProduct->getTypeInstance(true)
        ->getConfigurableAttributes($mainProduct);

in both cases $mainProduct is the configurable product instance.

Now you can put them all together as you wish. I would have done it but your question is a bit unclear.