I can get current product attribute using $product->getAttributes()
. How can I get the configurable product list and their corresponding attributes programmatically?
-
You tried: magento.stackexchange.com/questions/83107/…– Khoa TruongDinhAug 9, 2016 at 16:00
-
I want to retrieve it, not creating it.– TFSAug 9, 2016 at 16:04
2 Answers
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
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)