0

I have used the below code:

<?php $objectManager = \Magento\Framewor\App\ObjectManager::getInstance(); 
   $product = $objectManager->create('\Magento\Catalog\Model\Product');?>
<?php echo $msrp = $product->getMsrp();?>.

But this code is not working.But MSRP Price is not displaying.Can you please help me?

  • where do you want to get MSRP price, could you add little more brief, i.e product listing, product view page in custom module etc ? – Naveed Asim Mar 16 '18 at 7:12
  • Hi @ Naveed, On product listing page.Can you please help me? – Dileep Kumar Mar 16 '18 at 7:14
  • What is the issue ? you had same question couple of days ago didn't solution helped you out ? what issue you are having does it give error ? or don't display at all ? – Naveed Asim Mar 16 '18 at 7:19
  • Hi @ Naveed, actually in my product listing page I will display MSRP price but I have not got a perfect solution.I am searching in google also but no MSRP price related information in product listing page in magento2.I hope you helped to this task.Can you please help me? – Dileep Kumar Mar 16 '18 at 7:22
  • could you attach code snippet you are trying to implement to show price and also attach your detail page screen ( admin ) – Naveed Asim Mar 16 '18 at 7:25
3

Please don't use the object manager in this way :(

Product Page

Assuming you want to use this in a block you should be able to use the registry to get the product.

In your blocks constructor you can include $this->registry = $context->getRegistry(); and then in a method you can get the product and any attribute/data you wish

$product = $this->registry->registry('current_product');
return $product->getData('msrp');

Then from the block template you can call your method that returns the above msrp, eg. $block->getProductMsrp();


Product Listing Page

You should already have a $_productCollection so you should be able to get the msrp from the products in the collection

<?php foreach ($_productCollection as $_product): ?>
    <?php echo 'mrsp below'; ?>
    <?php echo $_product->getData('msrp); ?>
<?php endforeach; ?>

Doing the above gives me First product has an msrp, second does not

If you look in vendor/magento/module-msrp/view/base/templates/product/price/msrp.phtml you can see how Magento does this around line 48

Worth mentioning aswell that after making your changes you will most probably need to clear caches etc assuming you are working with caches enabled.

|improve this answer|||||
0

To show MSRP Open your theme folder :

app/design/frontend/smartwave/porto/Magento_Catalog/templates/product/

and in list.phtml add this line of code in your to show MSRP where ever you want:

$_product->getMsrp()
|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.