0

I'm trying to display upsell products on product page by getting upSellCollection as such:

$_product = Mage::registry('current_product')->getId();
$upsell_product = $_product->getUpSellProductCollection();

After this I'm getting:

Fatal error: Call to a member function getUpSellProductCollection() on a non-object

Any advice?

  • You sure you are on product page ? Which file you are working in ? Somewhere along the process, looks like you lost the registry variable for current_product. – Prateek Mar 19 '16 at 11:59
  • Hi, thank you for your time helping out. I've extended view.phtml to list/upsell.phtml Currently working on upsell.phtml – Aivis Zvezdovs Mar 20 '16 at 11:44
1

Fatal error: Call to a member function getUpSellProductCollection() on a non-object

This means your $_product is not an object but is a null type and you cannot call getUpSellProductCollection() function on null type.

If you are in product page then your $_product can be just like this:

$_product = $this->getProduct();

Check Mage_Catalog_Block_Product_View class

  /**
   * Retrieve current product model
   *
   * @return Mage_Catalog_Model_Product
   */
   public function getProduct()
   {
      if (!Mage::registry('product') && $this->getProductId()) {
          $product = Mage::getModel('catalog/product')->load($this->getProductId());
          Mage::register('product', $product);
       }
      return Mage::registry('product');
   }

Now you can get your up sell product like this:

$upsell_product = $_product->getUpSellProductCollection();

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.