To create a support ticket, start a search

Products Grid: Added a calculated column "Volume in cubic meters (m³)"


Target

We would like to add a calculated* column which indicates the volume of the product in cubic metres (m³).

We will then be able to:

  • use filters in the grids to find the most sizeable / less sizeable products.
  • export quickly the products grid including this field to work on an Excel spreadsheet

 

Setup

To add the field to the list of available fields for your products grids, click on the in the 'Add a field' panel and enter the following information:

What is the field ID?: v_m3

Sc creates the field, you now need to populate the grid with:

Field name: Volume in m3
Table: Another table
Type: Just display
Refresh combinations: No

 

The formula for calculating this field is as follows: Width x Height x Depth / 1000000

For a calculated field, we have two options:

SQL: the field can be used on all product grids

PHP: the field can only be used if the necessary fields (Width, Height, Depth for our example) are present in the grid.

 

SQL: From the Advanced Properties panel on the right handside, select the menu SQL Select and enter:

return ' , ((p.`width`*p.`height`*p.`depth`)/1000000) as v_m3';

 

PHP: From the Advanced Properties panel on the right handside, select the menu PHP Get Row data and enter:

if($col == 'v_m3'){
    $prodrow[$col] = (float)((float)$prodrow['width']*(float)$prodrow['height']*(float)$prodrow['depth'])/1000000;
}


Please note the $prodrow variable contains all the fields of the grid with their final value.

 

Save on the toolbar

Exit the editing window.

The new field is now present in the list of available fields and you can add it to your product grids.

 

* calculated for display. Is not stored in database.

 




Related articles