why the following code:

$attribute_string = $this->product->getResource()->getAttribute('attribute_code');

gives me null although the attribute exist.

and following code:

$attribute_string = $this->product->getAttributeText('layeredmake')

gives me false

  • what is the type of attribute_code, I mean is it dropdown or simple text? – Ramkishan Suthar Nov 14 '18 at 14:01
  • @Ramkishan it's multiple select – Yomna Mansour Nov 14 '18 at 14:08

Is this on product listing (category view, search result page)? If so you need to set the Used in product listing field to Yes

Go to Stores > Attributes > Product, open attribute layeredmake, open the 'Storefront Properties' and check the aforementioned field.

Then you should also be able to get the value the following way:

$attribute_string = $product->getLayeredmake();

If this is the case of a product page, then make sure your indexers are up to date and that the product actually has a value for the specific store view.

  • it still returns null – Yomna Mansour Nov 14 '18 at 14:25
  • @YomnaMansour if you haven't you should still reindex and flush the cache. bin/magento indexer:reindex catalog_product_attribute and bin/magento cache:flush – Zankar Nov 14 '18 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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