Problem/Motivation

Currently, we are manually removing the order items from the cart, if they are unavailable. This is prone to errors (e.g. not resetting the checkout flow nor the checkout step).

Instead, we should remove the order items using the cart manager, which also handles any sideeffects.

Steps to reproduce

Proposed resolution

Use CartManager to remove order items when they are unavailable.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

grevil created an issue. See original summary.

grevil’s picture

Status: Active » Needs review

Done, please review!

grevil’s picture

Here is the removeOrderItem method for reference:

  /**
   * {@inheritdoc}
   */
  public function removeOrderItem(OrderInterface $cart, OrderItemInterface $order_item, $save_cart = TRUE) {
    $order_item->delete();
    $cart->removeItem($order_item);
    $this->eventDispatcher->dispatch(new CartOrderItemRemoveEvent($cart, $order_item), CartEvents::CART_ORDER_ITEM_REMOVE);

    // If this results in an empty cart call the emptyCart method for
    // consistency.
    if ($cart->get('order_items')->isEmpty()) {
      $this->emptyCart($cart, $save_cart);
      return;
    }

    $this->resetCheckoutFlow($cart);
    $this->resetCheckoutStep($cart);
    if ($save_cart) {
      $cart->save();
    }
  }
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the fixes!

Please fix the cspells

anybody’s picture

@grevil still
purchaseability, probably should be: purchasability

  • grevil committed f71a4f0f on 1.x
    feat: #3566660 Use CartManager to remove orderItems when they are...
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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