Magento – how to get swatches attribute option in magento 2

attribute-optionsattributescolor-swatchesmagento2swatches

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

\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory 
$options = $this->_attrOptionCollectionFactory->create()->setAttributeFilter(
                        $id
                )->setPositionOrder(
                        'asc', true
                )->setStoreFilter($storeid[$i])
                ->load();

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

Best Answer

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

<?php 

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

foreach ($attributes as $attribute){

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

}
Related Topic