Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!isset($this->dataProvider)) {
         $this->dataProvider = new ArrayDataProvider(['allModels' => $this->basket->getItems($this->itemType), 'pagination' => false]);
     }
     parent::init();
 }
Esempio n. 2
0
 public function finalizeBasketPrice($price, Basket $basket)
 {
     foreach ($basket->getItems(Basket::ITEM_DISCOUNT) as $model) {
         if ($model instanceof Discount) {
             if ($model->type === 'PERCENT') {
                 $price *= (100 - $model->amount) / 100;
             }
         }
     }
     return ceil($price);
 }
Esempio n. 3
0
 public function saveFromBasket(Basket $basket)
 {
     $transaction = $this->getDb()->beginTransaction();
     try {
         $this->due_amount = $basket->getTotalDue(false);
         if (!$this->save()) {
             throw new \RuntimeException('Could not save order model');
         }
         foreach ($basket->getItems(Basket::ITEM_PRODUCT) as $item) {
             $model = new OrderLine(['order_id' => $this->id, 'product_id' => $item->id, 'quantity' => $item->basketQuantity, 'due_amount' => $item->totalPrice]);
             if (!$model->save()) {
                 throw new \RuntimeException('Could not save order line model');
             }
         }
         $transaction->commit();
     } catch (\Exception $exception) {
         $transaction->rollback();
         throw $exception;
     }
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function save(Basket $basket)
 {
     $sessionData = serialize($basket->getItems());
     $basket->session->set($this->basketVar, $sessionData);
 }
Esempio n. 5
0
 /**
  * @param \opus\ecom\Basket $basket
  * @return void
  */
 public function save(Basket $basket)
 {
     $identifier = $this->getIdentifier($basket->getSession()->getId());
     $items = $basket->getItems();
     $sessionData = serialize($items);
     $command = $this->db->createCommand();
     if (empty($items) && true === $this->deleteIfEmpty) {
         $command->delete($this->table, [$this->idField => $identifier]);
     } else {
         $command->setSql("\n                REPLACE {{{$this->table}}}\n                SET\n                    {{{$this->dataField}}} = :val,\n                    {{{$this->idField}}} = :id\n            ")->bindValues([':id' => $identifier, ':val' => $sessionData]);
     }
     $command->execute();
 }
 /**
  * @return \yii\web\Response
  */
 public function actionClear()
 {
     $this->basket->clear(true);
     return $this->redirect(['basket/index']);
 }