Ejemplo n.º 1
0
 /**
  * @param integer $productId
  */
 public function addLog($productId)
 {
     $cartLog = new CartLog();
     $cartLog->setSelectionDatetime(new \DateTime());
     $cartLog->setProduct($this->productRepository->find($productId));
     $this->entityManager->persist($cartLog);
     $this->entityManager->flush();
 }
Ejemplo n.º 2
0
 /**
  * @return array id => name
  */
 public function fetchProductsNamesByIds()
 {
     $output = [];
     $products = $this->productRepository->findAll();
     foreach ($products as $product) {
         $output[$product->getId()] = $product->getName();
     }
     return $output;
 }
Ejemplo n.º 3
0
 /**
  * Unserialize the string.
  * Return false if an error occur. Check the symfony logs.
  *
  * @param string $serializedBasket
  *
  * @return Basket|bool
  */
 public function unserializeBasket($serializedBasket)
 {
     $basket = new Basket();
     $data = unserialize($serializedBasket);
     if (true === array_key_exists('products', $data)) {
         $products = $this->productRepository->retrieveByIdList($data['products']);
         $basket->setProducts($products);
     } else {
         //@todo: log error
         return false;
     }
     if (true === array_key_exists('nbPerProduct', $data)) {
         foreach ($data['nbPerProduct'] as $productId => $nb) {
             $basket->setNbProductByProductId($productId, $nb);
         }
     } else {
         //@todo: log error
         return false;
     }
     return $basket;
 }