/** * Update removed cart items - set `removed` field to true if cart item was removed from a cart * * @param Cart $entity */ protected function updateRemovedCartItems(Cart $entity) { if ((int) $entity->getItemsQty() === 0) { foreach ($entity->getCartItems() as $cartItem) { if (!$cartItem->isRemoved()) { $cartItem->setUpdatedAt(new \DateTime('now'), new \DateTimeZone('UTC')); $cartItem->setRemoved(true); } } } elseif ($this->existingCartItems) { $existingCartItems = new ArrayCollection($this->existingCartItems); $newCartItems = $entity->getCartItems(); foreach ($existingCartItems as $existingCartItem) { if (!$newCartItems->contains($existingCartItem)) { if (!$existingCartItem->isRemoved()) { $existingCartItem->setUpdatedAt(new \DateTime('now'), new \DateTimeZone('UTC')); $existingCartItem->setRemoved(true); } } } } }