1

I'm trying to get MSRP Product Prices in cart/checkout pages. The price returned by the following code is always zero.

foreach ($quote->getAllVisibleItems() as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getId()); 
    $_msrpPrice = Mage::helper('core')->currency($product->getMsrp(),true,true);
    var_dump($_msrpPrice);

}

Any alternatives?

  • Your Magento version is 1. You did not specify this. – St3phan Apr 2 '18 at 12:43
  • I added it as a tag – zekia Apr 2 '18 at 12:43
  • 1
    Can you verify that the msrp for these items is not 0? is there any value returned for $product->getMsrp()? If not, do a check on the line that you populate the product to make sure it is being loaded, i.e. you are getting the correct value from $item->getId(). – mtr.web Apr 2 '18 at 19:44
  • @mtr.web I'm testing this with two products added to cart, one of them has mtrl price and one of them not. But both products return $_msrpPrice = 0,00. – zekia Apr 3 '18 at 8:46
  • 1
    @mtr.web you gave me a hint. $item->getId() returns a value, but it's not the products id. To get the real product id I had to use $item->getProductId(). Please post this as an answer so I can accept it. – zekia Apr 3 '18 at 8:51
1

Through debugging, it turns out that $item->getId() does not return the products' id. Instead, $item->getProductId() will work, and here is the edited code:

foreach ($quote->getAllVisibleItems() as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId()); 
    $_msrpPrice = Mage::helper('core')->currency($product->getMsrp(),true,true);
    var_dump($_msrpPrice);
}
2

Instead of loading each product you can define custom attributes in a moduels config.xml. Just add this to global section:

    <sales>
        <quote>
            <item>
                <product_attributes>
                    <msrp />
                </product_attributes>
            </item>
        </quote>
    </sales>

Now this should work too ...

foreach ($quote->getAllVisibleItems() as $item) {
    $_msrpPrice = Mage::helper('core')->currency($item->getProduct()->getMsrp(), true, true);
    var_dump($_msrpPrice);
}

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.