WIP
This commit is contained in:
@@ -11,6 +11,10 @@ trait HasShipping
|
||||
*/
|
||||
public function shippingPrice(): int
|
||||
{
|
||||
if ($this->shippingMethod) {
|
||||
return intval($this->shipping_price) ?: $this->shippingMethod->price;
|
||||
}
|
||||
|
||||
return intval($this->shipping_price) ?: OrderShipping::priceFor($this->shipping_method);
|
||||
}
|
||||
|
||||
@@ -19,6 +23,10 @@ trait HasShipping
|
||||
*/
|
||||
public function formattedShippingMethod(): string
|
||||
{
|
||||
if ($this->shippingMethod) {
|
||||
return $this->shippingMethod->name;
|
||||
}
|
||||
|
||||
return OrderShipping::formattedShippingMethod($this->shipping_method);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use App\Models\Ecommerce\Product\Order\Shipping\OrderShippingMethod;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Order extends Model
|
||||
@@ -31,6 +32,7 @@ class Order extends Model
|
||||
'number',
|
||||
'status',
|
||||
'shipping_method',
|
||||
'shipping_method_id',
|
||||
'shipping_price',
|
||||
'payment_type_id',
|
||||
'notes',
|
||||
@@ -85,4 +87,12 @@ class Order extends Model
|
||||
{
|
||||
return $this->belongsTo(PaymentType::class, 'payment_type_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipping method
|
||||
*/
|
||||
public function shippingMethod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(OrderShippingMethod::class, 'shipping_method_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\Order\Shipping;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class OrderShippingMethod extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'order_shipping_methods';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'price',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
/**
|
||||
* Translatable fields
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $translatable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the options for generating the slug.
|
||||
*/
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom('name')
|
||||
->saveSlugsTo('slug');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user