Beispiel #1
0
 /**
  *
  * add an article in the current cart
  * @param \Thelia\Core\Event\Cart\CartEvent $event
  */
 public function addItem(CartEvent $event)
 {
     $cart = $event->getCart();
     $newness = $event->getNewness();
     $append = $event->getAppend();
     $quantity = $event->getQuantity();
     $currency = $cart->getCurrency();
     $customer = $cart->getCustomer();
     $discount = 0;
     if (null !== $customer && $customer->getDiscount() > 0) {
         $discount = $customer->getDiscount();
     }
     $productSaleElementsId = $event->getProductSaleElementsId();
     $productId = $event->getProduct();
     $cartItem = $this->findItem($cart->getId(), $productId, $productSaleElementsId);
     if ($cartItem === null || $newness) {
         $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId);
         if (null !== $productSaleElements) {
             $productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);
             $event->setCartItem($this->doAddItem($event->getDispatcher(), $cart, $productId, $productSaleElements, $quantity, $productPrices));
         }
     }
     if ($append && $cartItem !== null) {
         $cartItem->addQuantity($quantity)->save();
         $event->setCartItem($cartItem);
     }
 }
 /**
  * Get the selected legacy product attributes.
  *
  * @param CartEvent $event
  */
 protected function getLegacyProductAttributes(CartEvent $event)
 {
     $product = ProductQuery::create()->findPk($event->getProduct());
     $productAttributes = $product->getTemplate()->getAttributes();
     $this->legacyProductAttributes = [];
     /** @var Attribute $productAttribute */
     foreach ($productAttributes as $productAttribute) {
         $legacyProductAttributeFieldKey = CartAddFormExtension::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId();
         if ($event->{$legacyProductAttributeFieldKey} !== null) {
             $this->legacyProductAttributes[$productAttribute->getId()] = $event->{$legacyProductAttributeFieldKey};
         }
     }
 }
Beispiel #3
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);
     }
 }
Beispiel #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);
     }
 }