function __construct($subtotal, Discount $discount)
 {
     parent::__construct($discount);
     $this->subtotal = $subtotal;
     // for Amount discounts on Subtotals, prevent amount from ever being greater than the Amount
     if ($discount->Type === "Amount" && $discount->Amount > $this->remaining) {
         $this->remaining = (double) $this->discount->Amount;
         $this->limited = true;
     }
 }
Exemplo n.º 2
0
 public function addAction()
 {
     $parent = ActiveRecordModel::getInstanceByID('DiscountCondition', $this->request->get('id'), DiscountCondition::LOAD_DATA);
     $child = DiscountAction::getNewInstance($parent);
     $child->isEnabled->set(true);
     $child->save();
     return new JSONResponse($child->toArray());
 }
Exemplo n.º 3
0
 public function testPaymentMethodSurcharge()
 {
     $condition = DiscountCondition::getNewInstance();
     $condition->isEnabled->set(true);
     $condition->conditionClass->set('RuleConditionPaymentMethodIs');
     $condition->addValue('TESTING');
     $condition->save();
     $action = DiscountAction::getNewInstance($condition, 'RuleActionPercentageSurcharge');
     $action->actionCondition->set($condition);
     $action->isEnabled->set(true);
     $action->type->set(DiscountAction::TYPE_ORDER_DISCOUNT);
     $action->amount->set(10);
     $action->save();
     $this->order->addProduct($this->products[1], 1, true);
     $this->order->setPaymentMethod('TESTING');
     $this->order->save();
     $price = $this->products[1]->getPrice($this->usd);
     $this->assertEquals((int) ($price * 1.1), (int) $this->order->getTotal(true));
     $action->actionClass->set('RuleActionFixedDiscount');
     $action->save();
     $this->assertEquals((int) ($price - 10), (int) $this->order->getTotal(true));
     $action->actionClass->set('RuleActionFixedSurcharge');
     $action->save();
     $this->assertEquals((int) ($price + 10), (int) $this->order->getTotal(true));
     $action->actionClass->set('RuleActionPercentageDiscount');
     $action->save();
     $this->assertEquals((int) ($price * 0.9), (int) $this->order->getTotal(true));
 }
Exemplo n.º 4
0
 public function testPastOrdersInQuantityPrices()
 {
     ActiveRecordModel::getApplication()->getConfig()->setRuntime('INVENTORY_TRACKING', 'DISABLE');
     $condition = DiscountCondition::getNewInstance();
     $condition->isEnabled->set(true);
     $condition->save();
     $action = DiscountAction::getNewInstance($condition);
     $action->actionClass->set('RuleActionIncludePastOrdersInQuantityPrices');
     $action->isEnabled->set(true);
     $action->save();
     $this->product1->isEnabled->set(true);
     $this->product1->stockCount->set(10);
     $this->product1->save();
     // price = 10
     $price = $this->product1->getPricingHandler()->getPrice($this->usd);
     $price->setPriceRule(3, null, 5);
     $price->setPriceRule(4, null, 4);
     $price->save();
     $this->order->addProduct($this->product1, 2, true);
     $this->order->save();
     $this->assertEquals(20, $this->order->getTotal(true));
     $this->order->finalize();
     $this->order->isPaid->set(true);
     $this->order->save();
     $this->order->reload();
     ActiveRecord::clearPool();
     // new order, purchase 1 item, but receive discount like for 3 items
     $this->validatePastOrderQtPriceOrderTotal(1, 5);
     $this->validatePastOrderQtPriceOrderTotal(2, 8);
     // test with date range
     $action->setParamValue('days', 3);
     $action->save();
     $this->order->dateCompleted->set(strtotime('now -4 days'));
     $this->order->save();
     $this->validatePastOrderQtPriceOrderTotal(1, 10);
     $action->setParamValue('days', 4);
     $action->save();
     $this->validatePastOrderQtPriceOrderTotal(1, 5);
     $this->order->dateCompleted->set(strtotime('now -2 days'));
     $this->order->save();
     $action->save();
     $this->validatePastOrderQtPriceOrderTotal(1, 5);
     $this->order->dateCompleted->set(strtotime('now -20 days'));
     $this->order->save();
     $action->save();
     $this->validatePastOrderQtPriceOrderTotal(1, 10);
 }
 function __construct(array $infoitems, Discount $discount)
 {
     parent::__construct($discount);
     $this->infoitems = $infoitems;
 }