product_id) { $product = Product::find($this->product_id); if ($product) { return $product; } } // Legacy flow: fallback to old system based on type_product return match ($this->type_product) { 3 => $this->belongsTo(Hosting::class, 'product_id'), 4 => $this->belongsTo(VPS::class, 'product_id'), default => null, }; } /** * Relationship: Cart belongs to Product (new system) */ public function productNew() { return $this->belongsTo(Product::class, 'product_id'); } /** * Relationship: Cart belongs to Customer */ public function customer() { return $this->belongsTo(Customer::class, 'customer_id'); } /** * Relationship: Cart has pricing info */ public function pricing() { return $this->belongsTo(ProductPricings::class, 'product_pricing_id'); } /** * Relationship: Cart has many addons */ public function addons() { return $this->hasMany(CartAddon::class, 'cart_id'); } /** * Get total price including addons */ public function getTotalPriceAttribute() { $basePrice = $this->price * $this->quantity; $addonsPrice = $this->addons->sum('price'); return $basePrice + $addonsPrice; } }