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