public function addItem(CartEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $cart = $event->getCart();
        $newness = $event->getNewness();
        $append = $event->getAppend();
        $quantity = $event->getQuantity();
        $currency = $cart->getCurrency();
        $customer = $cart->getCustomer();
        $discount = 0;

        if ($cart->isNew()) {
            $persistEvent = new CartPersistEvent($cart);
            $dispatcher->dispatch(TheliaEvents::CART_PERSIST, $persistEvent);
        }

        if (null !== $customer && $customer->getDiscount() > 0) {
            $discount = $customer->getDiscount();
        }

        $productSaleElementsId = $event->getProductSaleElementsId();
        $productId = $event->getProduct();

        // Search for an identical item in the cart
        $findItemEvent = clone $event;

        $dispatcher->dispatch(TheliaEvents::CART_FINDITEM, $findItemEvent);

        $cartItem = $findItemEvent->getCartItem();

        if ($cartItem === null || $newness) {
            $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId);

            if (null !== $productSaleElements) {
                $productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);

                $cartItem = $this->doAddItem($dispatcher, $cart, $productId, $productSaleElements, $quantity, $productPrices);
            }
        } elseif ($append && $cartItem !== null) {
            $cartItem->addQuantity($quantity)->save();
        }

        $event->setCartItem($cartItem);
    }
public function addItem(CartEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $cart = $event->getCart();
        $newness = $event->getNewness();
        $append = $event->getAppend();
        $quantity = $event->getQuantity();
        $currency = $cart->getCurrency();
        $customer = $cart->getCustomer();
        $discount = 0;

        if ($cart->isNew()) {
            $persistEvent = new CartPersistEvent($cart);
            $dispatcher->dispatch(TheliaEvents::CART_PERSIST, $persistEvent);
        }

        if (null !== $customer && $customer->getDiscount() > 0) {
            $discount = $customer->getDiscount();
        }

        $productSaleElementsId = $event->getProductSaleElementsId();
        $productId = $event->getProduct();

        // Search for an identical item in the cart
        $findItemEvent = clone $event;

        $dispatcher->dispatch(TheliaEvents::CART_FINDITEM, $findItemEvent);

        $cartItem = $findItemEvent->getCartItem();

        if ($cartItem === null || $newness) {
            $productSaleElements = ProductSaleElementsQuery::create()->findPk($productSaleElementsId);

            if (null !== $productSaleElements) {
                $productPrices = $productSaleElements->getPricesByCurrency($currency, $discount);

                $cartItem = $this->doAddItem($dispatcher, $cart, $productId, $productSaleElements, $quantity, $productPrices);
            }
        } elseif ($append && $cartItem !== null) {
            $cartItem->addQuantity($quantity)->save();
        }

        $event->setCartItem($cartItem);
    }
public function addItem ( CartEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ cart = $ event -> getCart ( ) ; $ newness = $ event -> getNewness ( ) ; $ append = $ event -> getAppend ( ) ; $ quantity = $ event -> getQuantity ( ) ; $ currency = $ cart -> getCurrency ( ) ; $ customer = $ cart -> getCustomer ( ) ; $ discount = 0 ; if ( $ cart -> isNew ( ) ) { $ persistEvent = new CartPersistEvent ( $ cart ) ; $ dispatcher -> dispatch ( TheliaEvents :: CART_PERSIST , $ persistEvent ) ; } if ( null !== $ customer && $ customer -> getDiscount ( ) > 0 ) { $ discount = $ customer -> getDiscount ( ) ; } $ productSaleElementsId = $ event -> getProductSaleElementsId ( ) ; $ productId = $ event -> getProduct ( ) ; // Search for an identical item in the cart $ findItemEvent = clone $ event ; $ dispatcher -> dispatch ( TheliaEvents :: CART_FINDITEM , $ findItemEvent ) ; $ cartItem = $ findItemEvent -> getCartItem ( ) ; if ( $ cartItem === null || $ newness ) { $ productSaleElements = ProductSaleElementsQuery :: create ( ) -> findPk ( $ productSaleElementsId ) ; if ( null !== $ productSaleElements ) { $ productPrices = $ productSaleElements -> getPricesByCurrency ( $ currency , $ discount ) ; $ cartItem = $ this -> doAddItem ( $ dispatcher , $ cart , $ productId , $ productSaleElements , $ quantity , $ productPrices ) ; } } elseif ( $ append && $ cartItem !== null ) { $ cartItem -> addQuantity ( $ quantity ) -> save ( ) ; } $ event -> setCartItem ( $ cartItem ) ; }
add an article in the current cart

@param \Thelia\Core\Event\Cart\CartEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher
add an article in the current cart