Get all Root-Category-IDs of all stores

This snippet gives you all entity_id’s of all Root-IDs of the Magento instance: /** * @return array Root-IDs of all stores */ public function getAllRootIds(){# $aRootIds = array(); $aRootIds[Mage_Catalog_Model_Category::TREE_ROOT_ID] = Mage_Catalog_Model_Category::TREE_ROOT_ID; $aAllStores = Mage::app()->getStores(); foreach ($aAllStores as $iID => $store){ $rootID = $store->getRootCategoryId(); $aRootIds[$rootID]=$rootID; } return array_keys($aRootIds); }  

Error cause by DEFINER in MySQL-dumps

When importing MySQL- dumps of a Magento database sometimes you get an error message like that (although you can connect to the database via shell f.e.): ERROR 1044 (42000) at line 592: Access denied for user ‘sheldon’@’localhost’ to database ‘magento’ In these cases you’ ll recognize that the user, who tries to connect, is wrong […]

Install attribute in entity main table

Sometimes it is useful to add some fields to the attribute main table (f.e.: IDs from external systems like a middleware or a PIM). In the following example you can see how to add ID-fields to the category entity. Therefore I created a setupscript as an instance of Mage_Catalog_Model_Resource_Setup. Setup-model declaration in config.xml: <?xml version=”1.0″?> […]

Make additional product attributes available over REST-API

To do this you only have to add a api2.xml in your modules etc folder that puts the necessary product tags into the node /config/api2/resources/product/attributes (xPath): <config> <api2> <resources> <product> <attributes> <sheldon_ean>EAN</sheldon_ean> <sheldon_articlenbr>Articlenumber (Model)</sheldon_articlenbr> <sheldon_stylenbr>Stylenumber</sheldon_stylenbr> <sheldon_color>Color</sheldon_color> <sheldon_size>Size</sheldon_size> <sheldon_material_description>Material Description</sheldon_material_description> <sheldon_supplement>Supplement</sheldon_supplement> <sheldon_carehints>Carehints</sheldon_carehints> <sheldon_is_aboable>Is aboable product</sheldon_is_aboable> <sheldon_is_sale_product>Is sale product</sheldon_is_sale_product> <sheldon_is_new_product>Is new product</sheldon_is_new_product> <sheldon_is_reddot_product>Is reddot Product</sheldon_is_reddot_product> <sheldon_reddot_years>Product Reddotyears</sheldon_reddot_years> […]

Send a file header in controller (file download)

To return a downloadable file in a controller action, you have to send a file header in controller like that: $fileName = ‘mm_actioncodes_export_’.date(“Ymd_His”).’.csv’; $fp = fopen(Mage::getBaseDir(‘var’) . DS .’export’ . DS . $fileName, ‘w’); fputcsv($fp, $codes, ‘;’, ‘”‘); fclose($fp); $this->_prepareDownloadResponse($fileName, array( ‘type’ => ‘filename’, ‘value’ => Mage::getBaseDir(‘var’) . DS .’export’ . DS . $fileName, //’rm’ => true […]

Trigger layout handle in another layout handle

In most cases you don’t want to write the same layout declaration twice. With the following snippet you can trigger a once written layout handle in other layout handles. So you can reuse the declaration. <modul_controller_action> <update handle=”modul_controller_action”/><!–layout handle to trigger–> </modul_controller_action>

IP Detection

This little snippet tries to get the IP-Address of the user: private function _detectIP(){ //Mage::log(‘_detectIP’, null, __CLASS__.’.log’, true); if (getenv(‘HTTP_CLIENT_IP’)) { $this->_ip = getenv(‘HTTP_CLIENT_IP’); Mage::log(‘Detected IP (getenv(\’HTTP_CLIENT_IP\’)):’, null, __CLASS__.’.log’, true); Mage::log($this->_ip, null, __CLASS__.’.log’, true); } elseif (getenv(‘HTTP_X_FORWARDED_FOR’)) { $ips = explode(‘,’, getenv(‘HTTP_X_FORWARDED_FOR’)); $this->_ip = (string)trim($ips[0]); } elseif (getenv(‘HTTP_X_FORWARDED’)) { $ips = explode(‘,’, getenv(‘HTTP_X_FORWARDED’)); $this->_ip = […]

Image Grid Column Renderer

To show product image previews in Magento Backend, you have to add a image grid column renderer block first: <?php /** * * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * It is available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php […]