From a8374545ea307a57eaab730b79f064e6a826a3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Sat, 28 Oct 2023 14:36:43 +0200 Subject: [PATCH] add uuid to order --- .../2020_01_01_000500_create_bazar_orders_table.php | 1 + src/Models/Order.php | 11 +++++++++++ src/Traits/InteractsWithItems.php | 10 ++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/database/migrations/2020_01_01_000500_create_bazar_orders_table.php b/database/migrations/2020_01_01_000500_create_bazar_orders_table.php index d2dbc74e..b8e34eb0 100644 --- a/database/migrations/2020_01_01_000500_create_bazar_orders_table.php +++ b/database/migrations/2020_01_01_000500_create_bazar_orders_table.php @@ -13,6 +13,7 @@ public function up(): void { Schema::create('bazar_orders', static function (Blueprint $table): void { $table->id(); + $table->uuid(); $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); $table->string('status'); $table->string('currency'); diff --git a/src/Models/Order.php b/src/Models/Order.php index 3fbbd128..09383665 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -12,6 +12,7 @@ use Cone\Root\Traits\InteractsWithProxy; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -24,6 +25,7 @@ class Order extends Model implements Contract { use Addressable; use HasFactory; + use HasUuids; use InteractsWithDiscounts; use InteractsWithItems; use InteractsWithProxy; @@ -121,6 +123,7 @@ public static function statuses(): array static::CANCELLED => __('Cancelled'), static::FAILED => __('Failed'), static::REFUNDED => __('Refunded'), + static::PARTIALLY_REFUNDED => __('Partially Refunded'), ]; } @@ -176,6 +179,14 @@ protected function statusName(): Attribute ); } + /** + * Get the columns that should receive a unique identifier. + */ + public function uniqueIds(): array + { + return ['uuid']; + } + /** * Create a payment transaction for the order. */ diff --git a/src/Traits/InteractsWithItems.php b/src/Traits/InteractsWithItems.php index d01e5ebe..8e99dbde 100644 --- a/src/Traits/InteractsWithItems.php +++ b/src/Traits/InteractsWithItems.php @@ -3,6 +3,7 @@ namespace Cone\Bazar\Traits; use Cone\Bazar\Bazar; +use Cone\Bazar\Interfaces\Inventoryable; use Cone\Bazar\Interfaces\LineItem; use Cone\Bazar\Models\Item; use Cone\Bazar\Models\Shipping; @@ -78,7 +79,9 @@ protected function lineItems(): Attribute { return new Attribute( get: function (): Collection { - return $this->items->merge([$this->shipping]); + return $this->items->when($this->needsShipping(), function (Collection $items): Collection { + return $items->merge([$this->shipping]); + }); } ); } @@ -160,7 +163,10 @@ protected function formattedTax(): Attribute */ public function needsShipping(): bool { - return true; + return $this->items->some(static function (Item $item): bool { + return $item->buyable instanceof Inventoryable + && $item->buyable->isVirtual(); + }); } /**