sarga/packages/Webkul/Cart/src/Models/Cart.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2018-09-06 06:20:30 +00:00
<?php
namespace Webkul\Cart\Models;
2018-09-10 09:31:34 +00:00
use Illuminate\Database\Eloquent\Model;
use Webkul\Product\Models\Product;
2018-09-20 10:01:51 +00:00
use Webkul\Cart\Models\CartAddress;
2018-09-26 04:21:14 +00:00
use Webkul\Cart\Models\CartShippingRate;
2018-09-10 09:31:34 +00:00
class Cart extends Model
2018-09-06 06:20:30 +00:00
{
protected $table = 'cart';
2018-09-20 15:12:11 +00:00
protected $fillable = ['customer_id', 'session_id', 'channel_id', 'coupon_code', 'is_gift', 'global_currency_code', 'base_currency_code', 'store_currency_code', 'quote_currency_code', 'grand_total', 'base_grand_total', 'sub_total', 'base_sub_total', 'sub_total_with_discount', 'base_sub_total_with_discount', 'checkout_method', 'is_guest', 'customer_full_name', 'conversion_time'];
2018-09-06 06:20:30 +00:00
protected $hidden = ['coupon_code'];
2018-09-10 09:31:34 +00:00
public function items() {
return $this->hasMany('Webkul\Cart\Models\CartItem');
2018-09-10 09:31:34 +00:00
}
2018-09-20 10:01:51 +00:00
/**
* Get the addresses for the cart.
*/
public function addresses()
{
return $this->hasMany(CartAddress::class);
}
/**
2018-09-26 04:21:14 +00:00
* Get the biling address for the cart.
2018-09-20 10:01:51 +00:00
*/
2018-09-26 04:21:14 +00:00
public function biling_address()
2018-09-20 10:01:51 +00:00
{
2018-09-26 04:21:14 +00:00
return $this->addresses()->where('address_type', 'billing');
2018-09-20 10:01:51 +00:00
}
2018-09-26 04:21:14 +00:00
/**
* Get all of the attributes for the attribute groups.
*/
public function getBilingAddressAttribute()
{
return $this->biling_address()->first();
}
/**
* Get the shipping address for the cart.
*/
public function shipping_address()
{
return $this->addresses()->where('address_type', 'shipping');
}
/**
* Get all of the attributes for the attribute groups.
*/
public function getShippingAddressAttribute()
{
return $this->shipping_address()->first();
}
/**
* Get the shipping rates for the cart.
*/
public function shipping_rates()
{
return $this->hasManyThrough(CartShippingRate::class, CartAddress::class, 'cart_id', 'cart_address_id');
}
}