feat: Enhance product support in Cart and OrderItem models
- Added new fields 'billing_cycle' and 'product_pricing_id' to Cart and OrderItem models. - Updated product retrieval logic to support both new and legacy systems. - Introduced relationships for Product and ProductPricings in Cart and OrderItem models. - Created migration to add new fields to the carts and order_item tables. - Updated frontend service index to handle new pricing structure and billing cycles. - Improved UI components for better user experience in product selection and pricing display. - Refactored action buttons in various views for consistency and improved styling.
This commit is contained in:
@@ -16,14 +16,52 @@ class Cart extends Model
|
||||
'price',
|
||||
'quantity',
|
||||
'months',
|
||||
'billing_cycle', // Add new field for billing cycle
|
||||
'product_pricing_id', // Add new field to link to ProductPricings
|
||||
];
|
||||
|
||||
/**
|
||||
* Get product - support both new and legacy system
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
// New flow: Check if product exists in Product table first
|
||||
if ($this->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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user