refactor(catalog): Complete catalog refactor to simplify its data model and its querying.
source commits: refactor/catalog
This commit is contained in:
@@ -119,7 +119,7 @@ class Purchase extends Model
|
||||
|
||||
$cart = $this->relationLoaded('cart')
|
||||
? $this->getRelation('cart')
|
||||
: $this->cart()->with('items.buyable')->first();
|
||||
: $this->cart()->with(['items.catalogItem', 'items.variant'])->first();
|
||||
|
||||
if (! $cart) {
|
||||
return 0.0;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Domains\Purchase\Models;
|
||||
|
||||
use App\Domains\Catalog\Models\ProductVariant;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -10,8 +10,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'compra_id',
|
||||
'buyable_id',
|
||||
'buyable_type',
|
||||
'source_catalog_item_id',
|
||||
'source_variant_id',
|
||||
'image_attachment_id',
|
||||
'nombre',
|
||||
'descripcion',
|
||||
'slug',
|
||||
'item_nombre',
|
||||
'variant_attributes',
|
||||
'cantidad',
|
||||
'precio_unitario',
|
||||
'discount_total',
|
||||
@@ -28,8 +34,10 @@ class PurchaseItem extends Model
|
||||
{
|
||||
return [
|
||||
'compra_id' => 'integer',
|
||||
'buyable_id' => 'integer',
|
||||
'buyable_type' => 'string',
|
||||
'source_catalog_item_id' => 'integer',
|
||||
'source_variant_id' => 'integer',
|
||||
'image_attachment_id' => 'integer',
|
||||
'variant_attributes' => 'array',
|
||||
'cantidad' => 'integer',
|
||||
'precio_unitario' => 'decimal:2',
|
||||
'discount_total' => 'decimal:2',
|
||||
@@ -46,11 +54,9 @@ class PurchaseItem extends Model
|
||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
*/
|
||||
public function buyable()
|
||||
/** @return BelongsTo<Attachment, $this> */
|
||||
public function imageAttachment(): BelongsTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
return $this->belongsTo(Attachment::class, 'image_attachment_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user