Configuration magento

Setting up Magento with multiple websites or stores

There are many tutorials how to set Magento to work with multiple stores and make different domains point at each store. Since release of Magento CE 1.4.0.0-beta1 and Magento EE 1.6.0.0 it is even more easy to do.

Magento evolves

Solutions used in previous versions required developer to modify index.php file to handle different domains pointing at different stores. New index php contains following code:

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run($mageRunCode, $mageRunType);

So it checks two environmental variables and use them to start Magento runing. What does it give you? You can set now which store/website is supposed to be running under selected domain directly in virtual host definition or even htaccess.

VirtualHost solution

To benefit from this little piece of code it is enough for you to add following lines within your VirtualHost definition:

SetEnv MAGE_RUN_CODE "base" # put here your website or store code
SetEnv MAGE_RUN_TYPE "website" # put here 'website' or 'store'

.htaccess solution

If you have no access to virtual host definitions, you can still try to use .htaccess for that, putting within following lines:

SetEnvIf Host .*yourhost.* MAGE_RUN_CODE=base
SetEnvIf Host .*yourhost.* MAGE_RUN_TYPE=website

Where .*yourhost.* is an regex expression matching the domain for which you want to set environmental variable.

So now you are capable of setting up your Magento multiple stores website without messing up with the core. Good luck.

Magento Backoffice (Admin Panel) Options - [Part 2]

Now, when you are a bit familiar with Magento "Admin Panel" options (see Magento Backoffice (Admin Panel) Options - [Part 1]), let's do something creative. You remember that the first part said that you can add your own menu entries? It's very useful if you want to control your module (of course the new menu entry doesn't have to manage a new module, it can be used to handle existing functionality as well). So - let's see how to do it.

First of all, you need to create a new module. Alternatively, you can download source code of a module which I created for the purpose of this article and to which I am going to refer. The module will display current time, and it's format will be set by you. The format should be a valid argument of PHP date() function.

Adding entry to menu takes place in config.xml file. What we need are the folowing lines:

<adminhtml>
    <menu>
        <example translate="title" module="adminhtml">
            <title>Set Time Format</title>
            <sort_order>60</sort_order>
            <children>
                <set_time>
                    <title>Set It!</title>
                    <action>example/index</action>
                </set_time>
            </children>
        </example>
    </menu>
</adminhtml>

This code will add entry labelled Set Time Format with subentry Set It! and it refers to module identified by example, controller index, action index. Basically, that's all that is necessary to put our new entry into the menu. Check the result in the backoffice - the new entry should appear between Catalog and Customers. If not - clear the cache.

The rest of the module are just files defining form used to enter time format and controller responsible for displaying the form or saving data. As you can see, I decided to store the data along with Magento config values. It was just a quick, dirty solution, to avoid creating more than what is essential in this short how-to.

You can also add your entry on System->Configuration page. It needs a bit diferent approach and this topic will be covered in the next part.

Magento Backoffice (Admin Panel) Options - [Part 1]

If you start your experience with Magento, you may be confused with all the options available in the backoffice (also called "Admin Panel"). What you get after a typical fresh install is: Dashboard, Sales, Catalog, Customers, Promotions, Newsletter, CMS, Reports, and System (if you do not see all these menu items, be sure that you are connected with administrator privileges). You can add more menu entries later, and we will talk about it in next parts. All of the entries, but Dashboard, contain their sub-menus. Now, let's have a closer look at some of them.

Dashboard is the admin home page. What you see there, is a summary for a selected shop - last orders from selected time range, amounts form selected time range, bestsellers, most viewed products, new customers... Basically this is what you would expect to get on your admin home page. Sales contains all management modules for orders, invoices, shipments and taxes. This is the place where you manage all the orders put by your customers. You can browse, cancel, hold or unhold, and print them. What is less intuitive, it also contains Terms and Conditions.

System entry contains some items worth to remember. Inside Tools you will find a possibility to create backup. Well, certainly a useful option. There is also Cache Management. And last, but not least - Configuration. Check Design tab. This is the place to set skin for your store, choose layout, and default theme.Magento will switch back to the default theme if the one you selected cannot be found. This is also the place to add the image that will be used as a watermark for the images in your store. And at the end - the setting used most often by me.

Check the Developer tab, still being under Configuration. Choose your store in the Current Configuration Scope field at the left. Debug section will then contain fields named 'Template Path Hints', and 'Add Block Names to Hints'. Uncheck 'Use website' and set both to Yes. Now go back to frontoffice and refresh page. Make sure you are on the same store that you selected in Configuration Scope in the admin panel. What you get are names of templates used to render displayed page, with corresponding blocks names. The dashed lines show templates borders. Trust me - this option is really worth remembering.