When I am trying to use the code

Mage::getModel('catalog/product')->loadByAttribute('sku', $sku2)->getProductUrl();

in my cart page i am getting the error as

Fatal Error: Call to a member function getProductUrl() in boolean

Can anyone kindly tell me why am I getting this.


You get this error, because Mage::getModel('catalog/product')->loadByAttribute('sku', $sku2) just returns false. Please check your SKU ($sku2) ... if this is invalid, you'll see this error.

I'd recommend adding a check if product exists ...

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku2);
if ($product->getId()) {
    echo $product->getProductUrl();
| improve this answer | |
  • Thank you for the help I got the answer by changing the code that I have mentioned in the answer that I have written below – Akshay Vasu Aug 7 '17 at 11:47

I resolved it by using the following line of code instead of the code that I have mentioned in the question above.

| improve this answer | |
  • This does not match your question ... either looking for ID or SKU ;) – sv3n Aug 7 '17 at 11:58
  • I was getting that error when I was trying to get the URL :) – Akshay Vasu Aug 7 '17 at 12:25
  • Yes, because invalid SKU in loadByAttribute ;) Change your code to the original one and use a valid SKU and it will work too :) – sv3n Aug 7 '17 at 12:28

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.