Skip to content

[Issue] Call RemoveItem on cart instead of ItemRepository #40255

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #40248: Call RemoveItem on cart instead of ItemRepository


Description (*)

This PR replaces the deleteById calls on the CartItemRepository with removeItem on the cart instance.
This makes sure expected observers are triggered and the item is actually updated on the cart object as well, instead of in the database only.

This fixes a case where if you mass remove items using updateCartItems only a single item is removed in the response.

Manual testing scenarios (*)

  1. Add multiple products to the cart
  2. remove the products with the following query
mutation updateCart($input: UpdateCartItemsInput) {
  updateCartItems(input: $input) {
    cart {
      items {
        uid
      }
    }
  }
}

{
  "input": {
    "cart_id": "xxxx",
    "cart_items": [
      {
        "cart_item_id": "xx",
        "quantity": 0
      },
      {
        "cart_item_id": "xx",
        "quantity": 0
      },
      {
        "cart_item_id": "xx",
        "quantity": 0
      },
      {
        "cart_item_id": "xx",
        "quantity": 0
      },
      {
        "cart_item_id": "xx",
        "quantity": 0
      }
    ]
  }
}
  1. Observe how items still appear to be in the cart until you manually request the cart again.
  2. Repeat these steps after applying this PR
  3. Observe how all selected items have immediately disappeared from the response.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Cart & CheckoutComponent: GraphQLGraphQLIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    Status

    Ready for Development

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions