Description
Summary
In the following MR: #27914
A new DTO pattern was introduced for the addProductsToCart
mutation.
This new pattern in Magento 2 GraphQl creates multiple cartItem objects via the new
keyword.
Thus losing all additional information to add a custom CartItemInput field.
See: magento/module-quote-graph-ql/Model/Resolver/AddProductsToCart.php
Specifically these lines:
$cartItemsData = $this->cartItemPrecursor->process($cartItemsData, $context);
$cartItems = [];
foreach ($cartItemsData as $cartItemData) {
$cartItems[] = (new CartItemFactory())->create($cartItemData);
}
/** @var AddProductsToCartOutput $addProductsToCartOutput */
$addProductsToCartOutput = $this->addProductsToCartService->execute($maskedCartId, $cartItems);
Any new info in $cartItemsData
is lost due to the CartItemFactory->create
function having the following code:
return new CartItem(
$data['sku'],
$data['quantity'],
$data['parent_sku'] ?? null,
isset($data['selected_options']) ? $this->createSelectedOptions($data['selected_options']) : [],
isset($data['entered_options']) ? $this->createEnteredOptions($data['entered_options']) : []
);
Also $cartItemsData
is not being passed to the addProductsToCartService
so it's impossible to properly extend.
Examples
Summary describes it well.
Proposed solution
Remove the newly introduced Data model which breaks extensibility and adds additional complexity.
Replace new keywords with ObjectManager so extensibility is possible.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status