0

How will I get the custom created category attribute value on the product list page?

I have seen many answers but no one is working.

5
  • 1
    where you want to add custom attribute value on list page what type of value it. is text or select
    – Aman Alam
    Commented Jan 22, 2019 at 7:14
  • Add code here, which you already tried Commented Jan 22, 2019 at 7:15
  • @RohanHapani I have tried from here all answers magento.stackexchange.com/questions/95563/… Commented Jan 22, 2019 at 7:18
  • @AmanAlam it is a text value Commented Jan 22, 2019 at 7:19
  • You can accept and upvote if it's helpful for you :) Commented Jan 22, 2019 at 7:33

1 Answer 1

1

You need to get value from current category data. Try this below code :

protected $_categoryFactory;
protected $_registry;

public function __construct(
    ....
    \Magento\Framework\Registry $registry,
    \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ....
) {
    ....
    $this->_registry = $registry;
    $this->_categoryFactory = $categoryFactory;
    ....
}

public function yourFunction()
{
    $current_cat_id = $this->_registry->registry('current_category')->getId();
    $categoryData = $this->_categoryFactory->create()->load($current_cat_id);
    $getContent = $categoryData->getData('is_home_page'); //is_home_page = your attribute code
    echo $getContent;
}
4
  • This one is not working. Commented Jan 22, 2019 at 7:48
  • Is any error or system.log? Commented Jan 22, 2019 at 8:34
  • I have used catalog_category_entity_varchar directly to get the values using attribute id. Commented Jan 28, 2019 at 5:46
  • @AmritPalSingh can you share your code? Commented Mar 13 at 12:38

Your Answer

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

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