Skip to main content

Posts

Customize or Merge the fields in admin grid Magento

Sometimes we need to customize the columns of grid list other than the table fields. Like, merging two fields into one column or displaying content after conditional check. For this we need to add a renderer. Renderer is the class that can render the values of a column by manipulating the data and outputting the data as we like. For this, 1. Create a folder Renderer inside "Block/Adminhtml" of our module. 2. Create a file Somefilename.php with following contents class Organicfeast_Customshipping_Block_Adminhtml_Renderer_Suburbname extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {     public function render(Varien_Object $row) {                 if ($row->getData('first_name') != NULL || $row->getData('last_name') != NULL) {             $firstName = $row->getData('first_name');         ...

Print Customer's Group Name on the transactional emails

For printing the customer’s group name on the order confirmation email, Firstly, we need to copy the following file "app/code/core/Mage/Sales/Model/Order.php" to  "app/code/local/Mage/Sales/Model/Order.php" as core files shouldn't be changed. In Order.php, we should add the following function. This function will return the customer group name. public function getCustomerGroupName(){     if ($groupId = $this->getCustomerGroupId()){         $group = Mage::getModel ('customer/group')->load($groupId);         if ($group->getId()){             return $group->getCode();         }     }     return ''; } Finally, we need to add the following code on the email template to get the group name, {{htmlescape var=order.getCustomerGroupName()}} Cheers!!

Error 503: Service Temporarily Unavailable Magento

We can come across a situation in magento where we are presented with the following message, "Service Temporarily Unavailable  The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later." This happens because when Magento is performing certain tasks, it temporarily creates a file called maintenance.flag. Magento automatically deletes this file when the task is complete. But when the task is incomplete or something wrong happen in between, then this file remains there. Magento checks for its existence and if found redirects to error 503 page. So, the solution is to check if the file maintenance.flag is in magento root. If it is there, then delete it. Cheers!!

Composer in php

For those who are unaware of composer in php, Composer is a tool for dependency management. It allows us to declare the dependent libraries our project needs and installs them in our project. It is inspired by the node's npm and ruby's bundler. So, basically if we have a project that depends on a number of libraries and those libraries depend on other libraries, we declare the libraries we depend on. Composer downloads and installs the required packages in our project. For this, we need a file composer.json that describes the project's dependencies. For e.g. we have used here monolog library to do logging. {     "require": {         "monolog/monolog": "1.2.*"     } }

Detecting the browsing device

We can check the device that is used for browsing. The following code detects if the browsing device is mobile. if (preg_match("/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", strtolower($_SERVER['HTTP_USER_AGENT']))) {  //browsed from mobile device }

Database server does not support the InnoDB storage engine

During installation of magento, sometimes we get the error as "database server does not support the InnoDB storage engine". To overcome this, edit the line of the file app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php Replace public function supportEngine()     {         $variables  = $this->_getConnection()             ->fetchPairs('SHOW VARIABLES');         return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true;     } with public function supportEngine()     {         $variables  = $this->_getConnection()             ->fetchPairs('SHOW ENGINES');         return (isset($variables['InnoDB']) && $variables['InnoD...

Prevent a html element to stop moving at certain point when page is scrolled

We should make the position of the element fixed. For this, the following small jquery snippet will fulfill the requirement. jQuery(window).scroll(function() {                var button = jQuery("#div").position().top;            var window_top = jQuery(window).scrollTop();                if(window_top <= top || window_top >= button) {             jQuery("#sbasket").removeClass('sticky');                   } else {             if(window_top > top) {                 jQuery("#sbasket").addClass('sticky');             }      ...