duncanmcclean / simple-commerce

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

Default shipping method not found after upgrade v6 #1019

Closed sstottelaar closed 7 months ago

sstottelaar commented 7 months ago

Description

When upgrading from v5 to v6 the default shipping method selection stopped working. My code that defines the default shipping method is this:

'sites' => [
        'default' => [
            'currency' => 'EUR',

            'shipping' => [
                'default_method' => 'mailbox_shipping',

                'methods' => [
                    \App\ShippingMethods\MailboxShipping::class => [],
                    \App\ShippingMethods\ParcelShipping::class => [],
                ],
            ],
        ],
    ],

And when I open up the cart, i get this error:

image

After some digging, I found this piece of code:

class ShippingCalculator
{
    public function handle(Order $order, Closure $next)
    {
        $shippingMethod = $order->get('shipping_method');
        $defaultShippingMethod = config('simple-commerce.sites.'.Site::current()->handle().'.shipping.default_method');

        if (! $shippingMethod && ! $defaultShippingMethod) {
            return $next($order);
        }

        $order->shippingTotal(
            Shipping::site(Site::current()->handle())
                ->use($defaultShippingMethod::handle())
                ->calculateCost($order)
        );

        return $next($order);
    }
}

Removing the ::handle() from ->use($defaultShippingMethod::handle()) fixed the issue for me, because the value of $defaultShippingMethod declared earlier is already a handle.

Steps to reproduce

  1. Define default_method with a handle
  2. Go to cart
  3. Get error 'Class "mailbox_shipping" not found where mailbox_shipping is the handle I used

Environment

Environment Application Name: Op Adventuur Laravel Version: 10.44.0 PHP Version: 8.2.16 Composer Version: 2.7.1 Environment: local Debug Mode: ENABLED URL: ndl3nw4ehg.sharedwithexpose.com Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: statamic Database: sqlite Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: EUR Gateways: Mollie Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EntryCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EntryOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Mailbox Shipping, parcel_shipping Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine

Statamic Addons: 4 Antlers: runtime Sites: 1 Stache Watcher: Enabled Static Caching: Disabled Version: 4.49.0 PRO

Statamic Addons aerni/font-awesome: 2.0.0 duncanmcclean/simple-commerce: 6.0.7 mattrothenberg/statamic-mapbox-address: 0.7.4 withcandour/aardvark-seo: 3.0.1

❯ php please support:details

Environment Application Name: Op Adventuur Laravel Version: 10.44.0 PHP Version: 8.2.16 Composer Version: 2.7.1 Environment: local Debug Mode: ENABLED URL: ndl3nw4ehg.sharedwithexpose.com Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: statamic Database: sqlite Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: EUR Gateways: Mollie Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EntryCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EntryOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: mailbox_shipping, parcel_shipping Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine

Statamic Addons: 4 Antlers: runtime Sites: 1 Stache Watcher: Enabled Static Caching: Disabled Version: 4.49.0 PRO

Statamic Addons aerni/font-awesome: 2.0.0 duncanmcclean/simple-commerce: 6.0.7 mattrothenberg/statamic-mapbox-address: 0.7.4 withcandour/aardvark-seo: 3.0.1

github-actions[bot] commented 7 months ago

Released as part of v6.0.8.

sstottelaar commented 7 months ago

Thanks a lot @duncanmcclean!