/** * @param ItemInterface $item * @param OrderInterface $order * @param bool $deleteEntity */ public function removeItem(ItemInterface $item, OrderInterface $order, $deleteEntity = true) { // Remove from order. $order->removeItem($item); if ($deleteEntity) { // Delete item. $this->em->remove($item); } }
/** * Removes items from cart that have no valid shop products * applied; and returns if all products are still available * * @param OrderInterface $cart * * @return bool If all products are available */ private function checkProductsAvailability(OrderInterface $cart) { // no check needed if ($cart->getItems()->isEmpty()) { return true; } $containsInvalidProducts = false; /** @var \Sulu\Bundle\Sales\CoreBundle\Entity\ItemInterface $item */ foreach ($cart->getItems() as $item) { if (!$item->getProduct() || !$item->getProduct()->isValidShopProduct($this->defaultCurrency)) { $containsInvalidProducts = true; $cart->removeItem($item); $this->em->remove($item); } } // persist new cart if ($containsInvalidProducts) { $this->em->flush(); } return !$containsInvalidProducts; }