Fatal error: Call to a member function getId() on a non-object in /app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php

StackOverflow https://stackoverflow.com/questions/22949022

  •  30-06-2023
  •  | 
  •  

Question

After migrating Magento to a new server I get this error on the dreaded white screen when trying to save a product:

Fatal error: Call to a member function getId() on a non-object in ...app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php on line 587

Here is the code on line 587

if (Mage::app()->isSingleStoreMode()) {
        $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
    }

Method from same section this is lines 556-588:

/**
 * Initialize product before saving
 */
protected function _initProductSave()
{
    $product     = $this->_initProduct();
    $productData = $this->getRequest()->getPost('product');
    if ($productData) {
        $this->_filterStockData($productData['stock_data']);
    }

    /**
     * Websites
     */
    if (!isset($productData['website_ids'])) {
        $productData['website_ids'] = array();
    }

    $wasLockedMedia = false;
    if ($product->isLockedAttribute('media')) {
        $product->unlockAttribute('media');
        $wasLockedMedia = true;
    }

    $product->addData($productData);

    if ($wasLockedMedia) {
        $product->lockAttribute('media');
    }

    if (Mage::app()->isSingleStoreMode()) {
        $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
    }
Was it helpful?

Solution

I realize this is old, but I was having a similar problem on a 1.9.0.1 store. When I turned on the cache it worked! With the cache off and cleared it didn't. Not sure why.

Hopefully this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top