Skip to main content

Posts

Showing posts with the label Magento

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!!

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...

Writing custom query in Magento Ecommerce platform

Magento has its own database logic and functions to execute the queries. We don't need to hardcode the query string as we can call the magento model functions. However, we can also execute custom query whenever needed. The following script shows how we can achieve it, From the magento controller: protected $db; $this->db = Mage::getSingleton('core/resource')->getConnection('core_write'); $query = "SELECT * FROM " . $this->db->getTableName('tablename') ; $results = $this->db->fetchAll($query); From anywhere in site, / * Get the resource model */ $resource = Mage::getSingleton(‘core/resource’);     /** Retrieve the read connection */ $readConnection = $resource->getConnection(‘core_read’); $tableName = $resource->getTableName(‘catalog_product_entity’); $query = "SELECT * FROM " . $ tableName ;

Changing the attribute type in Magento

Sometimes, we need to change the input type of attributes in Magento. Magento by default doesn't allow to change the input type from backend simply. We need to do this programmatically. Here is a code to change the input type from dropdown to text. $installer = new Mage_Eav_Model_Entity_Setup('core_setup'); $installer->startSetup(); $iProductEntityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId(); $idAttributeOldSelect = $installer->getAttributeId($iProductEntityTypeId, 'manufacturer'); $installer->updateAttribute($iProductEntityTypeId, $idAttributeOldSelect, array(     'frontend_input' => 'text' )); $installer->endSetup(); Finally, we need to remove the old values or they will conflict with the new setup. DELETE FROM catalog_product_entity_int WHERE entity_type_id = 4 and attribute_id = YOUR_ATTRIBUTE_ID_HERE; Cheers!!