/** * try to attach a new item to an existing cart * * @param EventDispatcherInterface $dispatcher * @param \Thelia\Model\Cart $cart * @param int $productId * @param ProductSaleElements $productSaleElements * @param float $quantity * @param ProductPriceTools $productPrices * * @return CartItem */ protected function doAddItem(EventDispatcherInterface $dispatcher, CartModel $cart, $productId, ProductSaleElements $productSaleElements, $quantity, ProductPriceTools $productPrices) { $cartItem = new CartItem(); $cartItem->setDisptacher($dispatcher); $cartItem->setCart($cart)->setProductId($productId)->setProductSaleElementsId($productSaleElements->getId())->setQuantity($quantity)->setPrice($productPrices->getPrice())->setPromoPrice($productPrices->getPromoPrice())->setPromo($productSaleElements->getPromo())->setPriceEndOfLife(time() + ConfigQuery::read("cart.priceEOF", 60 * 60 * 24 * 30))->save(); return $cartItem; }
public function updateClonePSE(ProductCloneEvent $event, $clonedProductPSEId, ProductSaleElements $originalProductPSE, $key) { $originalProductPSEPrice = ProductPriceQuery::create()->findOneByProductSaleElementsId($originalProductPSE->getId()); $clonedProductUpdatePSEEvent = new ProductSaleElementUpdateEvent($event->getClonedProduct(), $clonedProductPSEId); $clonedProductUpdatePSEEvent->setReference($event->getClonedProduct()->getRef() . '-' . ($key + 1))->setIsdefault($originalProductPSE->getIsDefault())->setFromDefaultCurrency(0)->setWeight($originalProductPSE->getWeight())->setQuantity($originalProductPSE->getQuantity())->setOnsale($originalProductPSE->getPromo())->setIsnew($originalProductPSE->getNewness())->setEanCode($originalProductPSE->getEanCode())->setTaxRuleId($event->getOriginalProduct()->getTaxRuleId())->setPrice($originalProductPSEPrice->getPrice())->setSalePrice($originalProductPSEPrice->getPromoPrice())->setCurrencyId($originalProductPSEPrice->getCurrencyId()); $this->eventDispatcher->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $clonedProductUpdatePSEEvent); }