Magento 2 Get specific attribute (manufacturer) collection in phtml file with images using object manager
Magento 2 Get specific attribute (manufacturer) with images using object manager
<?php
$om = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $om->get('\Magento\Catalog\Model\CategoryFactory');
$categoryHelper = $om->get('\Magento\Catalog\Helper\Category');
$categoryRepository = $om->get('\Magento\Catalog\Model\CategoryRepository');
$category = $categoryFactory->create()->load($catId);
$categoryProducts = $category->getProductCollection()
->addAttributeToSelect('*');
foreach ($categoryProducts as $_product) {
if($_product->getManufacturer()){
$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 } ?>
Comments
Post a Comment