2018-09-20 10:01:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-28 12:54:26 +00:00
|
|
|
namespace Webkul\Checkout\Models;
|
2018-09-20 10:01:51 +00:00
|
|
|
|
2020-04-16 19:13:19 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2019-02-18 07:30:40 +00:00
|
|
|
use Webkul\Checkout\Contracts\CartAddress as CartAddressContract;
|
2020-04-16 19:13:19 +00:00
|
|
|
use Webkul\Core\Models\Address;
|
2018-09-20 10:01:51 +00:00
|
|
|
|
2020-04-16 19:13:19 +00:00
|
|
|
class CartAddress extends Address implements CartAddressContract
|
2018-09-20 10:01:51 +00:00
|
|
|
{
|
2020-04-16 19:13:19 +00:00
|
|
|
public const ADDRESS_TYPE_SHIPPING = 'cart_address_shipping';
|
|
|
|
|
public const ADDRESS_TYPE_BILLING = 'cart_address_billing';
|
2018-09-26 04:21:14 +00:00
|
|
|
|
2020-04-16 19:13:19 +00:00
|
|
|
/**
|
|
|
|
|
* The "booted" method of the model.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::addGlobalScope('address_type', function (Builder $builder) {
|
|
|
|
|
$builder->whereIn('address_type', [
|
|
|
|
|
self::ADDRESS_TYPE_BILLING,
|
|
|
|
|
self::ADDRESS_TYPE_SHIPPING
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-09-26 04:21:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the shipping rates for the cart address.
|
|
|
|
|
*/
|
|
|
|
|
public function shipping_rates()
|
|
|
|
|
{
|
2019-02-18 07:30:40 +00:00
|
|
|
return $this->hasMany(CartShippingRateProxy::modelClass());
|
2018-09-26 04:21:14 +00:00
|
|
|
}
|
2018-09-27 07:53:26 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-04-16 19:13:19 +00:00
|
|
|
* Get the cart record associated with the address.
|
2018-09-27 07:53:26 +00:00
|
|
|
*/
|
2020-04-16 19:13:19 +00:00
|
|
|
public function cart()
|
2018-09-27 07:53:26 +00:00
|
|
|
{
|
2020-04-16 19:13:19 +00:00
|
|
|
return $this->belongsTo(Cart::class);
|
2018-09-27 07:53:26 +00:00
|
|
|
}
|
2018-09-26 04:21:14 +00:00
|
|
|
}
|