Skip to main content

Posts

Error Reporting in Php

PHP error reporting. To be enable to switch between error_reporting during development and release phases, one can define say 'php_error_reporting' in the main configuration file. # 0 - Turn off all error reporting # 1 - Running errors # 2 - Running errors + notices # 3 - All errors except notices and warnings # 4 - All errors except notices # 5 - All errors php_error_reporting=4 Setting error_reporting in PHP files would be something like the code below, <?php // setting PHP error reporting switch(case) { case 0: error_reporting(0); break; case 1: error_reporting(E_ERROR | E_WARNING | E_PARSE); break; case 2: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); break; case 3: error_reporting(E_ALL ^ (E_NOTICE | E_WARNING)); break; case 4: error_reporting(E_ALL ^ E_NOTICE); break; case 5: error_reporting(E_ALL); break; default:     error_reporting(E_ALL);

Setting up virtual host

WAMP or  XAMPP server lets our sites to browse by using the url:   http ://localhost . For eg:  http ://localhost/mysite . But we may need to test out environments which would require different domains, like http://local.server.com. For this, we need to configure the virtual hosts file of our apache server. These are the steps we need to configure vitual host on windows os: 1. Open vhosts.conf file. Location: xampp/apache/conf/extra 2. Add the following code at the end of the file. <VirtualHost *:80>     DocumentRoot "D:\xampp\htdocs"     ServerName localhost </VirtualHost> <VirtualHost local.server.com:80> <!-- this is the vitual host -->     DocumentRoot "D:\xampp\htdocs"     ServerName local.server.com     <Directory "D:\xampp\htdocs">         Order allow,deny         Allow from all     </Directory> </Virtu...

Error reporting in php

Error reporting in php will allow us to track the errors on our website. The error may be notice, warning, fatal errors. The syntax is: error_reporting(); error_reporing(E_ALL); error_reporing(E_ALL ^ E_NOTICE); E_ALL is "everything" E_ALL & ~E_NOTICE is "everything except notices" E_ALL ^ E_NOTICE is "everything except notices"

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.*"     } }