Google+

Pages

Monday, October 29, 2012

Magento: How to remove parent category path from sub category url in Magento

Hi friends,

Today I would like to tell you, how you can remove parent category path from sub category url in Magento.

To do so, Go to:
app/code/core/Mage/Catalog/Model folder and copy Url.php file to override it in your local package.

Open this file (Url.php) and find the following:
         public function getCategoryRequestPath($category, $parentPath)

With in this function, find the following code:

        if (null === $parentPath) {
            $parentPath = $this->getResource()->getCategoryParentPath($category);
        }
        elseif ($parentPath == '/') {
            $parentPath = '';
        }
and comment it like this:

 //     if (null === $parentPath) {
 //         $parentPath = $this->getResource()->getCategoryParentPath($category);
 //     }
 //     elseif ($parentPath == '/') {
            $parentPath = '';
 //       }
and save the file.

Note: It should be noted that the code $parentPath = ''; in else part should not be commented.
Now login to admin panel of your site, and go to:
System->Config->Index Management and click on "select all" then select Reindex Data from the Action Dropdown, then click on submit.

That's all.. Enjoy.. :)


Tuesday, October 23, 2012

Magento: How to view Magento version

Hi friends,

Have you faced problem when you were working on a complete customized theme and you were unable to know current magento version.

Just try this solution to find current Magento version of your website:

Create file versionTest.php parallel to index.php in root folder.
Now copy and paste following code in versionTest.php:
<?php
      include_once(‘App/Mage.php’);
      Mage::app();
      echo Mage::getVersion();
?>


Now just access this file using browser. Enjoy.. :)

Magento: Difference between Mage::getSingleton() and Mage::getModel() in Magento


Hi friends,
Some people ask about the difference between Mage::getModel() and Mage::getSingleton() in Magento.
Here is the difference between these two:

Mage::getModel('module/model') will create a new instance of the model object (if such object exists in configuration)
So if we write:
Mage::getModel('catalog/product'), it will create new instance of the object product each time. So,

$p1 = Mage::getModel('catalog/product');
$p2 = Mage::getModel('catalog/product');
Then $p1 is a one instance of product and $p2 is another instance of product.

While Mage::getSingleton('catalog/product') will create reference on existing object (if object does not exist then this method will create an instance using ::getModel() and returns reference to it).
So, if
$p1 = Mage::getSingleton('catalog/product');
$p2 = Mage::getSingleton('catalog/product');
Then $p1 and $p2 both refer to the same instance of product as reference $p2.

That's all.. Cheers.. :)