I have a custom template where I would like to get custom product attribute value, in my particular case is a yes/no attribute type. This has troubled me for quite a while as I can get all default attribute value, such as
price etc, but not my custom attribute value. The code I used was:
$attribute_value = $_product->getResource()->getAttribute('custom_attribute_code')->getFrontend()->getValue($_product);
It will always return
Yes no matter what.
Until I gave 'objectManager' a go and it worked and returned the correct attribute value and the code I used are:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId()); $attribute_value = $product->getData('custom_attribute_code');
So my question is
1) Why the first option returns only "Yes" and is it a bug?
2) Can someone please explain the difference between the two?