示例#1
0
 /**
  * Loads basket service
  * 
  * @return void
  */
 private function loadBasket()
 {
     // For brevity
     $mm = $this->moduleManager;
     $webPageManager = $mm->getModule('Cms')->getService('webPageManager');
     $pageManager = $mm->getModule('Pages')->getService('pageManager');
     $shop = $mm->getModule('Shop');
     // Grab basket manager and load data from a storage
     $basketManager = $shop->getService('basketManager');
     $config = $shop->getService('configManager')->getEntity();
     $basketWebPageId = $pageManager->fetchWebPageIdById($config->getBasketPageId());
     $basketUrl = $webPageManager->getUrlByWebPageId($basketWebPageId);
     // Now tweak basket's entity
     $basket = new BasketEntity();
     $basket->setUrl($basketUrl);
     $basket->setTotalPrice($basketManager->getTotalPrice());
     $basket->setTotalQty($basketManager->getTotalQuantity());
     $basket->setCurrency($config->getCurrency());
     $basket->setEnabled($config->getBasketEnabled());
     // Finally add $basket entity and append a script which handles a basket
     $this->view->addVariable('basket', $basket)->getPluginBag()->appendScript('@Shop/site.module.js');
 }
示例#2
0
 /**
  * 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);
 }