You are here

function commerce_discount_line_item_compatibility_check in Commerce Discount 7

Rules callback: executes the "Check discount compatibility at the line item level" condition.

Parameters

EntityDrupalWrapper $line_item_wrapper: The line item the discount would be applied to.

string $discount_name: The discount name whose compatibility needs to be checked.

Return value

bool Returns TRUE if nothing has disqualified compatibility.

1 string reference to 'commerce_discount_line_item_compatibility_check'
commerce_discount_build_discount_rules in ./commerce_discount.module
Build the rules configuration for the given discounts.

File

./commerce_discount.rules.inc, line 447
Rules integration for the Commerce Discount module.

Code

function commerce_discount_line_item_compatibility_check(EntityDrupalWrapper $line_item_wrapper, $discount_name) {

  // Ensure the discount we're loading still exists.
  if (!($discount = entity_load_single('commerce_discount', $discount_name))) {
    return FALSE;
  }

  // Use the line item unit price field for line item level compatibility checks.
  $unit_price = $line_item_wrapper->commerce_unit_price
    ->value();
  return _commerce_discount_check_compatibility($discount, $unit_price);
}