To support our customers during COVID-19 pandemic, we had introduced many
offers and discounts
to help your ecommerce businesses. Learn more

Magento 2 how to get category image

Magento 2 how to get category image

You can get the image of a category after load category. Following code will help you.

protected $_storeManager;
public function __construct(        
\Magento\Store\Model\StoreManagerInterface $storeManager
    ) {       
        $this->_storeManager = $storeManager;    
    }

 public function getThumbnailUrl($imageName){
        $url = $this->_storeManager->getStore()->getBaseUrl(
                \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
            ) . 'catalog/category/' . $imageName;
        return $url;
    }
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$load_cat = $_objectManager->create('Magento\Catalog\Model\Category')->load($_subcategory->getId());

$this->_customcatimage->getThumbnailUrl($main_cat->getthumbnail());


OR Simple use below code to get full image URL of category
$imageUrl = $load_cat->getImageUrl();

 
August 13, 2019
Did you like this post?
0
0