0

after add new custom attribute, i am trying to get my custom attribute category, filter by the parent id, actually it return me a null value or empty array I used $category->getData('label_text'), $category->getLabelText(), $category->getCustomAttribute('label_text')... Do i have to join catalog_category_varchar and eav_attribute to reach it ? If someone of you have some advices. thanks

3
  • how are you getting your $category instance?
    – Marius
    Jun 10, 2020 at 13:53
  • with $category = $objectManager->create('Magento\Catalog\Model\Category')->load($entityId);
    – lisa
    Jun 10, 2020 at 14:44
  • Please check your attribute's options. It must be visible on frontend otherwise will not be included in collection. Jun 10, 2020 at 15:10

1 Answer 1

0

Install/Upgrade script:

$eavSetup->addAttribute(
        \Magento\Catalog\Model\Category::ENTITY,
        'my_custom_attribute',
        [
            // ...
            'used_in_product_listing' => true, // for category pages
            'visible_on_front' => true, // for frontend??
            'is_used_in_grid' => true, // for category pages
            'is_visible_in_grid' => true // for category pages
        ]
    );

also on the collection do:

$collection->addAttributeToSelect('my_custom_attribute')

and then in the template you can just call:

$category->getMyCustomAttribute()
// or
$category->getData('my_custom_attribute');

If still not work run below command:

php bin/magento in:reindex

And more information this link ---

https://magento.stackexchange.com/a/184453/85907

Hope this help you

Thanks ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.