0

I need to get an image of subCategory.

$category = $block->getCurrentCategory();
$subcategories = $category->getChildrenCategories();
foreach ($subcategories as $var) {
    print_r($var->getData())
}

I get every data other than category image.

    Array
(
    [entity_id] => 12
    [attribute_set_id] => 3
    [parent_id] => 11
    [created_at] => 2018-06-26 08:26:17
    [updated_at] => 2018-06-26 11:45:37
    [path] => 1/2/11/12
    [position] => 1
    [level] => 3
    [children_count] => 4
    [is_active] => 1
    [request_path] => men/tops-men.html
    [name] => Tops
    [url_key] => tops-men
    [is_anchor] => 1
)

the array conatin this data.

0

Try this code :

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $block->getCurrentCategory();
$subcats = $category->getChildrenCategories();

foreach ($subcats as $subcat) {
    $_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
    $_category->getImageUrl()
}

See More : here

  • Objectmanager and LSD. Both bad approaches. – seanbreeden Oct 23 '18 at 15:53
0

$imageUrl = $var->getImageUrl();

  • there is no ImageUrl in the array – hetesh mohan Jun 26 '18 at 13:04

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.