3

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.

| improve this question | | | | |
3

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);
    }

}
| improve this answer | | | | |
  • what exactly you are doing? Please specify it. – Gopal Patel Apr 7 '17 at 7:47
  • I need to attribute data with swatches data into attribute option. Not for particular product. – Karangar Meghnathi Apr 8 '17 at 7:40

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.