示例#1
0
 /**
  * @param \yii2mod\cart\Cart $cart
  *
  * @return void
  */
 public function save(Cart $cart)
 {
     $session = $cart->getSession();
     $identifier = $this->getIdentifier($session->getId());
     $items = $cart->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();
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function save(Cart $cart)
 {
     $sessionData = serialize($cart->getItems());
     $this->session->set($this->key, $sessionData);
 }