Programming

Misuse of helper classes in Magento?

Misuse of helper classes in Magento?

In its MVC structure, Magento allows you to throw in additional classes that might not fit in strictly under the MVC “letters”. One example of these classes are helper classes. These are usually used to isolate a certain, possibly useful, algorithm. Algorithm whose usage would be overhead to write a model as it is more static and general in nature, meaning there is no point in applying it to given instance of an object.

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

Magento custom model with custom validation rules

Magento custom model with custom validation rules

Creating your own Magento module usually goes along with creating your own models within the module. Either you write one or multiple models per module, its a good idea to implement model validation method which you might/should call prior to model save. Good example of Magento’s model that use validation are Mage_Customer_Model_Customer and Mage_Customer_Model_Address_Abstract models. Quick look into the “public function validate()” methods of those two models reveal the simplicity of validation process.

Read more

Extending the Magento API

Extending the Magento API

If you are in the business of developing a mobile application or external web/desktop or some other application/service that needs to communicate with Magento trough its API, then my friend you are out of luck. I am not going to say Magento API is a trash, I’ll simply say it massively lacks certain methods within the existing exposed classes that will make your external application usable.

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

Simple example on how to programatically create two level categories in Magento

Simple example on how to programatically create two level categories in Magento

Recently I have been working on a new site that has large number of products and not so little number of categories. As you all know, Magento import system is somewhat obscure, does not seem to allow you a lot in terms of modifications. You are bound to creating a proper CSV file in order to do a valid import. One of the difficulties with such system often comes down to “how do I transfer all my categories” or “how to I transfer all my images” from old shop system to Magento. My so far practice has simple answer on that: Sometimes, there just isn’t any simply solution. Sometimes you will waste hours of coding just to build a proper CSV file that will later be passed to the import system.

Read more

Programatically create customer and order in Magento with full blown One Page Checkout process under the hood

Programatically create customer and order in Magento with full blown One Page Checkout process under the hood

Its been a while since my last article. Figured I might write one before Google search punishes me 🙂 -Recently I was working on a task that, among other things, required an order to be created programatically alongside with the customer and its billing and shipping address. Example I will demonstrate is just one way of doing things. If you have extra time on your hands, feel free to trace the code for more elegant solution.

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

Moving Magento site, missing images in catalog

Moving Magento site, missing images in catalog

Recently I have came across one funny issue. Interesting how issue can be funny. One of our clients had a request for Magento upgrade, from version 1.2 to 1.3.2.4. Most of you in in Magento development will likely to agree when I say that Magento upgrades can be a night mare. Luckily for me, this one went rather smoothly with one strange result, half of my product images were not visible on frontend/admin.

Read more