2

I already searched here, but none answers have work.

I have a custom module, where I get a list of products from one category setted by user, it is coded in a Helper class:

public function getConfigCategory()
{
    $category = $this->_categoryFactory->create()->load('CONFIGURATION');
    return $category;
}

public function getFilteredProducts()
{
    return $this->getConfigCategory()->getProductCollection()->addAttributeToSelect('*'); 
}

So, with this I have a list of products, wich one foreach (in a Model class), but when I try to get the manufacturer attribute, it always return null.

$brand = $product->getAttributeText('manufacturer');

$brand is always null, I have tried to reload $product with this:

$product = $this->objectManager->get('Magento\Catalog\Model\Product')->load($product->getId());

But the result is always the same, any ideia? Thanks in advance.

I'm using the sample data, and I have bundle items

2
  • Do you get your manufacture in $product object? Nov 17, 2017 at 15:55
  • Yes, with the getAttributeText method.
    – lpFranz
    Nov 17, 2017 at 15:58

1 Answer 1

0

You could try:

<?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); ?>

You may need to set your attribute up so attribute is visible in frontend also, this may solve your problem.

8
  • Thanks for answering, so I try it and returns No ...
    – lpFranz
    Nov 17, 2017 at 16:00
  • Is this just a plain text attribute?
    – harri
    Nov 17, 2017 at 16:02
  • No, is a drop down, wich the user must fill, in my store this have brands like Nike, Puma, etc. Is an magento native field.
    – lpFranz
    Nov 17, 2017 at 16:08
  • Did you check the attribute set to visible on frontend? That seems to work for my dropdowns. Not sure maybe try a reindex also?
    – harri
    Nov 17, 2017 at 16:10
  • Yes, is setted as visible, clean cache and reindex, but still returning No =/
    – lpFranz
    Nov 17, 2017 at 16:20

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.