Skip to main content
added 451 characters in body
Source Link
Neo
  • 1.2k
  • 8
  • 8
$howmany = !empty(field_get_items($entity_type, $entity, 'field_how_many') !== FALSE) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = !empty(field_get_items($entity_type, $entity, 'field_reg_price1') !== FALSE) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = !empty(field_get_items($entity_type, $entity, 'field_sale_price2') !== FALSE) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

Also check if checks inIf this format worksstill does not work, Please try to inspect the structure of the stuff returned by field_get_items(). I am pretty sure the issue lies in returning a null from the fist array_pop.

In order to inspect the structure, add these lines to your compute code after enabling and installing devel module: != FALSE

dpm(field_get_items($entity_type, $entity, 'field_how_many')); dpm(field_get_items($entity_type, $entity, 'field_reg_price1')); dpm(field_get_items($entity_type, $entity, 'field_sale_price2')));

$howmany = field_get_items($entity_type, $entity, 'field_how_many') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = field_get_items($entity_type, $entity, 'field_reg_price1') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = field_get_items($entity_type, $entity, 'field_sale_price2') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

Also check if checks in this format works: != FALSE

$howmany = !empty(field_get_items($entity_type, $entity, 'field_how_many')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = !empty(field_get_items($entity_type, $entity, 'field_reg_price1')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = !empty(field_get_items($entity_type, $entity, 'field_sale_price2')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

If this still does not work, Please try to inspect the structure of the stuff returned by field_get_items(). I am pretty sure the issue lies in returning a null from the fist array_pop.

In order to inspect the structure, add these lines to your compute code after enabling and installing devel module:

dpm(field_get_items($entity_type, $entity, 'field_how_many')); dpm(field_get_items($entity_type, $entity, 'field_reg_price1')); dpm(field_get_items($entity_type, $entity, 'field_sale_price2')));

Improved logic and added a few more options
Source Link
Neo
  • 1.2k
  • 8
  • 8
$howmany = is_array(field_get_items($entity_type, $entity, 'field_how_many')) !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = is_array(field_get_items($entity_type, $entity, 'field_reg_price1')) !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = is_array(field_get_items($entity_type, $entity, 'field_sale_price2')) !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

HopeAlso check if checks in this code helps you.format works: != FALSE

$howmany = is_array(field_get_items($entity_type, $entity, 'field_how_many')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = is_array(field_get_items($entity_type, $entity, 'field_reg_price1')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = is_array(field_get_items($entity_type, $entity, 'field_sale_price2')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

Hope this code helps you.

$howmany = field_get_items($entity_type, $entity, 'field_how_many') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = field_get_items($entity_type, $entity, 'field_reg_price1') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = field_get_items($entity_type, $entity, 'field_sale_price2') !== FALSE ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

Also check if checks in this format works: != FALSE

Source Link
Neo
  • 1.2k
  • 8
  • 8

$howmany = is_array(field_get_items($entity_type, $entity, 'field_how_many')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))) : 1; 

$price1 = is_array(field_get_items($entity_type, $entity, 'field_reg_price1')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))) : 1; 

$price2 = is_array(field_get_items($entity_type, $entity, 'field_sale_price2')) ? array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))) : 1; 

$entity_field[0]['value'] = $howmany*$price1*$price2;

Hope this code helps you.