/** * Adds product's id to the basket * * @param string $id Product id * @param integer $qty Quantity of product ids to be added * @return boolean */ public function add($id, $qty) { // Ensure product id exists, firstly. This is for synchronization $product = $this->productMapper->fetchById($id); // If id exists, then it will never be empty if (!empty($product)) { $price = $this->getPrice($product); // If we adding the same id twice, then we need to update its data instead if ($this->collection->hasKey($id)) { return $this->update($id, $qty, $price); } else { return $this->insert($id, $qty, $price); } } else { // Wrong id supplied, therefore can't add it return false; } }
/** * Fetches product's entity by its associated id * * @param string $id * @return \Krystal\Stdlib\VirtualEntity|boolean */ public function fetchById($id) { return $this->prepareResult($this->productMapper->fetchById($id)); }