- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015
09:51 PM
12-31-2015
09:51 PM
I have created a new category attribute using a setup script and now it is showing on the backend and assigned values (it is just a boolean attribute). the attribute name on EAV entity table is
is_home_category
.And now I'm trying to get its values on frontend
$categories = $this->getStoreCategories(true, true, true); foreach ($categories as $category): echo $category->getIsHomeCategory() endforeach;
But it only returns NULL , how can I get my custom category attribute on the frontend
_______________________________________________
An Expert in Anything Was Once a Beginner
An Expert in Anything Was Once a Beginner
Solved! Go to Solution.
Labels:
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015
09:58 PM
12-31-2015
09:58 PM
Instantiate a category collection manually and call its addAttributeToSelect method.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015
09:58 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015
10:47 PM
12-31-2015
10:47 PM
Re: Magento 2 get custom category attribute
thank you very much I have inject
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollection
and able to load category collection with
public function getCategoryCollection() { $collection = $this->_categoryCollection->create() ->addAttributeToFilter('is_home_category', '1'); return $collection; }
and Now I can call
getIsHomeCategory()
method but I can not get category name by getName() do you know how to get category name ?
_______________________________________________
An Expert in Anything Was Once a Beginner
An Expert in Anything Was Once a Beginner
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2015
11:01 PM
12-31-2015
11:01 PM
Re: Magento 2 get custom category attribute
my bad it should be
public function getCategoryCollection() { $collection = $this->_categoryCollection->create() ->addAttributeToSelect('*') ->addAttributeToFilter('is_home_category', '1'); return $collection; }
and thanks again
_______________________________________________
An Expert in Anything Was Once a Beginner
An Expert in Anything Was Once a Beginner