I'm trying to grab a product attribute in the cart template. But I just does not work! The attribute is set to Visible on Catalog Pages on Storefront = yes and Used in Product Listing = yes
I use a custom module to override the following template:
/vendor/magento/module-checkout/view/frontend/templates/cart/item/default.phtml
I have the product:
$_item = $block->getItem();
$product = $_item->getProduct();
Normally I would expect a custom attribute (of type text-area in this case) with an attribute code of 'sample_attr' to be available with one of these:
$product->getData('sample_attr');
or
$product->getSampleAttr();
Some attributes are available using this (sku, weight, price ..), but for a custom attribute neither works. The included helper (\Magento\Msrp\Helper\Data) also has no attribute method.
I can get all attribute codes using:
$attributes = $product->getAttributes();
foreach($attributes as $a)
{
var_dump($a->getName());
}
But how do I get the value of the attribute?