protected function CommerceDiscountTestBase::createDateDiscount in Commerce Discount 7
Create a date 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 $start_time: Discount valid from.
int $end_time: Discount valid until.
Return value
object The newly created commerce_discount entity.
6 calls to CommerceDiscountTestBase::createDateDiscount()
- CommerceDiscountDateTest::testDiscountDateOrderDiscountInTime in tests/
commerce_discount_date.test - Test order discount in timespan.
- CommerceDiscountDateTest::testDiscountDateOrderDiscountOutOfTime in tests/
commerce_discount_date.test - Test order discount out of timespan.
- CommerceDiscountDateTest::testDiscountDateProductDiscountInTime in tests/
commerce_discount_date.test - Test product discount in timespan.
- CommerceDiscountDateTest::testDiscountDateProductDiscountOutOfTime in tests/
commerce_discount_date.test - Test product discount out of timespan.
- CommerceDiscountDateTest::testDiscountSameDay in tests/
commerce_discount_date.test - Test product discount on the same day.
File
- tests/
commerce_discount_base.test, line 237 - Commerce Discounts test base.
Class
- CommerceDiscountTestBase
- Base class for commerce discount tests.
Code
protected function createDateDiscount($discount_type, $offer_type, $amount, $start_time, $end_time) {
// Use the base class to create a discount.
$discount = $this
->createDiscount($discount_type, $offer_type, $amount);
// Populate the date fields.
$discount_wrapper = entity_metadata_wrapper('commerce_discount', $discount);
$discount_wrapper->commerce_discount_date = array(
'value' => $start_time,
'value2' => $end_time,
'date_type' => 'datestamp',
);
$discount_wrapper
->save();
return $discount_wrapper
->value();
}