12/05/2012

Magento: How to setup multiple currency shop

To setup Multiple currencies for magento store is very easy. To do so, just follow below steps:


1. Login to admin panel of your website.
2. Go to System --> Configuration, then select Currency Setup from General tab.



        Then select values for Base currency, Default display currency and Allowed currencies and Save Config button.



Note: Press Control key of key board while selecting multiple options from Allowed Currencies section.

Magento still does not know about currency rates for newly selected currencies. To let magento know about currency interchange rates, follow step #3.

3. Go to System --> Manage Currency --> Rates.



        Just click on Import button on top right side. Now click on Save Currency Rates button.



Note: You can provide values manually also, but it is recommended to import rates from web service.

That's all.. refresh magento cache and you are done. Now on frontend prices of products can be displayed in the currencies you configured.

Magento: How To Set Up Multiple Languages in Magento


In order to configure a different language for your store, you need to follow a simple procedure:

1. First go to http://www.magentocommerce.com/translations, where you will find various language translations packs for default Magento interface.
        Download the language pack for the desired language, extract and paste the extracted files to respective places in your Magento directory.
         or
You can install it directly by searching and installing through Magento Connect.

2. Now go to Admin Panel, then go to System --> Manage Stores.



        Click on Create Store View button.
Select Store, provide appropriate value for Name and code, and select Enabled from Status dropdown. Click on Save Store View button.

3. Now go to System --> Configuration and Select Store View (which you created in step #2).
Clicking on General tab (on left side), you will see Locale Options on right side. Select installed Language from Locale dropdown. Save Config.



and you are done. Just Clear Magento Cache Storage and see reflection on frontend of you website.

12/03/2012

Magento: Upgrading mysql setup of module


Suppose, you are working on a module, and you need to:

* Add a new table, or
* Modify current tables, or
* Insert some default data in existing table, or
* Add/ modify some attributes

In every case, either you will
1. goto core_resource table
2. delete module's entry
3. and delete current tables of module

which is a poor solution, because sometimes, you don't have direct access to database, so you can't delete/ modify data in db in that case.
There is a simple solution for this. You can do it by simply upgrading you module version and write a new mysql upgrade file.


Suppose, you have a module named Mymodule. Its version is 0.1.1. You have the mysql setup file (mysql install file) mysql4-install-0.1.1.php in Mymodule/sql/mymodule_setup folder of your module.

You don’t need to make direct changes to database. To fulfill any of the above tasks in your module,


1) First create a new mysql upgrade file inside Mymodule/sql/mymodule_setup folder.

Let us suppose that you are going to change the version of your module from 0.1.1 to 0.1.2.

The name of mysql upgrade file should be mysql4-upgrade-0.1.1-0.1.2.php

2) Write necessary sql statements in this mysql upgrade file.

3) Now, you have to change the version in config.xml in Mymodule/etc folder as well.

Change the version like 0.1.2. Which is the new version for our module.

4) Reload your site. And you are done!


Note: The upgrade format is like mysql4-upgrade-CURRENT_VERSION-UPGRADED_VERSION.php


Enjoy.. :)

10/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.. :)


10/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.. :)

8/10/2012

Magento: Get all related products of current product

Obviously, we can get all related products of current product by calling related.phtml. But there are many cases, in which we can not call related.phtml. For example:let us assume that we are showing two or more products on a page and we may want to show small image and name of these two products at a time.

Many other situations can be there, when we may not have option, but to write custom code to get related products of currently loaded product.

For such situations, try this code:

$collection = Mage::getModel('catalog/product_link')
                    ->getCollection()
                    ->addFieldToFilter('product_id',$product_id)
                    ->addFieldToFilter('link_type_id','1');
$related_products = $collection->getData();
This will give you list of all related products of a product.
Note: Here $product_id is the id of currently loaded product.
That's all.. Cheers.. :)

COURTESY: Mr. Neeraj Gupta (My dear Friend)