Magento Themes and Magento Extensions

Logging user/customer actions in Magento

Share
Posted on July 20th, 2011 | Posted by admin

Recently I wrote a Magento extension called ActionLogger, inspired (thematically) by the “Logging of Administrator Actions” feature available in Magento Enterprise. ActionLogger is pretty simple extension, working on pretty simple but powerful concept of Magento controllers predispatch action.

All you need to do is to create event observer/observers for “controller_action_predispatch” event. This event is fired on every controller action call.

For example, if your store is located on url http://magento-1501.net url, and you go to url like http://magento-1501.net/electronics/cell-phones this will call action “view” from controller “category” from module “Mage_Catalog“. Simple logic/tracing would point this to be app\code\core\Mage\Catalog\controllers\CategoryController.php file and its viewAction().

How to add an external javascript/css file to Magento?

Share
Posted on July 20th, 2011 | Posted by admin

Have you ever had a need for adding external files into your Magento layout?
If you had then you know that you cannot do that from your xml layout files using methods/action:

1
2
3
4
<action method="addJs">
<action method="addCss">
or
<action method="addItem">

You could do that by hard-coding your “head.phtml” file, but then those external files will be loaded on all Magento pages.
This simple extension will provide you easy access for adding/removing external files such as JavaScript or CSS, libraries from remote servers which you cannot or don’t want to put on your server.
I called it Inchoo_Xternal extension.

How wonderful it would be if you could add or remove external, let’s say JavaScript libraries:
prototype: https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js
or
jquery: https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js
from yours “layout.xml” file and without modifying/hard-coding yours “head.phtml”.

Configurable product modification in Magento

Share
Posted on July 20th, 2011 | Posted by admin

In this article, I’ll give you extension that will change drop down selection (select field) to radio buttons on configurable products in Magento Community edition.

Well, what I had to do is rewrite Mage_Catalog_Block_Product_View_Type_Configurable block, and create a custom phtml file (configurable.phtml) with some custom validation on it.

Everything I just told you equals to this config.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_Configurable>
<version>0.1.1</version>
</Inchoo_Configurable>
</modules>
<global>
<models>
<configurable>
<class>Inchoo_Configurable_Model</class>
</configurable>
</models>
<blocks>
<configurable>
<class>Inchoo_Configurable_Block</class>
</configurable>
<catalog>
<rewrite>
<product_view_type_configurable>Inchoo_Configurable_Block_Frontend_Configurable</product_view_type_configurable>
</rewrite>
</catalog>
</blocks>
</global>
<frontend>
<layout>
<updates>
<configurable module="Inchoo_Configurable">
<file>configurable.xml</file>
</configurable>
</updates>
</layout>
</frontend>
</config>

How you could build your Magento extensions without view files

Share
Posted on July 20th, 2011 | Posted by admin

The main idea behind this article is something I previously wrote, making your extensions more distributable, less error prone, less depended, less intrusive. Such extensions are then more “safer” to be fetched and installed via Magento Connect. When I say safer I am thinking in terms of your extension not breaking someone live store, etc.

I would dare to say that one of the most annoying and dangerous areas of extension development are the theme view files. For example, imagine an extension that adds some “color switcher” like functionality on the product view page.

Usually extension developer will create his alternative of /app/design/frontend/default/default/template/catalog/product/view.phtml or /app/design/frontend/default/default/template/catalog/product/view/media.phtml file placing it under the default theme.

How To Pre Populate Product Dropdown Attribute Values

Share
Posted on July 20th, 2011 | Posted by admin

If you are looking to pre-populate product drop down attributes (custom types) i.e. “Partners” attribute etc. then you must be wondering how to pre-populate the product drop down attribute values in that attribute. One option is to manually enter all the data which is time consuming specially if you are supposed to fill large data set. What if the source of the data is large enough to enter and update? Situation gets worse if you are asked to check whether the data is upto-date or not.

Lets take a scenario where people are coming to a separate part of your website and registering as a partner which is getting stored in other database (Non-Magento database).

Now, we have to fetch partners from this remote site and pre-populate (upto-date) data in our newly created custom attribute dropdown (partners).