function commerce_product_pre_calculation_key in Commerce Core 7
Generates a price pre-calculation module key indicating which pricing Rules currently apply.
1 call to commerce_product_pre_calculation_key()
- commerce_product_calculate_sell_price in modules/
product_pricing/ commerce_product_pricing.module - Returns the calculated sell price for the given product.
File
- modules/
product_pricing/ commerce_product_pricing.module, line 164 - Enables Rules based product sell price calculation for dynamic product pricing.
Code
function commerce_product_pre_calculation_key() {
// Load the sell price calculation event.
$event = rules_get_cache('event_commerce_product_calculate_sell_price');
// If there are no rule configurations, use an empty key.
if (empty($event)) {
return '';
}
// Build an array of the names of all rule configurations that qualify for
// dynamic pre-calculation.
$rule_names = array();
$state = new RulesState();
foreach ($event as $rule) {
// Only add Rules with conditions that evaluate to TRUE.
if (count($rule
->conditions()) > 0 && $rule
->conditionContainer()
->evaluate($state)) {
$rule_names[] = $rule->name;
}
}
// If no valid Rules were found, return an empty string.
if (empty($rule_names)) {
return '';
}
// Otherwise sort to ensure the names are in alphabetical order and return the
// imploded module key.
sort($rule_names);
return implode('|', $rule_names);
}