SendCloud / sendcloud

A Magento 2 module for Sendcloud
9 stars 21 forks source link

Selected shipping method codes differ from available shipping method codes #147

Closed DuckThom closed 1 year ago

DuckThom commented 1 year ago

I'm working on a GraphQL based checkout for a Magento 2.4.5 shop in combination with Sendcloud dynamic checkout shipping methods and I noticed that the carrier and method codes change when setting the shipping method on the cart. In the cart response, on the shipping address, there's 2 fields: availableShippingMethods and selectedShippingMethod.

image

At the top you can see the carrierCode and methodCode of the selectedShippingMethod field, at the bottom the same fields but then from the availableShippingMethods item.

To set the shipping method we use the setShippingMethodOnCart GraphQL mutation with the carrier and method code from the availableShippingMethods field. However, when we then look at the returned cart's selectedShippingMethod, the codes do not match.

The request:

image

The response:

image

This makes it impossible to pre-select the selected shipping method in the shipping step of the checkout as we cannot match the carrier and/or method code against the available methods.

DuckThom commented 1 year ago

Upon further inspection, it looks like this might be a bug within Magento's Quote GraphQL module. The shipping method set on the quote address is split on the first underscore which does not work with sendcloud's sendcloud_checkout carrier code:

https://github.com/magento/magento2/blob/ea0cf6395753078e45af8c4a5ddc1ea2c4d91092/app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/SelectedShippingMethod.php#L53

For reference: https://github.com/magento/magento2/issues/36606

teodoratimoti commented 1 year ago

Hello @DuckThom

Thank you for reaching out.

Please note that our team will check this issue and we will get back to you with an update as soon as possible

Kind regards.

DuckThom commented 1 year ago

@teodoratimoti I've been informed by Magento that it's a unspoken/undocumented rule that carrier codes may not contain underscores. For reference, tig_postnl also has the same issue. In that module, a workaround was implemented: https://github.com/tig-nl/postnl-magento2/blob/master/Plugin/Order/ShipmentPlugin.php#L53

teodoratimoti commented 1 year ago

Hello @DuckThom,

Please note that our team is still working on this issue. We will keep you posted about the progress.

Best regards.

teodoratimoti commented 1 year ago

Dear @DuckThom,

Thank you for your patience.

The request you made requires more investigation. The Sendcloud support team is best to investigate more indepth. Please forward your request via the Support page in sendcloud: https://app.sendcloud.com/v2/support or reach out to support@sendcloud.com.

We hope we have informed you sufficiently and wish you a great day!

Kind regards.