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;
|
2021-10-04 08:30:32 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Webkul\Checkout\Database\Factories\CartAddressFactory;
|
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-17 13:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* Class CartAddress
|
2021-10-04 08:30:32 +00:00
|
|
|
*
|
2020-04-17 13:54:02 +00:00
|
|
|
* @package Webkul\Checkout\Models
|
|
|
|
|
*
|
|
|
|
|
* @property integer $cart_id
|
2021-10-04 08:30:32 +00:00
|
|
|
* @property Cart $cart
|
2020-04-17 13:54:02 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2020-04-16 19:13:19 +00:00
|
|
|
class CartAddress extends Address implements CartAddressContract
|
2018-09-20 10:01:51 +00:00
|
|
|
{
|
2021-10-04 08:30:32 +00:00
|
|
|
use HasFactory;
|
|
|
|
|
|
2020-04-20 06:22:31 +00:00
|
|
|
public const ADDRESS_TYPE_SHIPPING = 'cart_shipping';
|
2021-10-04 08:30:32 +00:00
|
|
|
|
2020-04-20 06:22:31 +00:00
|
|
|
public const ADDRESS_TYPE_BILLING = 'cart_billing';
|
2018-09-26 04:21:14 +00:00
|
|
|
|
2020-04-17 09:09:59 +00:00
|
|
|
/**
|
|
|
|
|
* @var array default values
|
|
|
|
|
*/
|
|
|
|
|
protected $attributes = [
|
|
|
|
|
'address_type' => self::ADDRESS_TYPE_BILLING,
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-16 19:13:19 +00:00
|
|
|
/**
|
|
|
|
|
* The "booted" method of the model.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2021-10-04 08:30:32 +00:00
|
|
|
protected static function boot(): void
|
2020-04-16 19:13:19 +00:00
|
|
|
{
|
2020-04-17 09:09:59 +00:00
|
|
|
static::addGlobalScope('address_type', static function (Builder $builder) {
|
2020-04-16 19:13:19 +00:00
|
|
|
$builder->whereIn('address_type', [
|
|
|
|
|
self::ADDRESS_TYPE_BILLING,
|
2021-10-04 08:30:32 +00:00
|
|
|
self::ADDRESS_TYPE_SHIPPING,
|
2020-04-16 19:13:19 +00:00
|
|
|
]);
|
|
|
|
|
});
|
2020-04-17 13:54:02 +00:00
|
|
|
|
|
|
|
|
parent::boot();
|
2020-04-16 19:13:19 +00:00
|
|
|
}
|
2018-09-26 04:21:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the shipping rates for the cart address.
|
|
|
|
|
*/
|
2021-10-04 08:30:32 +00:00
|
|
|
public function shipping_rates(): HasMany
|
2018-09-26 04:21:14 +00:00
|
|
|
{
|
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
|
|
|
*/
|
2021-10-04 08:30:32 +00:00
|
|
|
public function cart(): BelongsTo
|
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
|
|
|
}
|
2021-10-04 08:30:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new factory instance for the model
|
|
|
|
|
*
|
|
|
|
|
* @return CartAddressFactory
|
|
|
|
|
*/
|
|
|
|
|
protected static function newFactory(): CartAddressFactory
|
|
|
|
|
{
|
|
|
|
|
return CartAddressFactory::new();
|
|
|
|
|
}
|
2018-09-26 04:21:14 +00:00
|
|
|
}
|