/** * Returns all product entities stored in the basket * * @return array */ public function getProducts() { $products = $this->collection->getContainer(); $entities = array(); foreach ($products as $id => $options) { $product = $this->productMapper->fetchById($id); if (count($product) === 1) { // If a product itself has been removed. We'd simply ignore it and remove it from collection $this->removeById($id); } else { $qty = (int) $options[self::BASKET_STATIC_OPTION_QTY]; $price =& $options[self::BASKET_STATIC_OPTION_SUBTOTAL_PRICE]; $imageBag = clone $this->imageBag; $imageBag->setId((int) $product['id'])->setCover(Filter::escape($product['cover'])); // Grab actual price $price = $this->getPrice($product); // Now finally prepare the entity $entity = new BasketEntity(); $entity->setId($product['id'], BasketEntity::FILTER_INT)->setTitle($product['title'], BasketEntity::FILTER_HTML)->setInStock($product['in_stock'], ProductEntity::FILTER_INT)->setUrl($this->webPageManager->getUrl($product['web_page_id'], $product['lang_id']))->setImageBag($imageBag)->setQty($qty)->setPrice($price)->setSubTotalPrice($qty * $price); // Finally add prepared entity array_push($entities, $entity); } } // And return in reversed order return array_reverse($entities, true); }
/** * Removes category's web page * * @param string $id Category id * @return boolean */ private function removeWebPageById($id) { $webPageId = $this->categoryMapper->fetchWebPageIdById($id); return $this->webPageManager->deleteById($webPageId); }