Exemple #1
0
 /**
  * @param Product $product
  * @return Basket
  */
 public function add(Product $product)
 {
     $basket = $this->session->get('basket', []);
     if (!array_key_exists($product->getId(), $basket)) {
         $basket[$product->getId()] = ['name' => $product->getName(), 'price' => $product->getPrice(), 'quantity' => 1];
     } else {
         $basket[$product->getId()]['quantity']++;
     }
     $this->session->set('basket', $basket);
     return $this;
 }
Exemple #2
0
 /**
  * Add product to basket
  *
  * @param Product $product
  * @return Basket
  */
 public function add(Product $product)
 {
     // get basket
     $basket = $this->session->get('basket', []);
     // Add or update product with basket
     if (!array_key_exists($product->getId(), $basket)) {
         $basket[$product->getId()] = ['name' => $product->getName(), 'price' => $product->getPrice(), 'quantity' => 1];
     } else {
         $basket[$product->getId()]['quantity']++;
     }
     // Set new basket session
     $this->session->set('basket', $basket);
     return $this;
 }
 /**
  * {@inheritDoc}
  */
 public function getName()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getName', array());
     return parent::getName();
 }
Exemple #4
0
 /**
  * @param array $statisticsEntities
  * @param Product $product
  */
 protected function loadOneProductStatistics(array $statisticsEntities, Product $product)
 {
     $productId = $product->getProductId();
     $actualStatisticsData = $statisticsEntities[0];
     $allTimeStatisticsData = $this->getAllTimeProductsStatisticsByProductId($productId);
     $allViews = 0;
     $allOrders = 0;
     $allConversion = 0;
     $allTotal = 0;
     $views = $this->getUniqueViews($actualStatisticsData);
     if ($allTimeStatisticsData) {
         $allViews = $this->getUniqueViews($allTimeStatisticsData);
     }
     $orderCount = $this->getUniqueOrders($actualStatisticsData);
     if ($allTimeStatisticsData) {
         $allOrders = $this->getUniqueViews($allTimeStatisticsData);
     }
     $conversion = $this->getConversion($actualStatisticsData);
     if ($allTimeStatisticsData) {
         $allConversion = $this->getConversion($allTimeStatisticsData);
     }
     $total = $this->getTotal($actualStatisticsData);
     if ($allTimeStatisticsData) {
         $allTotal = $this->getTotal($allTimeStatisticsData);
     }
     $picture = '';
     if ($product->getPicture()) {
         $picture = $this->settingService->get('picture_url') . $product->getPicture();
     }
     $name = $product->getName();
     $sku = $product->getSku();
     $availableDateTime = $product->getAvailableDate();
     $availableDate = $availableDateTime->format('m.Y.');
     $score = $this->getScore($actualStatisticsData);
     $this->collectedData[] = array('picture' => $picture, 'name' => $name, 'sku' => $sku, 'availableDate' => $availableDate, 'score' => $score, 'orderCount' => $orderCount, 'conversion' => $conversion, 'total' => $total, 'views' => $views, 'allTimeViews' => $allViews, 'allTimeOrderCount' => $allOrders, 'allTimeConversion' => $allConversion, 'allTimeTotal' => $allTotal);
 }