Add an entity property for the Node which can be used as Search API index field
/**
* Implements hook_entity_property_info_alter().
*
* Adds an entity property for the node.
*/
function HOOK_entity_property_info_alter(&$info) {
$properties = &$info['node']['properties'];
$properties['custom_price_calculated'] = array(
'label' => t('Custom calculated price'),
'description' => t('The Price after applying all the changing components.'),
'type' => 'decimal', // options: integer, boolean, ....
'sanitized' => TRUE,
'getter callback' => '_get_my_component_price',
);
}
/**
* Get the amendments price by all applicable components.
*/
function _get_my_component_price($data, array $options, $name, $type, $info) {
$discount = _get_discount_info($data); // custom function.
if (isset($discount['discounted_price']['amount'])) {
$price = $discount['discounted_price']['amount'];
}
else {
$price = NULL;
}
// Convert the value to decimal value.
$currency_code = isset($discount['currency_code']) ? $discount['currency_code'] : 'EUR';
$amount = commerce_currency_amount_to_decimal($price, $currency_code);
return $amount;
}