You are here

protected function CommerceDiscountTestBase::createUsageDiscount in Commerce Discount 7

Create a discount.

Parameters

string $discount_type: The discount type; Either 'order_discount' or 'product_discount'.

string $offer_type: The discount offer type; Either 'fixed_amount' or 'percentage'.

int $amount: The discount offer amount.

int $max_usage: Maximal uses for the discount.

Return value

object The newly created commerce_discount entity.

5 calls to CommerceDiscountTestBase::createUsageDiscount()
CommerceDiscountUsageTest::testCommerceDiscountUsageFixedOrderDiscount in tests/commerce_discount_usage.test
Test fixed order discounts.
CommerceDiscountUsageTest::testCommerceDiscountUsageFixedProductDiscount in tests/commerce_discount_usage.test
Test fixed product discounts.
CommerceDiscountUsageTest::testCommerceDiscountUsagePercentageOrderDiscount in tests/commerce_discount_usage.test
Test percentage order discounts.
CommerceDiscountUsageTest::testCommerceDiscountUsagePercentageProductDiscount in tests/commerce_discount_usage.test
Test percentage product discounts.
CommerceDiscountUsageUITest::testCommerceDiscountUsageUIEditDiscount in tests/commerce_discount_usage_ui.test
Test usage specific elements in the edit discount UI.

File

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

Class

CommerceDiscountTestBase
Base class for commerce discount tests.

Code

protected function createUsageDiscount($discount_type, $offer_type, $amount, $max_usage) {

  // Use the base class to create a discount.
  $discount = $this
    ->createDiscount($discount_type, $offer_type, $amount);

  // Populate the max usage field.
  $wrapper = entity_metadata_wrapper('commerce_discount', $discount);
  $wrapper->discount_usage_limit = $max_usage;
  $wrapper
    ->save();
  return $wrapper
    ->value();
}