Simple database backups

Here’s a simple cron entry that makes database backups once a week and removes backups older than 90 days:

Place this in a file under /etc/cron.d/ and make sure the filename is without dashes or spaces.

Posted in Uncategorized | Leave a comment

Mass rename script

This script comes in handy when you don’t have rename installed on the system:

Run it like this:

Posted in Uncategorized | Comments closed

Increasing admin session lifetime

This is one of the most annoying things when you are doing development with Magento – getting logged out constantly.
To fix it set this variable to some ridiculous limit in php.ini:

Then increase the values in Magento’s admin (on the System → Configuration page):

  • Advanced → Admin → Security → Session Lifetime (seconds) = 86500
  • General → Web → Session Cookie Management → Cookie Lifetime = 86500

Your sessions should now last quite a bit longer.

Posted in Magento | Comments closed

Programmatically creating a product attribute

When developing a shop that needs to be deployed somewhere the proper way to create attributes is using setup scripts. This makes it easy for more developers to get a running version of the shop with all the attributes there without having to add them manually through the admin. It also makes managing product attributes easier since it’s automatic.

Read More »

Posted in Magento | Comments closed

Changing config values using setup scripts

This is a fairly trivial task. If you don’t know how to write a setup script, see How to write a setup (install or upgrade) script.
Updating configuration values boils down to finding the correct path (or key) and then storing the value for it.
In essence, these are the values stored in core_config_data table or (when they are not there) defined by the <default/> section in the config.xmls.

So, here is an example which is pretty much self-explanatory:

Posted in Magento | Comments closed

Writing setup scripts

Setup scripts are Magento’s mechanism for doing database migrations and module bootstrapping. They provide an easy way to:

  • Create any structures modules need (database tables, EAV attributes, additional columns in existing tables, etc),
  • Initialize environments (set up modules’ configurations in core_config_data for example),
  • Bootstrap a shop (everything from adding a store to preparing the products’ attributes),
  • Anything else that needs to happen before something goes live.

Read More »

Posted in Magento | Comments closed

Writing an observer

Magento uses the Observer design pattern which means it has events and you can attach your own observers to those events. These observers can modify things on the fly and are the preferred way to do things since they don’t involve rewriting any core classes, are lightweight and easy to maintain.

Read More »

Posted in Magento | Comments closed

Creating a new Magento module the old-school way

This will show you how to create a new module with the initial setup and (almost) everything you need to get it up and running.

Read More »

Posted in Magento | Comments closed

Adding columns to flat tables

This can be done easily via the setup script. An example is all you really need:

Posted in Magento | Comments closed

Add notice, error and success messages to the flash messenger

Fairly easy to do:

For the admin it’s a wee bit different:

Easy, isn’t it?

Posted in Magento | Comments closed