0

I have created a swatch text attribute. But the values are not getting saved properly. How to set values to the section "Manage Swatch(Values of Your Attribute)".

enter image description here

0
        <?php
        if($_product->getManufacturer()){
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category

            $brand_value = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product);
            $brand_id = $_product->getManufacturer();
            $curnt_cat_url = $category->getUrl();
            $brandId = '?manufacturer='.$brand_id;

            $om = \Magento\Framework\App\ObjectManager::getInstance();
            $swatchHelper=$om->get("Magento\Swatches\Helper\Media");
            $swatchCollection = $om->create('Magento\Swatches\Model\ResourceModel\Swatch\Collection');
            $swatchCollection->addFieldtoFilter('option_id',$brand_id);
            $item=$swatchCollection->getFirstItem();
            $ThumbImage =  $swatchHelper->getSwatchAttributeImage('swatch_thumb', $item->getValue());
            $SwatchImage = $swatchHelper->getSwatchAttributeImage('swatch_image', $item->getValue());

            ?>

            <div class="brand_bg">
                <a href="<?php echo $curnt_cat_url.$brandId; ?>" title="<?php echo $brand_value; ?>" ><img src="<?php echo $ThumbImage; ?>"></a>
            </div>
        <?php } ?>
        <?php/***********End Brand Attribute************/?>

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.