Skip to content

Commit

Permalink
add uuid to order
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 28, 2023
1 parent 9dec62b commit a837454
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 11 additions & 0 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,7 @@ class Order extends Model implements Contract
{
use Addressable;
use HasFactory;
use HasUuids;
use InteractsWithDiscounts;
use InteractsWithItems;
use InteractsWithProxy;
Expand Down Expand Up @@ -121,6 +123,7 @@ public static function statuses(): array
static::CANCELLED => __('Cancelled'),
static::FAILED => __('Failed'),
static::REFUNDED => __('Refunded'),
static::PARTIALLY_REFUNDED => __('Partially Refunded'),
];
}

Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 8 additions & 2 deletions src/Traits/InteractsWithItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
});
}
);
}
Expand Down Expand Up @@ -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();
});
}

/**
Expand Down

0 comments on commit a837454

Please sign in to comment.