1. Create your own custom module that does the following:
- adds custom attribute to category entity
This non-required attribute is type int with source model value of Magento\Eav\Model\Entity\Attribute\Source\Boolean, default value is 1.
- add the custom attribute to the Category form, by overriding category_form.xml
- create Plugin that intercepts Magento\Catalog\Helper\Category::getCategoryUrl
$category->getCustomAttribute('blah_is_clickable') returns something instead of nullgetCustomAttribute is just a guess on my part.catalog_category_entity_int table.$category->getCustomAttribute('blah_is_clickable') always returns nullSince Magento2 stores my category custom attribute in catalog_category_entity_int table,
what is the correct way to fetch the value given an instance of
Magento\Catalog\Model\Category?
@VladimirZaets ping
I am assuming that you need the custom attribute (e.g 'description') value in your template file. Then you simply need to use this :
$_category->getData('description');     where
$_category = $objectManager->create('MagentoCatalogModelCategory')->load($currentCategoryId);
@routbiplab I ended up finding my own solution, forgot to close this ticket.
I created an event listener for the catalog_category_collection_load_before event.
In my observer class I added my custom attribute to the collection.
$collection->addAttributeToSelect('is_clickable');
The missing piece of the puzzle was that I didn't add my custom attribute to the Category entity's default attribute set. Drove me crazy trying to figure out why the collection was missing Category entities.
Also the official docs discourage the use of ObjectManager, and I believe the AbstractModel::load method is deprecated (in favour of repository classes).
Most helpful comment
@routbiplab I ended up finding my own solution, forgot to close this ticket.
I created an event listener for the
catalog_category_collection_load_beforeevent.In my observer class I added my custom attribute to the collection.
$collection->addAttributeToSelect('is_clickable');The missing piece of the puzzle was that I didn't add my custom attribute to the Category entity's default attribute set. Drove me crazy trying to figure out why the collection was missing Category entities.
Also the official docs discourage the use of
ObjectManager, and I believe theAbstractModel::loadmethod is deprecated (in favour of repository classes).