public function trackCart(CartEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $cart = $event->getCart();
     foreach ($cart->getCartItems() as $cartItem) {
         $product = $cartItem->getProduct();
         $defaultCategory = CategoryQuery::create()->findPk($product->getDefaultCategoryId());
         $this->tracker->addEcommerceItem($product->getRef() ? $product->getRef() : $product->getId(), $product->getTitle(), $defaultCategory->getTitle(), $cartItem->getRealPrice(), $cartItem->getQuantity());
     }
     $this->tracker->doTrackEcommerceCartUpdate($cart->getTotalAmount());
 }
Esempio n. 2
0
 /**
  * Find a specific record in CartItem table using the current CartEvent
  *
  * @param CartEvent $event the cart event
  */
 public function findCartItem(CartEvent $event)
 {
     if (null !== ($foundItem = CartItemQuery::create()->filterByCartId($event->getCart()->getId())->filterByProductId($event->getProduct())->filterByProductSaleElementsId($event->getProductSaleElementsId())->findOne())) {
         $event->setCartItem($foundItem);
     }
 }
Esempio n. 3
0
 public function tntCalculCartWeight(CartEvent $event)
 {
     $event->getCart()->setVirtualColumn('total_weight', $event->getCart()->getWeight());
     $maxWeightPackage = TNTFrance::getConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, 25);
     $totalPackage = 0;
     //If packages are separated per product
     if (1 == TNTFrance::getConfigValue(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, 0)) {
         /** @var \Thelia\Model\CartItem $cartItem */
         foreach ($event->getCart()->getCartItems() as $cartItem) {
             if (null != ($pse = ProductSaleElementsQuery::create()->findPk($cartItem->getProductSaleElementsId()))) {
                 $totalPackage += ceil($cartItem->getQuantity() * $pse->getWeight() / $maxWeightPackage);
             }
         }
     } else {
         $totalPackage += ceil($event->getCart()->getVirtualColumn('total_weight') / $maxWeightPackage);
     }
     $event->getCart()->setVirtualColumn('total_package', $totalPackage);
 }
Esempio n. 4
0
 /**
  * Find a specific record in CartItem table using the current CartEvent
  *
  * @param CartEvent $event the cart event
  */
 public function findCartItem(CartEvent $event)
 {
     // Do not try to find a cartItem if one exists in the event, as previous event handlers
     // mays have put it in th event.
     if (null === $event->getCartItem() && null !== ($foundItem = CartItemQuery::create()->filterByCartId($event->getCart()->getId())->filterByProductId($event->getProduct())->filterByProductSaleElementsId($event->getProductSaleElementsId())->findOne())) {
         $event->setCartItem($foundItem);
     }
 }
Esempio n. 5
0
 /**
  *
  * Modify article's quantity
  *
  * don't use Form here just test the Request.
  *
  * @param \Thelia\Core\Event\Cart\CartEvent $event
  */
 public function changeItem(CartEvent $event)
 {
     if (null !== ($cartItemId = $event->getCartItem()) && null !== ($quantity = $event->getQuantity())) {
         $cart = $event->getCart();
         $cartItem = CartItemQuery::create()->filterByCartId($cart->getId())->filterById($cartItemId)->findOne();
         if ($cartItem) {
             $event->setCartItem($this->updateQuantity($event->getDispatcher(), $cartItem, $quantity));
         }
     }
 }
 /**
  * @return Cart
  */
 public function getDuplicatedCart()
 {
     return parent::getCart();
 }