/** * @inheritdoc */ public function init() { if (!isset($this->dataProvider)) { $this->dataProvider = new ArrayDataProvider(['allModels' => $this->basket->getItems($this->itemType), 'pagination' => false]); } parent::init(); }
/** * Renders the widget. */ public function run() { if ($this->basketLink) { $this->options['href'] = $this->basketLink; $html = Html::beginTag('a', $this->options); } else { $html = Html::beginTag('div', $this->options); } if ($this->basketIcon) { $html .= Html::tag('i', '', ['class' => $this->basketIcon]); } $count = $this->basket->getCount($this->itemType); if ($count) { $html .= call_user_func($this->summaryText, $count, $this->basket->getTotalDue()); } else { $html .= Html::tag('span', $this->emptyText); } if ($this->basketLink) { $html .= Html::endTag('a'); } else { $html .= Html::endTag('div'); } echo $html; }
/** * @inheritdoc */ public function save(Basket $basket) { $sessionData = serialize($basket->getItems()); $basket->session->set($this->basketVar, $sessionData); }
/** * @param \dlds\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(); }