Magento Themes and Magento Extensions

How to extend Magento core controller?

Share
Posted on June 27th, 2011 | Posted by admin

Hi, today I’ll show you how to edit Magento’s core module without messing with core files themselves, or “the right way of doing things”.:D

First of all, I chose Magento’s Customer module and its Account controller as an example. First, you need to find it in Magento’s Core folder (full path: “app/code/core/Mage/Customer/controllers/AccountController.php“).

First step is to create and place folders in your module that will override Magento’s core controller. On to that part:

  1. First, create this file in same folder structure:app/code/local/Inchoo/Coreextended/controllers/Frontend/Customer/AccountController.php. (of course, you can always replace Inchoo with desired namespace, and Coreextended with some other module name, but you’ll need to edit the rest accordingly).
  2. Then create xml for our module located here:app/code/local/Inchoo/Coreextended/etc/config.xml (same analogy as above applies)
  3. And finally, create this file app/etc/modules/Inchoo_Coreextended.xml.

Handling intensive Magento tasks in the background, simulating AJAX via CRON

Share
Posted on June 27th, 2011 | Posted by admin

For those of a weak hart, please skip this article. Before I start presenting the idea, please note that this is just an idea. So what’s it about? In our everyday Magento development there are numerous examples/tasks where we need to import some data into Magento or programmatically create some entries like products, orders, customers, etc. When dealing with larger scale of things, importing/creating 50000 of products can turn out to be a real challenge. Usually we (the developers) strive to a simplest possible solution, which in this case ideally would be to make simple foreach loop where we would have our code handling product creation in each iteration of the loop. Technically this works, but with extreme PHP/environment configurations only.

Second thing that might come to a mind is AJAX approach, like the one seen on the default Magento store where you initiate your product import. This solution is better than previously mentioned as it eliminates the system ending up “resource-less” . If you catch my point. There is one major drawback with this approach as well. That is, this approach works only while your browser is turned on.

Load XLS files into Magento modules using PHP-ExcelReader class

Share
Posted on June 27th, 2011 | Posted by admin

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.

So, here it goes:
public function loadXML($path_to_XML)

{
$include_path = dirname(__FILE__);
$path_to_PHP_ExcelReader = $include_path.”/read_xls/Excel/reader.php”;

require_once $path_to_PHP_ExcelReader;

// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();

How to set multiple stores/websites with one magento installation on different domains

Share
Posted on June 27th, 2011 | Posted by admin

This article will describe quickest way how to use and configure one Magento installation on different domains.
Point here is what do you want to have on that different domains, for example you want to have chosen categories/products on one domain and the other one will be on different language.
First you figure that and then go to configuration.

So for each domain you need to create webiste in main Magento admin installation:
System > Manage Stores > Create Website

For Name: you enter name of you desired domain (“my.website.com”)
For Code: you will enter identifier for that domain (“my_website_com”)

After that you will go to:

Magento: Mass Exclude/Unexclude Images

Share
Posted on June 27th, 2011 | Posted by admin

By default, Magento will check the ‘Exclude’ box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view. Should you ever want to mass unexclude them (or mass exclude your images), you can simply run one of the following sql commands in your database:

# Mass Unexclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `disabled` = '1';

# Mass Exclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0';