Magento system, offers users an excellent tool for creating rules of special prices for multiply products at the same time. We have 2 types of rules: the first refers to a catalog of products, while the other to the contents of customers shopping cart. Let's look little bit closer at this first one.

In this example, we'll create a rule of reducing 50% of the price of each product in a specific category in our catalog.

Go to Promotions -> Catalog Price Rules -> Add New Rule

At the beginning we give the name of the rule, then we mark stores to take effect in (obviously, if we have more than 1) and select group of clients. Remember to include the start date and end date of promotion period, You can also enter a From/To Time to be more specific.

On the Conditions Tab, set a condition to define the category of products: if the product is equal category id 44 (Sacs enfants) then...

..then perform the action: apply a percentage discount of the original price by 50 (50%).
Accept a new rule by click on "Save & Apply"

From now on, prices of all products from category 'Sacs enfants' ( category_id = 44) will be reduced by 50%. Products will display the original price (crossed out) and promotion one (as a rule).

Please note, prices usually refer to the standard price of the product. So if the product is set to individual special price it will be superior, depending on how we set the condition in price rule.

Let's say you want to create a new attribute for a product, e.g. 'color'.
There should be a set of possible values for this attribute. So what you do is create
an attribute of 'Dropdown' type. You set all its properties, give it a title and create its options, e.g. 'black', 'white', 'red' and 'yellow'.
But there is still one surprise that you may have. When you try to obtain the color simply by:

$product->getColor()

all you get is a numeric value corresponding to an option value in the dropdown.
But you probably would like to get a color name.
Fortunately you don't need to construct database queries, as Magento already thought about it.
So to get the name of the color selected for a product you need to use a method:

$product->getAttributeText('color');

where 'color' is the text that you have set as attribute code. Remember that you cannot
change attribute code nor its type after you create it.

Managing cross-sell relations can take a long time with Magento Community Edition if you have many products in you catalog.

With Magento Community Edition, you used to have to create relations between each product (cross-sell, up-sell and related products), product after product. Making this automatic required to develop a specific module or to import links from another system.

Then we need to add some observer to catalog/product/view.phtml so we can reload it when the value of color is changed (attribute76 is the id of select for attribute color, it's default id if we use standard Magento attribute, if changed, may need adjusting)

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:

Magento, thanks to Prototype framework, has nice set of JavaScript validators - so we can validate user input without reloading site. Of course, we cannot rely only on it, but it is good starting point - and for majority of users, it will have good look'n'feel.

But sometimes bulit-in validators are just not enough - for example, we can add custom fields for customer account, address etc. and we need some custom validation there. Magento together with Prototype gives us quick and easy way.

Little bit of theory - Prototype gives us Validation class. To check if form is valid, we have to call validate() method, which checks validation classes. I say classes, cause those are defined by css classes for input, for example:

<inputname="someinput"class="required-entry"/>

will require to be not-empty. It would be nice to add our own classes to keep this process so simple as it is. So...

Step 1.

Create your own file, for example /skin/frontend/default/your_skin/js/myvalidation.js and add it to page.xml layout file.
Important note: it must be somewhere below adding script prototype/validation.js - usually, end of head block is good and safe place.

We don't want to make any JavaScript error if for some reason validation script is not enabled, so we ensure it exists

Adding a validators. Argument is array, each value of it is also array - so you can add multiple validators at once.

This is css class that validator will be searching for, note that it must begin with validation- ('-' sign at end) - otherwise it may not work as desired.

This is error message displayed when validation is not passed.

Finally, our most important function - validator itself.

Next validators...

In this example validator function takes two arguments, but in fact usually first one is enough.
So first - called v here - is value of input at moment of validation
Second - called r here - can be useful in very custom validators - it is reference to validated object.
When validator function returns true, validation for field is passed, if false - opposite.

Recently, while working on Magento checkout process, I stumbled on two issues related to the "one page checkout" solution used on sites Magento. The problems are maybe not very difficult to solve, but as they repeat in different projects, I think they deserve mentioning. In this article I'll shortly explain the checkout progress mechanism in Magento, I'll investigate why it doesn't work with custom layout, and how to fix it.

The checkout progress column is updated by javascript each time any checkout step is completed. But if you decide to set different layout for checkout page than the default "two-columns-right" (default in Community Edition; in Enterprise Edition we've got "one column" layout here), the checkout progress column will not be updated any more. Why?

To find an answer on this mysterious riddle, open the file /skin/frontend/default/default/js/opcheckout.js. This is the javascript mechanism controlling behaviour of checkout process. About line 50 you can find function reloadProgressBlock:

This function updates the content of the right column, filling it with the actual checkout progress status. So if the layout of checkout page is "two columns right", everything works fine. But in other case the function fails – it can't find the DOM element with class="col-right", specified by $$('.col-right')[0] javascript statement.

Now the solution is obvious – to replace $$('.col-right')[0] by the selector of your wrapper element containing <divclass="one-page-checkout-progress">. So, for example, if your HTML structure looks like that:

then you have to copy the default opcheckout.js file, put it into your theme's appriopriate folder, and edit the reloadProgressBlock function, by changing the $$('.col-right')[0] into $('my-custom-right-column'):

The flexibility of Magento Dataflow module lies in fact you can easily create your own adapters, parsers, mappers and apply them to your specific dataflow needs.

The basic case you may wonder how to do, is import of data for your custom module. Let's do this by example. Imagine you need to display on you e-shop list of stores, you have created custom module, table in database and datamodel part, all you need now is to populate this table with data you have within csv file.

Process rows of data

Now the custom part of this process. Within your custom module you have to create custom adapter that will create row in database for each processed row of parsed file. Within your module root directory create file ./Model/Convert/Adapter/Store.php of this content:

Every module can contain a configuration file named system.xml. In this file we can define tabs and sections which will be later placed in System->Configuration, we define their content also. Data entered in the sections is stored in core_config_data table. Handling the data between the sections and the database in done by Magento, so it's a quite handy solution if we just need to put the data inside the database.

First, we need to create system.xml in module etc directory. The file should contain following definitions: what will be the tab for our module management, what sections it will contain and what is the content of each section. Our file is quite simple. First, the tabs:

As you can see, we define path to our section. The path will be also relevant for saving or loading data from database, because it is used as an identifier. In our case data entered in field time_format wil have identifier setit/settingtime/time_format.

Magento will add the sections to permissions management in System->Permissions->Roles->Role Resources. Check this tab, our new sections should be listed there when you choose 'Custom'. If you see 'Access Denied' error when you click on 'Set It!' section, then go to System->Permissions->Roles, select Administrators and Role Resources. Change All to Custom, mark all checkboxes - be careful, because mistake in this step may cause inability to login to Admin Panel. Save, then go back and change Custom back to All and save again. Now you should have fully functional module management.