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

Shipping methods do not work after order recalculation #75

Open
ivarsbariss-solspace opened this issue Sep 9, 2021 · 3 comments
Open

Comments

@ivarsbariss-solspace
Copy link

ivarsbariss-solspace commented Sep 9, 2021

Description
During the creation of a cart, I am receiving the correct shipping methods with rates (FedEx), and when I select a shipping method a shipping adjuster is added correctly to the cart. I can also save the cart and edit it and still receive the correct shipping methods with rates and select them.

After marking the same cart as completed (turning the cart into an order) and then recalculating it the previously added shipping method disappears from the order and under the "Shipping Method" dropdown I can see all my enabled FedEx services and none of them I am able to add to the order.

After a quick debugging of the Craft Commerce recalculation method, it looks like that during the order recalculation all the enabled shipping services (methods) in Postie are automatically added to the "Shipping Method" dropdown with a 0 rate, and none of them are trying to fetch the new rates from the Postie's provider (FedEx).

Steps to reproduce

  1. Create a cart and select a shipping method. (Notice that only valid shipping methods for the cart are provided in the "Shipping Method" dropdown and the shipping method correctly adds to the cart)

Screenshot 2021-09-09 at 12 51 34

  1. Mark order as completed (Notice that everything is still correctly in place)

Screenshot 2021-09-09 at 12 52 42

  1. Press "Edit" and then "Recalculate order" (Notice that the previously selected shipping method disappears from the order and the "Shipping Method" dropdown now consists of all enabled services)

Screenshot 2021-09-09 at 12 54 04

  1. Select any of the shipping methods in the "Shipping Method" dropdown and notice that none of them will be added to the order.

Screenshot 2021-09-09 at 12 54 28

Additional info

  • Plugin version: 2.4.9
  • Craft version: 3.6.11.2
  • Craft Commerce version: 3.3.5.1
  • Multi-site: No

Additional context
Postie configuration:


return [
    'pluginName' => 'Postie',
    'hasCpSection' => true,
    'enableCaching' => false,
    'displayDebug' => true,
    'displayErrors' => true,
    'manualFetchRates' => false,
    'fetchRatesPostValue' => 'postie-fetch-rates',
    'providers' => [
        'fedEx' => [
            'enabled' => true,
            'settings' => [
                'useTestEndpoint' => false,
                'freightShipperStreetAddress' => '39 Royal Road',
                'freightShipperStreetAddress2' => '',
                'freightShipperCity' => 'Flemington',
                'freightShipperZipcode' => '08822',
                'freightShipperStateCode' => 'NJ',
                'freightShipperCountryCode' => 'US',
                'freightBillingStreetAddress' => '39 Royal Road',
                'freightBillingStreetAddress2' => '',
                'freightBillingCity' => 'Flemington',
                'freightBillingZipcode' => '08822',
                'freightBillingStateCode' => 'NJ',
                'freightBillingCountryCode' => 'US',
                'enableFreight' => true,
            ],
            'services' => [
                'FEDEX_GROUND' => 'Ground',
                'INTERNATIONAL_PRIORITY' => 'International Priority',
                'INTERNATIONAL_PRIORITY_FREIGHT' => 'FedEx International Priority Freight',
                'FEDEX_FREIGHT_PRIORITY' => 'FedEx Freight Priority',
            ],
        ]
    ]
];
@engram-design
Copy link
Member

Yeah, this is a tricky scenario in that when a cart has been completed, we switch from live rates to a snapshot rate. I have a feeling that re-calculating the order essentially ditches the snapshot data. This is because Commerce treats most shipping methods like they're defined under Commerce > Shipping, and Postie-provided live rates are a bit second-class.

I'll investigate further what we can do.

@ivarsbariss-solspace
Copy link
Author

@engram-design thank you for looking into this.

@engram-design
Copy link
Member

So this was slightly related to #29 (comment) where we introduced handling for completed orders. But that was some time ago, and now with Commerce's "Recalculate order" functionality this has posed an issue.

Originally, our handling of completed orders was to not fetch live rates, but still return all available shipping methods enabled for the provider in Postie. These were returned as $0 due to it not being live rates. This was mainly so you could access a ShippingMethod model on the order order.shippingMethod.

However, I've changed this in b6eb38a to only return the shipping method picked before completing the order, and with the proper price. This should prevent issues when recalculating the order total.

As an aside, it does beg the question whether live rates should be allowed when editing an order. It makes sense in case the customer decides to change their shipping method from say "regular" to "express" which would effect the cost. However, this might be difficult in practice, as there's no current way of being able to detect when you're editing a completed order in the control panel, and whether you're just viewing the order.

We certainly don't want to fetch live rates when viewing an order (which it would currently do if we removed this "completed order" check), but there are cases you want to pick a live rate. Commerce would need a way of notifying us when you're editing a completed order through the control panel (via Vue) so we could access that in Postie (PHP). Looking at how they handle the edit order functionality, this currently isn't possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants