QUALITY PATCH

MDVA-37234: Adding an item to the cart multiple times (parallel request) for the same SKU creates…

Adding an item to the cart multiple times (parallel request) for the same SKU creates a duplicate line item for the same cart ID. Quality patch MDVA-37234 for magento/module-quote-graph-ql applies to Magento Open Source and Adobe Commerce 2.3.5 to 2.4.3-p3.

Categories
Shopping Cart, Order/Checkout, GraphQL
Components
magento/module-quote-graph-ql, magento/module-quote
Origin
adobe-commerce-support
Since QPT
1.1.3

Issue

Adding an item to the cart multiple times (parallel request) for the same SKU creates a duplicate line item for the same cart ID.

Steps to reproduce

1. Create a simple product with SKU = simple1. 1. Create a customer. 1. Generate a customer token for making GraphQL request. <pre> <code class="language-graphql"> mutation { generateCustomerToken( email: "customer email" password: "customer password" ) { token } } </code> </pre> 1. Use the token mentioned in step 3 to create an empty cart for the customer. <pre> <code class="language-graphql"> mutation{ createEmptyCart } </code> </pre> 1. Create a script to make two addSimpleProductsToCart requests running in parallel. For example: <pre> <code class="language-#!/bin/bash"> curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" -d '{"query" : "mutation { addSimpleProductsToCart( input: { cart_id: \"<YOUR_CART_ID>" cart_items: [ { data: { quantity: 2 sku: \"simple1\" } } ] } ) { cart { items { id product { name sku } quantity } } } }"}' http://magento2.3.local/graphql & curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" -d '{"query" : "mutation { addSimpleProductsToCart( input: { cart_id: \"<YOUR_CART_ID>" cart_items: [ { data: { quantity: 1 sku: \"simple1\" } } ] } ) { cart { items { id product { name sku } quantity } } } }"}' http://magento2.3.local/graphql </code> </pre> 1. Run the script.

Adobe's page lists 2.3.5 - 2.3.7-p1 and 2.4.1 - 2.4.2-p1 as compatible; the versions below are resolved from the current QPT constraints and are the ones the tool will offer.

Adobe scheduled the permanent fix for 2.4.4.

Install

Install the Quality Patches Tool with composer require magento/quality-patches, apply the prerequisites listed for all files applicable to your distribution and version first, then run vendor/bin/magento-patches apply MDVA-37234. On Cloud, add MDVA-37234 under stage.build.QUALITY_PATCHES in .magento.env.yaml.

For cweagans/composer-patches, choose a compatible version below and download the bundle. Copy its MDVA-37234/ folder into patches/composer/, merge composer.patches.json into composer.json, then run composer install. Bundle prerequisites the same way and list them first. Paths are relative to each package root, using the default -p1 level. Prefer local files when configuring composer-patches; a remote URL can change.

Patch files and compatible versions

Packages across compatible versions (2): magento/module-quote-graph-ql, magento/module-quote
Packages across compatible versions (2): magento/module-quote-graph-ql, magento/module-quote

magento/magento2-base >=2.3.5 <2.4.0

Magento Open Source
2.3.7-p4, 2.3.7-p3, 2.3.7-p2, 2.3.7-p1, 2.3.7, 2.3.6-p1, 2.3.6, 2.3.5-p2, 2.3.5-p1, 2.3.5
Adobe Commerce
2.3.7-p4, 2.3.7-p3, 2.3.7-p2, 2.3.7-p1, 2.3.7, 2.3.6-p1, 2.3.6, 2.3.5-p2, 2.3.5-p1, 2.3.5
Requires
MDVA-35197
Patch file
patches/os/MDVA-38481_2.3.6_v2.patch
  • vendor/magento/module-quote-graph-ql/Model/Cart/AddProductsToCart.php
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddSimpleProductsToCart.php

magento/magento2-base >=2.4.1 <2.4.2

Magento Open Source
2.4.1-p1, 2.4.1
Adobe Commerce
2.4.1-p1, 2.4.1
Requires
MDVA-34469
Patch file
patches/os/MDVA-37234_2.4.1.patch
  • vendor/magento/module-quote-graph-ql/Model/Cart/AddProductsToCart.php
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddSimpleProductsToCart.php

magento/magento2-base >=2.4.2 <=2.4.2-p2

Magento Open Source
2.4.2-p2, 2.4.2-p1, 2.4.2
Adobe Commerce
2.4.2-p2, 2.4.2-p1, 2.4.2
Patch file
patches/os/MDVA-38760_2.4.2_v3.patch
  • vendor/magento/module-quote/Model/QuoteMutex.php (added)
  • vendor/magento/module-quote/Model/QuoteMutexInterface.php (added)
  • vendor/magento/module-quote/etc/di.xml
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddProductsToCart.php
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddSimpleProductsToCart.php

magento/magento2-base >=2.4.3 <2.4.4

Magento Open Source
2.4.3-p3, 2.4.3-p2, 2.4.3-p1, 2.4.3
Adobe Commerce
2.4.3-p3, 2.4.3-p2, 2.4.3-p1, 2.4.3
Patch file
patches/os/MDVA-40835_2.4.3.patch
  • vendor/magento/module-quote/Model/QuoteMutex.php (added)
  • vendor/magento/module-quote/Model/QuoteMutexInterface.php (added)
  • vendor/magento/module-quote/etc/di.xml
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddProductsToCart.php
  • vendor/magento/module-quote-graph-ql/Model/Resolver/AddSimpleProductsToCart.php

Sources

Łukasz Bajsarowicz
Built by

Łukasz Bajsarowicz, e-commerce architect

Magento and Adobe Commerce architecture, upgrades, performance and audits for merchants and agencies since 2015; magento.watch is the tooling I use on those projects.

Open source, maintained on weekends.