Do you want to add some custom tables or attributes for your custom Magento extension? Let’s understand the process with an extension named ”Insync_Test” to run our installation script.
I hope you are familiar with magento extension development, if not please read our previous blog
Let’s create the directory structure according to the following image.
Add registration file “Insync_Test.xml” in “app\etc\modules” to activate custom module.
true local
Now, we make sure that Magento knows about the module
- Clear cache in Magento Admin, if cache is enabled.
- Go to System->Configuration
- Click Advanced
- In the “Disable modules output” setting box, look for your new module named “Insync_Test”
Now we will create configuration file “config.xml” in path “app\code\local\Insync\Test\etc\” for our module. Add below content.
1.1.5.0 Insync_Test Mage_Eav_Model_Entity_Setup <!— This class needed to create new attribute in Magento --> core_setup core_write core_read
Here version number is important as it decides latest script version to run.
Now we will create the script file with same version declared in “config.xml”.
Create “mysql4-install-1.1.5.0.php” in path “app\code\local\Insync\Test\sql\insync_test_setup\”
Make sure your script file version (in this case 1.1.5.0), should match version defined in “config.xml”.
Add below content to your script file
Now copy your extension into your Magento root folder.
Open Magento admin and clear cache.
If script ran successfully, you can find the table “insync_Test” in Magento Database.
Each time you clear Magento cache, Magento compares for Version number for “insync_test” listed in “core_resource” table and version number in “config.xml” file, if version mismatches Magento look for appropriate script file.
For up-gradation process, suppose if you want to add new functionality into your Magento Extension. You can create an upgrade file in the same folder where script file exists.
Let’s say you want to add a new customer attribute in Magento.
Create a new file “mysql4-upgrade-1.1.5.0-1.1.5.1.php” in “app\code\local\Insync\Test\sql\insync_test_setup”. This means extension will upgrade from 1.1.5.0 to 1.1.5.1. We need to change the version number in “config.xml” to 1.1.5.1, otherwise upgrade script will not run.
Add below content to upgrade file
And also if you check “core_resource” table in Magento Database. You will see latest version number for the extension. Upgrade file like this can be created as many times as required. Cheers, Now you can create install scripts for your extension.
Let me know after comment below if you have any problem.
You may also like it.
Important Things to Remember When Pricing a New Product