1

How to get product attribute value in magento 2.0.6 product view page and list page

1
  • 1
    CheckLink. - Check Above Link Sure help you to Get attribute value
    – Nikul
    Jul 12, 2016 at 5:11

1 Answer 1

1

In product view page you can get like this:

$this->getProduct()->getId();
$this->getProduct()->getName();

You can get custom attribute like this:

$attribute = $this->getProduct()->getResource()->getAttribute('attribute_id');
if ($attribute)
{
    $brick_value = $attribute->getFrontend()->getValue($this->getProduct());
}
5
  • Thank you for your reply i am getting below error Fatal error: Call to a member function getResource() on a non-object in view.phtml Jul 12, 2016 at 5:29
  • this code is work only in magento 2 product view page. Jul 12, 2016 at 5:39
  • i am using magento 2.0.6 is it work? Jul 12, 2016 at 5:41
  • using this $_attributeValue =$product->getResource()->getAttribute('test_attrivute ')->getFrontend()->getValue($product); i am getting YES/NO as text how can get value like 1/0 Jul 12, 2016 at 12:39
  • yes. i have used above code in my store. Jul 12, 2016 at 12:56

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.