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); }  

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 […]

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 = […]