示例#1
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);
 }
示例#2
0
 public function updateActionField()
 {
     list($fieldName, $id) = explode('_', $this->request->get('field'));
     $value = $this->request->get('value');
     $action = ActiveRecordModel::getInstanceByID('DiscountAction', $id, DiscountAction::LOAD_DATA, array('DiscountCondition', 'DiscountCondition_ActionCondition'));
     if ('type' == $fieldName) {
         switch ($value) {
             case DiscountAction::TYPE_ORDER_DISCOUNT:
                 $action->type->set(DiscountAction::TYPE_ORDER_DISCOUNT);
                 $action->actionCondition->set(null);
                 break;
             case DiscountAction::TYPE_ITEM_DISCOUNT:
                 $action->type->set(DiscountAction::TYPE_ITEM_DISCOUNT);
                 $action->actionCondition->set($action->condition->get());
                 break;
             case DiscountAction::TYPE_CUSTOM_DISCOUNT:
                 $newCondition = DiscountCondition::getNewInstance();
                 $newCondition->isEnabled->set(true);
                 $newCondition->isActionCondition->set(true);
                 $newCondition->isAnyRecord->set(true);
                 $newCondition->save();
                 $action->actionCondition->set($newCondition);
                 $action->type->set(DiscountAction::TYPE_ITEM_DISCOUNT);
                 $action->save();
                 return new JSONResponse(array('field' => $fieldName, 'condition' => $newCondition->toArray()));
                 break;
         }
     } else {
         if ($this->request->get('isParam') != 'false') {
             $action->setParamValue($fieldName, $value);
             $fieldName .= '_' . $action->getID();
         } else {
             $action->{$fieldName}->set($value);
         }
     }
     $action->save();
     return new JSONResponse($fieldName);
 }
示例#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));
 }