Skip to content

Commit

Permalink
fix shipping driver issue
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Apr 25, 2021
1 parent 5cec383 commit 3599405
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/bazar.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*/

'gateway' => [
'default' => 'transfer',
'default' => env('BAZAR_GATEWAY_DRIVER', 'transfer'),
'drivers' => [
'cash' => [],
'manual' => [],
Expand All @@ -90,7 +90,7 @@
*/

'shipping' => [
'default' => 'local-pickup',
'default' => env('BAZAR_SHIPPING_DRIVER', 'local-pickup'),
'drivers' => [
'local-pickup' => [],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up(): void
$table->id();
$table->foreignId('order_id')->constrained('bazar_orders')->cascadeOnDelete();
$table->string('key')->nullable()->unique();
$table->string('driver')->nullable();
$table->string('driver');
$table->string('type');
$table->unsignedDecimal('amount');
$table->timestamp('completed_at')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up(): void
Schema::create('bazar_shippings', static function (Blueprint $table): void {
$table->id();
$table->uuidMorphs('shippable');
$table->string('driver')->default('local-pickup');
$table->string('driver');
$table->unsignedDecimal('cost')->default(0);
$table->unsignedDecimal('tax')->default(0);
$table->timestamps();
Expand Down
5 changes: 4 additions & 1 deletion src/Concerns/InteractsWithItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Bazar\Models\Product;
use Bazar\Models\Shipping;
use Bazar\Models\User;
use Bazar\Support\Facades\Shipping as ShippingManager;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
Expand Down Expand Up @@ -66,7 +67,9 @@ public function products(): MorphToMany
*/
public function shipping(): MorphOne
{
return $this->morphOne(Shipping::getProxiedClass(), 'shippable')->withDefault();
return $this->morphOne(Shipping::getProxiedClass(), 'shippable')->withDefault([
'driver' => ShippingManager::getDefaultDriver(),
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function create(): Response
'countries' => Countries::all(),
'currencies' => Bazar::currencies(),
'statuses' => Order::proxy()::statuses(),
'drivers' => Collection::make(Shipping::enabled())->map->name(),
'drivers' => Collection::make(Shipping::enabled())->map->name()->flip(),
]);
}

Expand Down
13 changes: 12 additions & 1 deletion src/Models/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Shipping extends Model implements Contract
protected $attributes = [
'tax' => 0,
'cost' => 0,
'driver' => 'local-pickup',
];

/**
Expand Down Expand Up @@ -70,6 +69,18 @@ class Shipping extends Model implements Contract
*/
protected $table = 'bazar_shippings';

/**
* The "booted" method of the model.
*
* @return void
*/
protected static function booted(): void
{
static::creating(static function (self $shipping): void {
$shipping->driver = $shipping->driver ?: Manager::getDefaultDriver();
});
}

/**
* Get the proxied contract.
*
Expand Down

0 comments on commit 3599405

Please sign in to comment.