2

I have extended the phtml file

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

I want to get the msrp price and attribute set id in the extended template in both list page and view page.

I have used the following code

<?php $product = $this->helper('Company\Module\Helper\Data')->getCurrentProduct();?>
<?php $msrp = $product->getMsrp();?>
<?php $attributeSetId = $product->getAttributeSetId();?>

In view page it is working fine. But in list page getting error as 'Call to a member function getMsrp() is null'.

1 Answer 1

0

The error provided sounds very unfamiliar. It should either say:

  1. Call to a member function getMsrp() on null

or

  1. Methond getMsrp() is undefined

I am very tempted to say that the error you got is the first example (on null instead of is null). A strong reason for this is that on a magento product a get method converts to getData() which is always defined. For example getMsrp() is equal to getData('msrp) and even if msrp attribute is not loaded it should return an empty string.

Moving forward you should check your getCurrentProduct() method and see why it's returning a null product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.