Retrieve current product, category and CMS page Magento Registry

Sunday, 13. November 2011

Here are the quick snippet scripts for pulling out the current product, category and cms page from inside script or template files in Magento.

Get Current category

$_category = Mage::registry('current_category');

Get Current Product

$_product = Mage::registry('current_product');

Get Gurrent CMS Page

$_cmspage = Mage::registry('cms_page')


Fatal error: Call to a member function toHtml() on a non-object in app/code/core/Mage/Core/Model/Layout.php on line 529

Friday, 11. November 2011

Most upgrades from versions below 1.4 to latest version are more likely to encounter this problem when trying to re-install the same theme back on the new version. The solution is simple as explained below:

Fatal error: Call to a member function toHtml() on a non-object in app/code/core/Mage/Core/Model/Layout.php on line 529

Locate and open the file app/design/frontend/default/YOUR_THEME/layout/page.xml file and change the following line:

<block type="core/profiler" output="toHtml"/>


<block type="core/profiler" output="toHtml" name="core_profiler"/>


Get magento folder or directory path seemingly

Tuesday, 8. November 2011

Here are some snippets for getting specific Magento folder or directory path from templates or code files.

Magento Base Folder or Directory

echo Mage::getBaseDir('base');

Magento App Folder or Directory

echo Mage::getBaseDir('app');

Magento Media Folder or Directory

echo Mage::getBaseDir('media');

Magento JS Folder or Directory

echo Mage::getBaseDir('js');


Recoverable Error: Argument 1 passed to Mage_Core_Model_Store :: setWebsite() must be an instance of Mage_Core_Model_Website

Friday, 4. November 2011

When upgrading Magento to the latest version, I stumbled upon this error:

Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null given, called in /path/app/code/core/Mage/Core/Model/App.php on line 427 and defined in /path/app/code/core/Mage/Core/Model/Store.php on line 279

To fix this issue:

1) Navigate to the following file and delete it.


If problem persists: here is what you will need to do. Basically, your current database has the admin store id greater than 0. This script should be run via phpmyadmin or similar tool.

UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';

Get Drop Down list and Multi-Select values for Magento Product Attributes

Tuesday, 1. November 2011

Here is a quick snippet for retrieving the text values of Select (drop down list) and Multi-Select attributes for Magento Products.

Get attribute object – if you only have attribute code

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $_attribute_code);

Get Multi-Select Values

if($attribute->getFrontendInput() == 'multiselect') {
  $multiSelectArray = $_product->getAttributeText($_attribute);
  echo implode(', ',$multiSelectArray);

Get Drop Down list (Select) Value

if($attribute->getFrontendInput() == 'select') {
  echo $_product->getAttributeText($_attribute);