Programming


Our latest launch from Australia: Australian Gifts Online

Our latest launch from Australia: Australian Gifts Online

Australian Gifts Online is an Australian family business, owned by Paul and Jill Leach who have been selling online since February 2006. Last year, they decided to move their storefront to join the Magento Community. However, since they are constantly moving forward to keep up with the latest e-commerce trends, Paul approached Inchoo Australia’s office in Sydney looking towards improving the overall user experience, Magento design and performance.

Read more

Prevent PO Boxes in shipping address field on Checkout

Prevent PO Boxes in shipping address field on Checkout © jechasteen@sxc.hu

We recently integrated a feature that would prevent users from creating an order with a PO Box in Australia. Since we are already familiar with Australia Post shipping integration (and heavy modifications of it, I might add :)), the first thing that came to mind is to have a look if there’s some API or web interface that can be used to filter out post codes that are linked to PO Boxes. Many high volume addresses and/or PO Boxes in Australia have their own post code, so it looked like an obvious solution. It turns out that it’s not that simple or logical, since there are many edge cases where you can not reliably tell if you should filter the code out or not. There is a guide made by Fontis that shows how to validate the input fields in order to filter out PO Boxes. However, in our case we had some dynamic content loading with Temando shipping method integrated. This guide is intended as a more general solution that is compatible with Checkout page’s dynamic content and third party Shipping methods integration like Temando.

Read more

Custom router in Magento

Custom router in Magento

Creating the custom router could be very useful thing when we want to separate some business logic that can be applied on same route (url) without redirecting to different routes inside the controller.

Why don’t we create separate route for different logic and we are done?

Read more

Injecting Variables into a Magento CMS static block

Injecting Variables into a Magento CMS static block

In this tutorial i’ll show you how to inject any custom variable you need into a cms static block in place of a {{var variable_name}} tag. You’ve seen this in the email templates if you were working on them (in the matter of fact the model (filter) we’re calling is extending the same filter the email templates are using for injecting the variables).

Read more

Validate your input, Magento style

Validate your input, Magento style

I’m sure most fo you will agree that Magento’s frontend validation for form input fields is a nice feature. All it takes is for you to add some CSS classes to the input fields and then upon form submission validation is triggered that outputs, by default, red colored messages that point the possible validation failures etc. This validation is done on the client side via Java Script.

Read more

Emulate store in Magento

Emulate store in Magento

Magento 1.5 introduced very interesting piece of code that enables easy store emulation when programming, Emulation model a.k.a. Mage_Core_Model_App_Emulation class.

Read more

Layered navigation, but not quite

Layered navigation, but not quite

Recently I got a chance to rewrite Magento’s layered navigation standard functionality. The request was very specific as the client wanted to keep all of the “filters” visible all the time. For example if  you wish to filter your results by Color (let’s say you have yellow, green, red, blue and magenta) products are filtered but the layered navigation displays all filters. This way a costumer can re-filter the products in current category without the need to return to the category view.

Read more

Logging user/customer actions in Magento

Logging user/customer actions in Magento

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.

Read more

Magento code library – Handling files and folders

Magento code library – Handling files and folders

Among most often custom coding tasks are usually those related to some import/export between Magento and other system. Usually existing store owners when switching from their current shop system to Magento want to transfer all of their products, orders, and most importantly customers.

Most of the time, standard Magento product/customer import/export is not sufficient for the task at hand. Limitations like file size upload and structure of original data require you to do a custom scripts that will handle the job of data transfer. Think of shops with several tens of thousands of orders, customers, products.

Read more

Programmatically change Magento’s core config data

Programmatically change Magento’s core config data

Every Magento installation has certain core configuration data already set. When you update those values from the administration interfaces, changes are saved mainly to core_config_data database table. It seems important and something that you shouldn’t touch, right? As always, there are times you will wish to get your hands on it. In some cases you will wish to chance settings directly from the code. This article demonstrates the proper way.

Read more

Load XLS files into Magento modules using PHP-ExcelReader class

Load XLS files into Magento modules using PHP-ExcelReader class

Recently I had a small problem and it turned out that it wasn’t small as a initially thought. I had to read XLS (Microsoft Excel document) into PHP. After I spent almost 2 hours browsing through internet, I found myself most satisfied with open source project “PHP-ExcelReader class“. It has everything I needed (multiple sheets support and it could read data from both Excel 2000 and 2007). On the other hand, Magento doesn’t support XLS, and I decided to write a small method that you can implement in any Magento class.

Read more

Programmatically create order in Magento

Programmatically create order in Magento

Surprisingly one of the trickiest parts of “under the hood” Magento is how to create order programmatically. At least for me, this was/is the most complex area of Magento development. Reason why it is so difficult is that the order creation process is all but not straightforward. You cannot simply instantiate order model, set some data and call upon the save() method. If you ask me, this is how it should be done.

Read more

Mysteries of Magento Encryption Key

Mysteries of Magento Encryption Key

If you ever went through Magento installation process, you know that at some point you are asked for Magento Encryption key. Magento will automatically generate one for you if you do not enter anything in this field. For first installation, this is just fine. You will see a note that Magento uses this key to encrypt passwords, credit cards and more. Is this really the case?

Read more

Programatically create attribute in Magento, useful for the “on the fly” import system

Programatically create attribute in Magento, useful for the “on the fly” import system

Sometimes when doing an import in Magento from old shop system you are faced with lot of issues related to attributes. For instance your old shop system might have several product attributes that simply do not fit into the default Magento attributes. In such cases you need to create these attributes manually in the Magento admin, assign them to the appropriate attribute set and then construct a valid CSV file with valid column names for these new attributes.

Read more

Inline translation in Magento

Inline translation in Magento

If you need translations for your site but translation packs are not fully translated, then inline translation is very nice feature.
In this post I will cover entire process for inline translation in Magento.

Read more

Creating cron script in Magento

Creating cron script in Magento

Creating Magento cron script is very simple thing. First of all we have to create the module, (I hope that you know how to create magento module) and add in config.xml file next code:

Read more

Magento Hello world module (extension)

Magento Hello world module (extension)

Previously I already wrote how to build custom module (extension) in Magento. Here is a new, refreshed article on that subject.

We will start by creating a simple “Hello world” module. However, you will soon see that simple takes a new meaning with Magento. Creating a bare bone module requires at least two files in Magento. For your module to work you need /app/etc/modules/MyCompany_MyModule.xml, app/code/local/MyCompany/MyModule/etc/config.xml. But, barebone module will not give you a “Hello developer” 🙂 -So, we need to add few more files to the game.

Read more

Programatically create Magento blocks and inject them into layout

Programatically create Magento blocks and inject them into layout

Imagine a scenario where you wish to simply create a view file like custom-note.phtml and show this view file on some new url inside the Magento store. One way to do this is to create a CMS page and call that block from within CMS page. But what if you wish to create and append this block to other areas of Magento layout that are inaccessible from CMS page interface form admin? What if I want to add new div element under the breadcrumbs and append new block under it?

Read more

Add breadcrumbs in Magento to pages that miss them

Add breadcrumbs in Magento to pages that miss them

Here is one solution on how to add breadcrumbs to pages in Magento that by default do not have breadcrumbs. Recently we had a client that requested a basic breadcrumb to be shown on pages that Magento does not serve breadcrumbs.

<?php
/**
*
* CUSTOM BREADCRUMBS
*
* Adds url breadcrumbs for pages that do not have breadcrumbs by default
*
*/
 
?>
<?php if(is_null($crumbs)): ?>
<?php
 
/**
* NOTE
* On some servers use ->getServer('PATH_INFO')
* and on some ->getServer('ORIG_PATH_INFO')
*/
 
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');
 
if(is_null($urlPart))
{
$urlPart = $urlRequest->getServer('PATH_INFO');
}
 
$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);
 
//$controllerName = Mage::app()->getFrontController()->getRequest()->getControllerName();
//$controllerName = ucfirst($controllerName);
 
$controllerName = str_replace("/", " ", $urlPart);
$controllerName = str_replace("_", " ", $controllerName);
$controllerName = str_replace("-", " ", $controllerName);
$controllerName = ucfirst($controllerName);
 
?>
<span class="breadcrumbs">
<strong class="float"><?php echo $this->__("You're currently on: ") ?></strong>
<ul class="breadcrumbs">
<li class="home">
<a title="<?php echo $this->__('Go to Home Page') ?>" href="<?php echo $this->getUrl() ?>"><?php echo $this->__('Home') ?></a>
</li>
<li> / </li>
<li class="<?php echo strtolower($controllerName) ?>">
<strong><?php echo $this->__($controllerName) ?></strong>
</li>
</ul>
</span>
<?php endif; /* END OF CUSTOM BREADCRUMBS */ ?>
Read more