System configuration fields

There are different field types for Magento’s system configuration. These are for example: Button Checkboxes Checkbox Date File Hidden Imagefile Image Label Link Multiline Multiselect Note Obscure Password Radio Radios Reset Select Submit Textarea Text Time The following snippets show you how to add them to your system.xml: Enable selection (yes/no): <?xml version=”1.0″?> <config> <sections> […]

Rewrite exiting Magento models

To rewrite exiting Magento models, you can add the following snippet to your modules config.xml: <?xml version=”1.0″?> <config> <modules> <AskSheldon_Module> <version>0.1.3</version> </AskSheldon_Module> </modules> <!– … –> <global> <models> <checkout> <rewrite> <session>AskSheldon_Module_Model_Checkout_Session</session> <type_onepage>AskSheldon_Module_Model_Checkout_Type_Onepage</type_onepage> </rewrite> </checkout> </models> </global> <!– … –> </config> In this case Mage_Checkout_Model_Session and Mage_Checkout_Model_Type_Onepage are rewritten.

Substring or split

MySQL don’t now an explode or split function. But you can use SUBSTRING_INDEX: SUBSTRING_INDEX(caet_ast.value, “\n”, 1) as street_name, SUBSTRING_INDEX(caet_ast.value, “\n”, -1) as street_nbr, This gets Testweg for street_name and 881 for street_nbr if caet_ast.value was “Testweg\n 881”. The function is also nestable: SUBSTRING_INDEX(SUBSTRING_INDEX(path, ‘/’, 2), ‘/’, -1) This makes 3 if path was 1/3/342/357/363.

Upload File via FTP on shell

To upload a file on the shell via FTP (https://en.wikipedia.org/wiki/File_Transfer_Protocol) you can use the wput command. Therefor you have to install it with your systems package manager (aptitude in this example): $> sudo apt-get install wput Now you can upload files like that: $> wput loacalfiletoupload ftp://user:password@host/path/to/target/on/remote/host Attention: The target path have to be relative to […]

Translation files for custom modules

To register a translation file for your module: <!– Translation file for FE –> <frontend> <translate> <modules> <Sheldon_Module> <files> <!– filename under app/locale/LANGUAGE_CODE/ f.e.: LANGUAGE_CODE = “EN_US” –> <default>filename.csv</default> </files> </Sheldon_Module> </modules> </translate> </frontend>   <!– Translation file for BE–> <adminhtml> <translate> <modules> <Sheldon_Module> <files> <!– filename under app/locale/LANGUAGE_CODE/ f.e.: LANGUAGE_CODE = “EN_US” –> <default>filename.csv</default> […]

Find out where my.cnf is located

To find out where the MySQL configuration (my.cnf) is stored, you can use the strace command: $> strace mysql “;” 2>&1 | grep my.cnf You will get an output showing all the paths the MySQL deamon searches for the my.cnf upon startup like that: stat(“/etc/my.cnf”, 0x7fffecb75210) = -1 ENOENT (No such file or directory) stat(“/etc/mysql/my.cnf”, {st_mode=S_IFREG|0644, st_size=3505, […]

Include TypoScript from file

To include TypoScript from an external file you can add this line to the setup or constants part of a template record in Typo3 Backend: <INCLUDE_TYPOSCRIPT: source=”FILE: fileadmin/typoscript.ts”> To see your changes immediately, you should add the no_cache flag to your default config: config.no_cache = 1 This disables the caching of your TypoScript.

Performance optimized attribute saving

Sometimes, when you have to handle many data-sets, it is more efficient to save only those attributes that have changed: // load product $product = Mage::getModel(“catalog/product”)->load(142);   // change attribute $product->setTitle(“Test”);   // tell resource attribute to save only the specified field $product->getResource()->saveAttribute($product, “title”);  

Download or upload a file over SSH

#Copy something from this system to some other system: $> scp /path/to/local/file username@hostname:/path/to/remote/file   #Copy something from some system to some other system: $> scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file   #Copy something from another system to this system: $> scp username@hostname:/path/to/remote/file /path/to/local/file You can add a port with the -P param You can do it recursive with […]