Problem/Motivation

If a user clicks on the empty cart button that results in calling \Drupal\commerce_cart\CartManager::emptyCart() all the order items are removed and so are any adjustments. If a user uses an order quantity to reduce each quantity to 0 or an order item remove button it results in calling \Drupal\commerce_cart\CartManager::removeOrderItem() - if this results in the cart being empty the adjustments are not removed and the empty cart event is not fired.

Proposed resolution

Call emptyCart if the cart is empty after removing an item in \Drupal\commerce_cart\CartManager::removeOrderItem()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new748 bytes

Here's a quick fix. Let's see what breaks.

alexpott’s picture

StatusFileSize
new3.6 KB
new4.33 KB

Add here's a test show the bug.

The last submitted patch, 3: 3065951-3.test-only.patch, failed testing. View results

alexpott’s picture

StatusFileSize
new4.83 KB
new9.16 KB

We need to deal with promotions added as coupons to the cart. If the cart is emptied they should be removed too for consistency.

kkumaren’s picture

StatusFileSize
new9.19 KB

Here is an updated patch

joshmiller’s picture

Status: Needs review » Reviewed & tested by the community

Working on a production site and includes tests :)

mglaman’s picture

I don't know why #6 was uploaded. There's no interdiff and from all I can see

+++ b/modules/promotion/tests/src/Kernel/PromotionCartTest.php
@@ -104,4 +105,77 @@ class PromotionCartTest extends OrderKernelTestBase {
+   /**
+   * Tests adding a product with a promotion to the cart.

This is the only change, which improperly formats the phpdoc

joshmiller’s picture

@mglaman This looks like an ambiguous change, we are referencing #5 on two production sites.

mglaman’s picture

StatusFileSize
new9.11 KB

The patches didn't apply, so here's a reroll. I also fixed the test method descriptions

  • mglaman committed ffb7238 on 8.x-2.x authored by alexpott
    Issue #3065951 by alexpott, mglaman, kkumaren, joshmiller: Using \Drupal...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.