duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
143 stars 37 forks source link

Define default shipping costs before selecting #555

Closed steffenschmidt closed 2 years ago

steffenschmidt commented 2 years ago

What's the issue you're running into?

Hi there,

I have three different shipping methods with different shipping costs. As they are selected in the third checkout step I would like to display a default value for shipping costs in the cart view. But the values are empty before selecting the shipping method in step three.

Any idea how to set a default shipping costs (e.g. the lowest one, or name it explicit) to show this in the shopping cart?

Cheers

Steffen

Steps to reproduce

Environment

Statamic 3.2.32 Pro
Laravel 8.81.0
PHP 8.1.0
aryehraber/statamic-logbook 2.0.2
doublethreedigital/simple-commerce 2.3.64
jackabox/statamic-plausible-analytics 1.1.0
duncanmcclean commented 2 years ago

As you've noticed, Simple Commerce won't calculate shipping costs until you actually have a shipping method selected.

I think if we were to introduce this, we'd need to make it an opt-in feature or add it into a breaking release as it may not be the behaviour that everyone would expect.

To get around this in the meantime, you could potentially listen for the OrderSaved event emitted by Simple Commerce and if the order doesn't have a shipping_method set, you can set it to the default one. Here's an example of what that listener may look like:

public function handle(OrderSaved $event)
{
    if (! $event->order->has('shipping_method') {
        $event->order->set('shipping_method', YourDefaultShippingMethod::class);
    }
}
steffenschmidt commented 2 years ago

As you've noticed, Simple Commerce won't calculate shipping costs until you actually have a shipping method selected.

I think if we were to introduce this, we'd need to make it an opt-in feature or add it into a breaking release as it may not be the behaviour that everyone would expect.

Ok understood and it would be ok for me if you won‘t do it. Otherwise instead of a breaking release it could be configurable: Only if a default value is set than it calculates the grant total with the default shipping costs.

To get around this in the meantime, you could potentially listen for the OrderSaved event emitted by Simple Commerce and if the order doesn't have a shipping_method set, you can set it to the default one. Here's an example of what that listener may look like:

Thanks and I will try this for my current solution.

github-actions[bot] commented 2 years ago

Released as part of v2.4.0-beta.3.

duncanmcclean commented 2 years ago

I've added the ability to configure a 'default shipping method' to the next version of Simple Commerce, v2.4. It's included as part of the latest beta release. Learn more about upgrading to the v2.4 beta.

My hope is for v2.4 to be out at the end of the month/start of next month.

github-actions[bot] commented 2 years ago

Released as part of v2.4.0.