You are here

public function CommerceDiscountTestBase::discountAppliedToOrder in Commerce Discount 7

Determines whether or not a discount has been applied to an order.

Parameters

string $discount_name: The machine-name of the discount to look for.

object $order: The order object to inspect for the discount.

Return value

bool Boolean indicating whether or not the discount is applied to the order.

6 calls to CommerceDiscountTestBase::discountAppliedToOrder()
CommerceDiscountConditionsTest::testCommerceProductContainsProducts in tests/commerce_discount_conditions.test
Test commerce_product_contains_products() condition.
CommerceDiscountConditionsTest::testOrderContainsProductsCondition in tests/commerce_discount_conditions.test
Tests the 'commerce_order_contains_products' rule.
CommerceDiscountTest::testCommerceDiscountCompatibilityStrategies in tests/commerce_discount.test
Test discount compatibility strategies.
CommerceDiscountTest::testCommerceDiscountCompatibilityStrategiesRefresh in tests/commerce_discount.test
Test discount compatibility regression https://www.drupal.org/node/2621526.
CommerceDiscountTest::testCommerceDiscountCompatibilityStrategiesRefreshNone in tests/commerce_discount.test
Test discount compatibility regression https://www.drupal.org/node/2621526.

... See full list

File

tests/commerce_discount_base.test, line 182
Commerce Discounts test base.

Class

CommerceDiscountTestBase
Base class for commerce discount tests.

Code

public function discountAppliedToOrder($discount_name, $order) {

  // Fetch the list of discounts applied to the order based on the price
  // components in its order total array.
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_total = $order_wrapper->commerce_order_total
    ->value();
  $applied_discounts = commerce_discount_get_discounts_applied_to_price($order_total);

  // Look for the given discount in the list of applied discounts.
  return in_array($discount_name, $applied_discounts);
}