diff --git a/src/controllers/CartController.php b/src/controllers/CartController.php index e2836ad29c..4e0eb14555 100644 --- a/src/controllers/CartController.php +++ b/src/controllers/CartController.php @@ -121,7 +121,6 @@ public function actionUpdateCart(): ?Response $qty = (int)$this->request->getParam('qty', 1); if ($qty > 0) { - // We only want a new line item if they cleared the cart if ($clearLineItems) { $lineItem = Plugin::getInstance()->getLineItems()->createLineItem($this->_cart, $purchasableId, $options); diff --git a/tests/unit/controllers/CartTest.php b/tests/unit/controllers/CartTest.php index e49a61c543..8fd6d304a4 100644 --- a/tests/unit/controllers/CartTest.php +++ b/tests/unit/controllers/CartTest.php @@ -222,6 +222,10 @@ public function testAddSinglePurchasable(): void self::assertCount(1, $cart->getLineItems()); self::assertSame(2, $cart->getTotalQty()); self::assertSame($variant->getSalePrice() * 2, $cart->getTotal()); + + if ($cart->id) { + Craft::$app->getElements()->deleteElement($cart, true); + } } /** @@ -255,6 +259,10 @@ public function testAddMultiplePurchasablesLite(): void self::assertSame($lastItem['qty'], $cart->getTotalQty()); $lineItem = $cart->getLineItems()[0]; self::assertEquals($lastItem['id'], $lineItem->purchasableId, 'The last line item to be added is the one in the cart'); + + if ($cart->id) { + Craft::$app->getElements()->deleteElement($cart, true); + } } /** @@ -285,6 +293,10 @@ public function testAddMultiplePurchasables(): void $cart = Plugin::getInstance()->getCarts()->getCart(); self::assertCount(2, $cart->getLineItems(), 'Has all items in the car'); + + if ($cart->id) { + Craft::$app->getElements()->deleteElement($cart, true); + } } /** @@ -326,6 +338,10 @@ public function testAddAddressCustomFieldsOnUpdateCart(): void self::assertEquals($shippingAddress['fields']['testPhone'], $cartShippingAddress->testPhone); self::assertEquals($billingAddress['addressLine1'], $cartBillingAddress->addressLine1); self::assertEquals($billingAddress['fields']['testPhone'], $cartBillingAddress->testPhone); + + if ($cart->id) { + Craft::$app->getElements()->deleteElement($cart, true); + } } /**