0

In Magento 1, I was able to get attibute value with following code:

Mage::getResourceModel('catalog/product')->getAttributeRawValue($_id, 'att_price', $_storeId)

How can I get the value in Magento 2, in tempalte

vendor/magento/module-catalog/view/base/templates/product/price/amount/default.phtml  

I copied it to my theme:

/app/design/frontend/xxx/ddd/Magento_Catalog/templates/product/price/amount/default.phtml

Thanks for the help! Martin

0

In Magento 2 Get Attribute Raw Value Like This :-

$protected $_resourceProduct;

public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product $resourceProduct)
         {
             $this->_resourceProduct = $resourceProduct;
         }

         public function getData()
         {

            $value = $this->_resourceProduct->getAttributeRawValue($productId,'attribute_name',$store_id);
         }
| improve this answer | |
  • Thanks. But from where do I get $productId? – matin Jun 21 '19 at 8:18
  • in your phtml file you can get product id using object manager – Rk Rathod Jun 21 '19 at 8:22
  • 1
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); – Rk Rathod Jun 21 '19 at 8:22
  • or another option is to override the amount.php file and add your custom function for get current product data – Rk Rathod Jun 21 '19 at 8:23
  • Thanks! But echo $product->getId(); returns error? – matin Jun 21 '19 at 8:26
0

You can use this

echo $block->getSaleableItem()->getResource()->getAttribute('attribute_name')->getFrontend()->getValue($block->getSaleableItem());
| improve this answer | |

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.