I made this code to create the custom attribute:
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
$eavSetup->addAttribute(
Category::ENTITY,
'is_tile',
[
'type' => 'int',
'label' => 'My Custom Label',
'input' => 'boolean',
'sort_order' => 100,
'source' => '',
'global' => ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => null,
'group' => '',
'backend' => '',
'used_in_product_listing' => true,
'visible_on_front' => true,
'is_used_in_grid' => true,
'is_visible_in_grid' => true
]
);
$this->moduleDataSetup->getConnection()->endSetup();
It works, I can save the value of is_tile on the backend side. But I would like to get it in this phtml file:
<block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
products.phtml:
<?php $category = $block->getCurrentCategory(); ?>
<?php var_dump($category->getData('is_tile')); ?>
But the output of my var_dump
is NULL
.
I've also made this file in my module etc/catalog_attributes.xml, with this content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
<group name="catalog_category">
<attribute name="is_tile"/>
</group>
</config>
But I am still getting the null
value. How can I get my custom category attribute value, without reloading the category? like here:
$categoryId = 5;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$object_manager = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
echo "<pre>";
print_r($object_manager->getData('is_tile'));