0

I can get current product attribute using $product->getAttributes(). How can I get the configurable product list and their corresponding attributes programmatically?

2

You can use \Magento\ConfigurableProduct\Api\LinkManagementInterface::getChildren to get list of child for configurable product and \Magento\ConfigurableProduct\Api\OptionRepositoryInterface::getList to get list of attributes that used to create configurable product

1

Navigate to vendor/magento/module-configurable-product/Model/Product/Type/Configurable.php, we can see getConfigurableAttributes($product) to retrieve the configurable attributes.

vendor/magento/module-configurable-product/Test/Unit/Model/Product/Type/ConfigurableTest.php

/**@var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $_model**/
/**@var \Magento\Catalog\Model\Product $product **/

$this->_model->getConfigurableAttributes($product)
  • I have set the configurable in admin panel. But when I run $product->getConfigurableAttributes($product), it returns empty. – Paul Aug 9 '16 at 16:21
  • 1
    Magento recomend use Service Layer API. Any other code can be changed/removed – KAndy Aug 9 '16 at 16:22

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.