Blogz

Recent Blogz

Drupal 7: Commerce convert decimal to currency

In Drupal commerce will help to convert any numbers into a proper currency format. The function commerce_currency_format() helps to convert decimal numbers to particular country formatted currency. This function will accept a decimal number and country currency code for change given number into currency.

Drupal 7: Database Aggregate functions (SUM, MIN, MAX, COUNT, AVG,..)

The MySQL database query supports aggregate functions to retrieve values from the database. In our custom query, we can able to add aggregate queries. The function addExpression() takes object of database query to aggregate results in db_select(). The below example will demonstrate the usage of aggregate functions.

Drupal 7: Database query with MySQL Date functions

The MySQL is the database which stores any type of data in Database. Using the MySQL we can able to store date-related fields. The MySQL will support Date functions to retrieve and format database date field values. In Drupal also we can able to add date functions in our queries with help of where() function in the database object. The below is the syntax and example of usage of the where() function.

Drupal 7: Making Drupal block is no-cachable:

Drupal system makes blocks is cachable to speed render. The block cache is stored in Drupal core database block_cache table. By altering or change information of block as non-cachable. This is achieved by passing cache as "DRUPAL_NO_CACHE" in hook_block_info() for custom block and hook_block_info_alter() in existing block.

Drupal 7: Render/Display field value from entity object

In Drupal, each and every entity will different fields. These Fields are stored as the seprate table in Drupal system. Based on the field type(Text field, Body field, Integer, File upload field, entity reference field) the render display format can change. While rendering field value in our custom code need to concentrate on the field display format. The function drupal_render() with field_view_field() we can output formated values.

Drupal 7: Formating Date time (Changing Date based on timezone)

The Drupal will support different type timezone to process date related data. But actual data are stored in Unix time stamp format of UTC in the database. The Drupal default core system will process dates as configured in system configuration. While we accessing database date values we need to format to particular timezone date.