Esempio n. 1
1
 /**
  * Add a product(s) to cart
  *
  * @param array $items            
  * @return true
  */
 public function insert(array $items)
 {
     if (!is_array($items) or empty($items)) {
         throw new \Exception('Only correct values could be saved in Shopping cart.');
     }
     if (!is_array($this->session['cart'])) {
         $this->session['cart'] = array();
     }
     if ($this->isMultidimention($items)) {
         foreach ($items as $item) {
             $this->session['cart'][$this->generateToken($item)] = $this->hydrator->hydrate($item, new $this->entityPrototype());
         }
     } else {
         $this->session['cart'][$this->generateToken($items)] = $this->hydrator->hydrate($items, $this->entityPrototype);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @param  array  $fields
  * @return array
  */
 public function _get($fields = array())
 {
     $results = $this->connection->find(static::$collection, $this->_where, $fields);
     $this->_count = $results->count();
     if (!is_null($this->_limit)) {
         $results->limit($this->_limit);
     }
     if (!is_null($this->_skip)) {
         $results->skip($this->_skip);
     }
     if (!empty($this->_sort)) {
         $results->sort($this->_sort);
     }
     return Hydrator::hydrate($this, $results);
 }