¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -5,6 +5,8 @@ namespace Modules\Order\Entities;
use Modules\Support\Money;
use Modules\Support\Eloquent\Model;
use Modules\Product\Entities\Product;
use Illuminate\Database\Eloquent\Collection;
class OrderProduct extends Model
{
@@ -20,7 +22,7 @@ class OrderProduct extends Model
*
* @var array
*/
protected $with = ['product', 'options'];
protected $with = ['product', 'options', 'variations'];
/**
* The attributes that aren't mass assignable.
@@ -29,16 +31,25 @@ class OrderProduct extends Model
*/
protected $guarded = [];
public function url()
{
return route('products.show', ['slug' => $this->product->slug]);
}
public function hasAnyOption()
{
return $this->options->isNotEmpty();
}
public function hasAnyVariation()
{
return $this->variations->isNotEmpty();
}
/**
* Determine if order product has been deleted.
*
@@ -49,10 +60,40 @@ class OrderProduct extends Model
return $this->product->trashed();
}
/**
* Store order product's variations.
*
* @param Collection $variations
*
* @return void
*/
public function storeVariations($variations)
{
$variations->each(function ($variation) {
$orderProductVariation = $this->variations()->create([
'order_product_id' => $this->id,
'variation_id' => $variation->id,
'type' => $variation->type,
'value' => $variation->values->first()->label,
]);
$orderProductVariation->storeValues($variation->values);
});
}
public function variations()
{
return $this->hasMany(OrderProductVariation::class);
}
/**
* Store order product's options.
*
* @param \Illuminate\Database\Eloquent\Collection $options
* @param Collection $options
*
* @return void
*/
public function storeOptions($options)
@@ -68,6 +109,13 @@ class OrderProduct extends Model
});
}
public function options()
{
return $this->hasMany(OrderProductOption::class);
}
public function product()
{
return $this->belongsTo(Product::class)
@@ -75,10 +123,6 @@ class OrderProduct extends Model
->withTrashed();
}
public function options()
{
return $this->hasMany(OrderProductOption::class);
}
/**
* Get the order product's name.
@@ -90,6 +134,7 @@ class OrderProduct extends Model
return $this->product->name;
}
/**
* Get the order product's slug.
*
@@ -100,13 +145,26 @@ class OrderProduct extends Model
return $this->product->slug;
}
public function getUnitPriceAttribute($unitPrice)
{
return Money::inDefaultCurrency($unitPrice);
}
public function getLineTotalAttribute($total)
{
return Money::inDefaultCurrency($total);
}
/**
* Get the order product's SKU.
*
* @return string
*/
public function getSkuAttribute()
{
return $this->product_variant ? $this->product_variant->sku : $this->product->sku;
}
}