Category : PHP

Magento – save and get data from cache

Just a method to save and get data from magento cache $mydataforcache = “My data for cache”; $cache_name = “maycachename”; $CACHEDATA = MAGE::app()->loadCache($cache_name); if (isset($CACHEDATA) && ($CACHEDATA != “”)) { // Use data echo $CACHEDATA; } else { // Save data to cache Mage::app()->saveCache($mydataforcache, $cache_name, array(), 10800); }

Zend Framework – Setting the DocType

Specify the DocType $this->doctype(‘XHTML1_STRICT’); XHTML1_STRICT – XHTML 1.0 Strict XHTML1_TRANSITIONAL – XHTML 1.0 Transitional HTML4_STRICT – HTML 4.01 Strict HTML4_Loose – HTML 4.01 Loose HTML5 – HTML 5 Source: Zend Framework

Magento get customer group Id and group name

Get customer group Id // Check if costomer is logged in if(Mage::getSingleton(‘customer/session’)->isLoggedIn()) { // Get group Id $groupId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId(); } Get group name: $group = Mage::getModel(‘customer/customer_group’)->load($groupId); $group->getName();

Magento get parameters

Get a parameter value: $paramValue = $this->getRequest()->getParam($paramName); Get all parameters and values: $allParams = $this->getRequest()->getParams();

Magento get subcategories

Get subcategories of a main category: $_cat = Mage::getModel(‘catalog/category’)->load($cat_id); $_subcats = $_cat->getChildrenCategories(); foreach ($_subcats as $subcat) { echo “<h1>” . $subcat->getName() . “<h1>”; } Get subcategories Ids $subcat_ids = Mage::getResourceSingleton(‘catalog/category_tree’)->load()->getChildren($cat_id, false);

Magento Installation – 404 not found

Hack to solve the “404 Not Found error” after magento installation: Replace in the original index.php: Mage::run(”); with Mage::run(‘default’); Instead of ‘default’ can be used the name of default store.

Magento – TinyMCE Image Uploader / Image incorrect URL

Small hack in file: app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php to correct image url from something like: <img src=”http://www.mysite.com//index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ii9jbGFzc2lmaWVkVUwuanBnIn19/key/f90eef374eaee0f5b76fc9783680c059/” /> into the correct image url. public function getImageHtmlDeclaration($filename, $asIs = false) { $fileurl = $this->getCurrentUrl() . $filename; $mediaPath = str_replace(Mage::getBaseUrl(‘media’), ”, $fileurl); $directive = sprintf(‘{{media url=”%s”}}’, $mediaPath); $directive = $fileurl; if ($asIs) { $html = sprintf(”, $directive); } else {

Read More →

1 2 3 4