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?

2
  • 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
    Commented Mar 19, 2016 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 Commented Mar 20, 2016 at 11:44

1 Answer 1

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();
0

Your Answer

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

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