hasMany(CartItem::class)->whereNull('parent_id'); } public function all_items() { return $this->hasMany(CartItem::class); } /** * Get the addresses for the cart. */ public function addresses() { return $this->hasMany(CartAddress::class); } /** * Get the biling address for the cart. */ public function billing_address() { return $this->addresses()->where('address_type', 'billing'); } /** * Get billing address for the cart. */ public function getBillingAddressAttribute() { return $this->billing_address()->first(); } /** * Get the shipping address for the cart. */ public function shipping_address() { return $this->addresses()->where('address_type', 'shipping'); } /** * Get shipping address for the cart. */ 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'); } /** * Get all of the attributes for the attribute groups. */ public function selected_shipping_rate() { return $this->shipping_rates()->where('method', $this->shipping_method); } /** * Get all of the attributes for the attribute groups. */ public function getSelectedShippingRateAttribute() { return $this->selected_shipping_rate()->where('method', $this->shipping_method)->first(); } /** * Get the payment associated with the cart. */ public function payment() { return $this->hasOne(CartPayment::class); } }