Closed Hexmage closed 1 year ago
Hi @Hexmage. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @Hexmage,
Thanks for posting the issue!
I would like to suggest you add stock_status
, so that it will give the exact situation of stock.
for eg: The below query:
{
cart(cart_id: "5VrDt8LhknXPP3ugJuXZZerItlVDrtB0") {
items {
id
product {
name
sku
stock_status
}
quantity
}
}
}
Will return:
{
"errors": [
{
"message": "Some of the products are out of stock.",
"extensions": {
"category": "graphql-input"
},
"locations": [
{
"line": 7,
"column": 5
}
],
"path": [
"cart",
"items",
0
]
}
],
"data": {
"cart": {
"items": [
null,
{
"id": "12",
"product": {
"name": "Joust Duffle Bag",
"sku": "24-MB01",
"stock_status": "OUT_OF_STOCK"
},
"quantity": 1
},
{
"id": "13",
"product": {
"name": "Strive Shoulder Pack",
"sku": "24-MB04",
"stock_status": "IN_STOCK"
},
"quantity": 1
}
]
}
}
}
You can see stock_status
as OUT_OF_STOCK
where the product is out of stock.
Thanks
@engcom-Hotel But what if the stock of a product changes from 3 to 2 and I had 3 in my cart. stock_status won't help me identify what the problem is in that scenario.
It's nice that there are error messages in the cart response, but they need a second pass over. Because as they are now they aren't good enough.
Hello @Hexmage,
Thanks for the reply!
This is the valid point, if the cart item is less in stock then proper handling is required. I have followed the below steps to reproduce the issue:
Add 2 items in the cart with 4 quantities each
Set the quantity of a product to 2 in the admin panel, it should be in the customer cart.
Run the cart
query:
{
cart(cart_id: "RQg4YPcQX1htp47j6GMpTKRshfY6SVm6") {
items {
id
product {
name
sku
stock_status
}
quantity
}
}
}
The response for the same is as follows:
{
"errors": [
{
"message": "The requested qty is not available",
"extensions": {
"category": "graphql-input"
},
"locations": [
{
"line": 7,
"column": 5
}
],
"path": [
"cart",
"items",
0
]
}
],
"data": {
"cart": {
"items": [
null,
{
"id": "32",
"product": {
"name": "Strive Shoulder Pack",
"sku": "24-MB04",
"stock_status": "IN_STOCK"
},
"quantity": 3
},
{
"id": "33",
"product": {
"name": "Joust Duffle Bag",
"sku": "24-MB01",
"stock_status": "IN_STOCK"
},
"quantity": 4
}
]
}
}
}
It should display which item has not enough quantity.
Updating the main description as well.
Thanks
Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x
, ^Area:.*
Once all required labels are present, please add Issue: Confirmed
label again.
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1965 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@engcom-Hotel I also consider the fact that a null object appears in the items node when an error occurs very crucial to resolve. As it currently breaks default Venia.
@magento I am working on this
@Usik2203 I'd rather have something that has to be unique to identify the product, because the product name can be identical for products. Also your solution doesn't solve the null object that suddenly got added to the items array.
Any update about null value? I can still reproduce this on 2.4.3-p2
@alitopaloglu I've learned that the null value is the actual exception object. Which is handled by the resolver to make the error node in the response. But this node is never deleted after its handled. I'm currently testing some code on my own environment where I moved the Exception Object to a new node in the item that created it. But this will not work with default Venia.
Hi @Hexmage did you make any progress on this? I'm desperately looking for a solution.
@PauloPhagula Think they fixed it in https://github.com/magento/magento2-pwa which is a repo with pwa specific fixes because the normal magento repo doesn't update fast enough.
Hello, Any Update on this error, its been setting here for months @m2-assistant
@Hexmage I just checked and magento2-pwa didnt fix the issue either
@marwan-corals They sort of did. They added a new graphql endpoint for just errors. While this doesn't fix the fact that there is an empty error object in the cart, it does allow you to easier find out which errors are in the cart.
Personally I used a plugin on the function to add an error string element to each order_item with the raw exception message in there instead of the empty node.
@Hexmage, thanks for the reply, but if the item is shown as null, how is this handled? also can you please share with me this plugin
@Hexmage are you willing to help here ?
@marwan-corals The Plugin
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Experius\CartFix\Plugin\Magento\QuoteGraphQl\Model\Resolver;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item as QuoteItem;
use Magento\QuoteGraphQl\Model\Cart\GetCartProducts;
/**
* @inheritdoc
*/
class CartItems
{
/**
* @var GetCartProducts
*/
private $getCartProducts;
/** @var Uid */
private $uidEncoder;
/**
* @param GetCartProducts $getCartProducts
* @param Uid $uidEncoder
*/
public function __construct(
GetCartProducts $getCartProducts,
Uid $uidEncoder
) {
$this->getCartProducts = $getCartProducts;
$this->uidEncoder = $uidEncoder;
}
/**
* @inheritdoc
*/
public function afterResolve($subject, $result, Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($value['model'])) {
throw new LocalizedException(__('"model" value should be specified'));
}
/** @var Quote $cart */
$cart = $value['model'];
$itemsData = [];
$cartProductsData = $this->getCartProductsData($cart);
$cartItems = $cart->getAllVisibleItems();
/** @var QuoteItem $cartItem */
foreach ($cartItems as $cartItem) {
$productId = $cartItem->getProduct()->getId();
if (!isset($cartProductsData[$productId])) {
$itemsData[] = new GraphQlNoSuchEntityException(
__("The product that was requested doesn't exist. Verify the product and try again.")
);
continue;
}
$productData = $cartProductsData[$productId];
$errorMessages = null;
if ($cart->getData('has_error')) {
foreach ($cartItem->getErrorInfos() as $error) {
$errorMessages[] = $error;
}
}
$itemsData[] = [
'id' => $cartItem->getItemId(),
'uid' => $this->uidEncoder->encode((string) $cartItem->getItemId()),
'quantity' => $cartItem->getQty(),
'product' => $productData,
'errors' => $errorMessages,
'model' => $cartItem,
];
}
return $itemsData;
}
/**
* Get product data for cart items
*
* @param Quote $cart
* @return array
*/
private function getCartProductsData(Quote $cart): array
{
$products = $this->getCartProducts->execute($cart);
$productsData = [];
foreach ($products as $product) {
$productsData[$product->getId()] = $product->getData();
$productsData[$product->getId()]['model'] = $product;
$productsData[$product->getId()]['uid'] = $this->uidEncoder->encode((string) $product->getId());
}
return $productsData;
}
}
The schema.graphqls additions
interface CartItemInterface {
errors: [Error]
}
type Error {
origin: String
type: Int
message: String
}
They removed the module : https://github.com/magento/magento2-pwa/commit/96c5f5f2ed31865f0b87f096221ddb9245f194da
That explains a lot.
Thanks, @Hexmage the provided code is helpful; one more note here is to add to di.xml
<type name="Magento\QuoteGraphQl\Model\Resolver\CartItems">
<plugin name="Magento_CartItems_Add_Source_Errors" type="PathTo\Your\Class\Resolver\CartItems" />
</type>
Hi @Hexmage ,
Thanks for your contribution and collaboration.
I have tried to reproduce the issue in 2.4-develop
but issue is not reproducible to me.
Followed below steps :
Get cart details through graphql query:
query {
customerCart {
id
items {
uid
product {
name
sku
}
quantity
}
}
}
After running above query I am not getting any error message "message": "The requested qty is not available",
as you have reported.
Below is the screenshot for your reference:
If anything missing in above steps kindly provide the information.
Please note that I did PR changes but the response of step 4 was same.
Please test it in latest 2.4-develop
if you are facing any issue kindly provide the information.
Thanks
@engcom-Lima Feels like you don't have manage stock turned on. Because there should be an error message when the stock is below the available stock.
HI @Hexmage ,
I have tried to reproduce the issue in 2.4-develop and followed below steps but issue is not reproducible to me:
Get cart details through graphql query:
query {
customerCart {
id
items {
uid
product {
name
sku
}
quantity
}
}
}
Kindly provide me more information inorder to reproduce the isssue.
Also, please check in latest 2.4-develop
and inform us whether issue is reproducible or not.
Thanks
Hi @Hexmage ,
Thank for your contribution and collaboration.
Please provide more information required to reproduce the issue.
Thanks
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
1.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.