conedevelopment / bazar

Bazar is an e-commerce package for Laravel applications.
https://root.conedevelopment.com
MIT License
427 stars 57 forks source link

Extending shipping with a new driver doesn't overwrite the default #148

Closed rowanfuchs closed 3 years ago

rowanfuchs commented 3 years ago

I'm a little lost in the functionality of the contracts and extension of them. I have the following shipping driver set up but it always defaults to local-pickup unless I hard code assigning a new carrier after the creation of a new cart. Am I missing something? How can I make sure it it enforces the default dhl of the config value shipping.default

Config:

'shipping' => [
    'default' => strtolower(env('BAZAR_SHIPPING_DRIVER', 'local-pickup')),
    'drivers' => [
        'local-pickup' => [],
        'dhl' => [],
    ],
],

Result of the default is: dhl

The boot of AppServiceProvider contains the extension of the Shipping facade

use Bazar\Support\Facades\Shipping;

public function boot()
{
    Shipping::extend('dhl', function ($app) {
        return new DHLDriver();
    });
}

The DHLDriver contains the following

<?php

namespace App\Drivers;

use Bazar\Contracts\Shippable;
use Bazar\Shipping\Driver;

class DHLDriver extends Driver
{
    public function calculate(Shippable $model): float
    {
        return 4.5;
    }
}
iamgergo commented 3 years ago

Well, this was a bug as it turned out. I've fixed this in v0.7.4.

From now new shipping instances should pick up the default driver.

Thanks for your feedback and your work, we really apreciate it!