Browsing articles in "Magento"
Nov 3, 2013
kalpesh

Magento remove session id from URL

Magento displays session ID in url, something like:

http://loca.lho.st?__SID=2wewesfdgfsdm

You can remove this in two ways:

1. Go to your Magento admin panel > System > Configuration > Web.
Under Session Validation Settings, set “No” against label “Use SID on the Frontend”.
If this doesn’t work, then move to option two below.

2. Edit the file at app/code/core/Mage/Core/Model/App.php (somewhere around line 222),

protected $_useSessionInUrl = true;

Change that value to “false”. That should now prevent session IDs appearing in URL.

Oct 20, 2013
kalpesh

Magento Error: Fatal error: Call to a member function rewrite() on a non-object in app/code/core/Mage/Core/Controller/Varien/Front.php on line 165

Magento Error: Fatal error: Call to a member function rewrite() on a non-object in /var/www/magento/app/code/core/Mage/Core/Controller/Varien/Front.php on line 165

While upgrading Magento from 1.7 to 1.8 version, this error generally appears and stops the site from loading.

We can get rid of this error simply by clearing the cache:

rm -rf var/cache/*

If you don’t have terminal access, clear all the contents of var/cache/ directory.

Further if you have memcached or other caching system installed, flush them as well.

Aug 21, 2013
kalpesh

Magento remove reviews and ratings of products

Magento don’t provide admin screen where store owner can delete all the reviews and ratings of the products. The easiest way to delete them is using raw SQL queries, which you can run in Mysql console or in PhpMyAdmin. Remove/delete all the reviews and ratings of products in Magento using simple SQL queries given below.

truncate table `rating_option_vote`; 
truncate table `rating_option_vote_aggregated`;
truncate table `review`; 
truncate table `review_detail`; 
truncate table `review_entity_summary`; 
truncate table `review_store`;
Aug 17, 2013
kalpesh

Magento debug XML (layout, config) files

In Magento if there is any error in XML file, Magento silently ignores it and continues further parsing. So you never get to know where is the actual error and makes it difficult to debug. You can’t even do any logging in XML file and also Magento don’t tell that error is in XML. It makes debugging almost impossible and ends up wasting in hours to find some silly mistake.

But we can know if there is any error in XML (layout.xml or config.xml or any xml file) if you use below code in the controller action which is being called. The browser will display WHOLE XML code and if it encounters any error in it, simply gives where is the error in the XML tree.

If you are trying to load let’s say Product View page, then put this code in Mage/Catalog/controllers/ProductController.php file’s viewAction() method temporarily to display whole XML tree to find out error(s) if any. As we are saying to display the page as XML, the page will break if it finds any mal-formed XML code and will show where is the mistake.

header("Content-Type: text/xml");
echo Mage::app()->getConfig()->getNode()->asXml();exit;

If you want to debug Layout Handles only, you can just check by this code:

header("Content-Type: text/xml");
echo Mage::app()->getLayout()->getUpdate()->getHandles();exit;
Aug 17, 2013
kalpesh

Magento delete empty categories and sub-categories

Remove all empty categories and sub-categories in Magento. When there are empty categories, the website shows empty page in those categories in frontend. Create a file in the magento root, I will name it rmvEmptyCats.php, with following code:

require "app/Mage.php";
umask(0);
Mage::app();

$categoryCollection = Mage::getModel('catalog/category')->getCollection()
    ->addFieldToFilter('level', array('gteq' => 2)); //greater than root category id

foreach($categoryCollection as $category) {
    if ($category->getProductCount() === 0) {
        $category->delete();
    }
}

echo 'Empty Categories Deleted!';

Now you can easily run it by navigating to http://loca.lho.st/rmvEmptyCats.php and wait for the message Empty Categories Deleted!

Note that this is going to DELETE those categories with zero product count.

Pages:«1...6789101112...29»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions