/** * Get the total reduction value applied by a voucher. * * @return float */ public function getVoucherReduction() { $filter = self::FILTER_STACKABLE; if ($this->getVoucher()) { $filter = $this->getVoucher()->getStackable() ? self::FILTER_STACKABLE : self::FILTER_NON_STACKABLE; } //$charge = $this->getPreTotalCharge($filter); $charge = $this->getItemsCharge($filter); if (is_null($this->getVoucherCode())) { return 0.0; } return (double) $charge - rtShopVoucherToolkit::applyVoucher($this->getVoucherCode(), $charge); }
$t->is($voucher->getMode(), 'Group', '::getMode() Voucher type is Group.'); $t->is($voucher->getReductionType(), 'dollarOff', '::getReductionType() Voucher reduction_type is dollarOff.'); $voucher->adjustReductionValueBy($order_total); $t->is($voucher->getReductionValue(), 10, '::getReductionValue() Untouched reduction_value is correct.'); $t->diag('Voucher type: Group, Reduction_type: percentageOff'); $order_total = 130; $voucher = rtShopVoucherToolkit::getApplicable($code2, $order_total, date("Y-m-d H:i:s")); $t->is(get_class($voucher), 'rtShopVoucher', '::getApplicable() Returns a rtShopVoucher object correctly.'); $t->is($voucher->getId(), $i4->getId(), '::getApplicable() Found applicable voucher.'); $t->is($voucher->getMode(), 'Group', '::getMode() Voucher type is Group.'); $t->is($voucher->getReductionType(), 'percentageOff', '::getReductionType() Voucher reduction_type is percentageOff.'); $voucher->adjustReductionValueBy($order_total); $t->is($voucher->getReductionValue(), 15, '::getReductionValue() Untouched reduction_value is correct.'); $t->diag('Apply voucher to order total'); $order_total = 100; $voucher_total = rtShopVoucherToolkit::applyVoucher($code4, $order_total, date("Y-m-d H:i:s")); $t->is($voucher_total, 40, '::applyVoucher() Applied voucher correctly and returned new total.'); // Clean up $i3->delete(); $i4->delete(); $i5->delete(); $i6->delete(); $i7->delete(); $i8->delete(); unset($voucher); unset($i3, $i4, $i5, $i6, $i7, $i8); /** * rtShopVoucherToolkit Class */ class rtShopVoucherTestTools {