how to get progmatically swatches attribute option data in magento 2. I tried this:-

$options = $this->_attrOptionCollectionFactory->create()->setAttributeFilter(
                        'asc', true

with this above code i only get option data, not the swatches value. Please advice.

1 Answer 1


You Can get all the swatches attribute option data with below code.


$attributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product); 

foreach ($attributes as $attribute){

    foreach($attribute['values'] as $data){
        echo "<pre>";

  • what exactly you are doing? Please specify it. Apr 7, 2017 at 7:47
  • I need to attribute data with swatches data into attribute option. Not for particular product. Apr 8, 2017 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.