Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.4.5] Incorrect carrier/method code on selected shipping method in GraphQL #36606

Closed
2 of 5 tasks
DuckThom opened this issue Dec 14, 2022 · 13 comments
Closed
2 of 5 tasks
Assignees
Labels
Area: Shipping Component: GraphQL GraphQL Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Project: GraphQL Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@DuckThom
Copy link

DuckThom commented Dec 14, 2022

Preconditions and environment

  • Magento 2.4.5
  • GraphQL modules are enabled

Steps to reproduce

  1. Set a shipping address on the cart which has an available shipping method with an underscore in the carrier (ie. sendcloud_checkout)
  2. Set the shipping method on the cart
  3. Compare the carrier and method codes in available_shipping_methods and selected_shipping_method on the cart.shipping_addresses[0] object returned by GraphQL

GraphQL query:

query {
    cart(cart_id: "<cart_id>") {
        shipping_addresses {
            selected_shipping_method {
                carrier_code
                method_code
            }
            available_shipping_methods {
                carrier_code
                method_code
            }
        }
    }
}

Expected result

The returned selected_shipping_method matches with one of the available_shipping_methods carrier and method codes.

Result based on above query:

{
    "data": {
        "cart": {
            "shipping_addresses": [
                {
                    "selected_shipping_method": {
                        "carrier_code": "sendcloud_checkout",
                        "method_code": "ddc961a8-1824-40ab-88a9-392f2f58e3b5"
                    },
                    "available_shipping_methods": [
                        {
                            "carrier_code": "sendcloud_checkout",
                            "method_code": "ddc961a8-1824-40ab-88a9-392f2f58e3b5"
                        }
                    ]
                }
            ]
        }
    }
}

Actual result

There is a mismatch between the carrier/method codes in the selectedShippingMethod and availableShippingMethods.

Result based on above query:

{
    "data": {
        "cart": {
            "shipping_addresses": [
                {
                    "selected_shipping_method": {
                        "carrier_code": "sendcloud",
                        "method_code": "checkout_ddc961a8-1824-40ab-88a9-392f2f58e3b5"
                    },
                    "available_shipping_methods": [
                        {
                            "carrier_code": "sendcloud_checkout",
                            "method_code": "ddc961a8-1824-40ab-88a9-392f2f58e3b5"
                        }
                    ]
                }
            ]
        }
    }
}

Additional information

The shipping method is saved on the quote as method.carrierCode + '_' + method.methodCode

In the resolver for the selected_shipping_method field, the following line is present:

list($carrierCode, $methodCode) = explode('_', $address->getShippingMethod(), 2);

This will split on the first underscore, which is not correct.

Possible solution:

diff --git a/vendor/magento/module-quote-graph-ql/Model/Resolver/ShippingAddress/SelectedShippingMethod.php b/vendor/magento/module-quote-graph-ql/Model/Resolver/ShippingAddress/SelectedShippingMethod.php
--- a/vendor/magento/module-quote-graph-ql/Model/Resolver/ShippingAddress/SelectedShippingMethod.php	
+++ b/vendor/magento/module-quote-graph-ql/Model/Resolver/ShippingAddress/SelectedShippingMethod.php
@@ -38,11 +38,11 @@
             return null;
         }
 
-        list($carrierCode, $methodCode) = explode('_', $address->getShippingMethod(), 2);
-
         /** @var Rate $rate */
         foreach ($rates as $rate) {
             if ($rate->getCode() == $address->getShippingMethod()) {
+                $carrierCode = $rate->getCarrier();
+                $methodCode = $rate->getMethod();
                 $carrierTitle = $rate->getCarrierTitle();
                 $methodTitle = $rate->getMethodTitle();
                 break;

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”.
@m2-assistant
Copy link

m2-assistant bot commented Dec 14, 2022

Hi @DuckThom. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented Dec 14, 2022

Hi @engcom-November. 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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf 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 branch

    Details- 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.

@engcom-Hotel engcom-Hotel added the Reported on 2.4.5 Indicates original Magento version for the Issue report. label Dec 15, 2022
@engcom-November
Copy link
Contributor

Hi @DuckThom ,
Thank you for reporting and collaboration. As per Magento devdocs , Graphql supports only below shipping methods by default.
image and none of the shipping methods have underscore in carrier code to reproduce the issue. Also sendcloud is a 3rd party package and code of the extension is not part of Magento git repository. Community cannot able to provide fix for it in this repository. All questions, issue reports and fix for them should be addressed to the corresponding extension owners(support) on the Magento Market place page. Kindly recheck the issue on Magento 2.4-develop instance with Graphql supported shipping methods and provide missing steps if the issue is still reproducible.
Thank you.

@engcom-November engcom-November added the Issue: needs update Additional information is require, waiting for response label Dec 15, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Dec 15, 2022
@DuckThom
Copy link
Author

I agree that the built-in carriers do not use underscores in the codes, however, it's not mentioned anywhere what the allowed characters are for custom carriers.

IMO, it would be better if it was either mentioned in the dev docs what the allowed characters are or if some validation is added perhaps. As right now, it can lead to cases such as this one where unexpected data is returned.

@engcom-November engcom-November added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Dec 28, 2022
@engcom-November
Copy link
Contributor

Hi @DuckThom ,
Verified the issue again on Magento 2.4-develop instance using custom shipping method using both with / without underscore in carrier code and the issue is reproducible. Hence updating the description and confirming the issue.
Scenario 1: Custom shipping method created without underscore in carrier code. No issue. Graphql response retrieved as expected. Method displayed in "available_shipping_methods" and "selected_shipping_method"
image

Scenario 2: Custom shipping method created with underscore in carrier code. Issue: Underscore is missing in Graphql response and the method is not displayed in "available_shipping_methods".
image

@engcom-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: GraphQL GraphQL Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Project: GraphQL Area: Shipping labels Dec 28, 2022
@m2-community-project m2-community-project bot removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Dec 28, 2022
@m2-community-project m2-community-project bot moved this from Needs Update to Confirmed in Issue Confirmation and Triage Board Dec 28, 2022
@m2-community-project m2-community-project bot added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: needs update Additional information is require, waiting for response labels Dec 28, 2022
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-7550 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Dec 28, 2022

✅ Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@github-jira-sync-bot
Copy link

❌ You don't have permission to export this issue.

@engcom-November engcom-November added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jan 2, 2023
@m2-community-project m2-community-project bot added this to Ready for Development in High Priority Backlog Jan 2, 2023
@Vasudev-22
Copy link
Contributor

@magento I am working on this

@engcom-November
Copy link
Contributor

Hi @DuckThom ,
Development team is currently working on this issue.
Thank you.

@m2-community-project m2-community-project bot moved this from Dev In Progress to Done in High Priority Backlog May 19, 2023
@m2-community-project m2-community-project bot removed the Progress: PR Created Indicates that Pull Request has been created to fix issue label May 19, 2023
@engcom-Hotel
Copy link
Contributor

engcom-Hotel commented May 19, 2023

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-7550 by the internal team
Related commits: https://github.com/magento/magento2/search?q=AC-7550&type=commits

Based on the Jira ticket, the target version is 2.4.7-beta1.

Thanks

@hostep
Copy link
Contributor

hostep commented Jun 3, 2023

@engcom-Hotel: either you made a typo, or the info from Jira is incorrect, because those fixes are not included in Magento 2.4.6? It's probably going to be included in 2.4.7(-beta1)?

@engcom-Hotel
Copy link
Contributor

Hello @hostep,

That was a typo, I corrected it.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Shipping Component: GraphQL GraphQL Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Project: GraphQL Reported on 2.4.5 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

No branches or pull requests

6 participants