map(function ($rate) { return core()->currency($rate ?? 0); }); return [ 'id' => $this->id, 'is_guest' => $this->is_guest, 'customer_id' => $this->customer_id, 'items_count' => $this->items_count, 'items_qty' => $this->items_qty, 'applied_taxes' => $taxes, 'tax_total' => $this->tax_total, 'formatted_tax_total' => core()->formatPrice($this->tax_total), 'sub_total_incl_tax' => $this->sub_total_incl_tax, 'sub_total' => $this->sub_total, 'formatted_sub_total_incl_tax' => core()->formatPrice($this->sub_total_incl_tax), 'formatted_sub_total' => core()->formatPrice($this->sub_total), 'coupon_code' => $this->coupon_code, 'discount_amount' => $this->discount_amount, 'formatted_discount_amount' => core()->formatPrice($this->discount_amount), 'shipping_method' => $this->shipping_method, 'shipping_amount' => $this->shipping_amount, 'formatted_shipping_amount' => core()->formatPrice($this->shipping_amount), 'shipping_amount_incl_tax' => $this->shipping_amount_incl_tax, 'formatted_shipping_amount_incl_tax' => core()->formatPrice($this->shipping_amount_incl_tax), 'grand_total' => $this->grand_total, 'formatted_grand_total' => core()->formatPrice($this->grand_total), 'items' => CartItemResource::collection($this->items), 'billing_address' => new AddressResource($this->billing_address), 'shipping_address' => new AddressResource($this->shipping_address), 'have_stockable_items' => $this->haveStockableItems(), 'payment_method' => $this->payment?->method, 'payment_method_title' => core()->getConfigData('sales.payment_methods.'.$this->payment?->method.'.title'), 'vip_status' => $this->getVipStatus(), $this->mergeWhen($this->giftcard_number, [ 'giftcard_number' => $this->giftcard_number, 'giftcard_amount' => $this->giftcard_amount, 'base_giftcard_amount' => $this->base_giftcard_amount, 'formatted_giftcard_amount' => core()->formatPrice($this->giftcard_amount), 'remaining_giftcard_amount' => $this->remaining_giftcard_amount, 'formatted_remaining_giftcard_amount' => core()->formatPrice($this->remaining_giftcard_amount), ]), $this->mergeWhen($this->vip_plus_amount && $this->vip_plus_amount > 0, [ 'vip_plus_amount' => $this->vip_plus_amount, 'base_vip_plus_amount' => $this->base_vip_plus_amount, 'formatted_vip_plus_amount' => core()->formatPrice($this->vip_plus_amount), ]), $this->mergeWhen($this->vip_discount_amount && $this->vip_discount_amount > 0, [ 'vip_discount_amount' => $this->vip_discount_amount, 'base_vip_discount_amount' => $this->base_vip_discount_amount, 'formatted_vip_discount_amount' => core()->formatPrice($this->vip_discount_amount), ]), ]; } /** * Get VIP status for current customer. * * @return array */ protected function getVipStatus(): array { if (!auth()->guard('customer')->check()) { return [ 'is_vip' => false, 'vip_expire_date' => null, 'days_remaining' => 0, 'can_show_discount' => true, ]; } $customer = auth()->guard('customer')->user(); if (!$customer->vip_expire_date) { return [ 'is_vip' => false, 'vip_expire_date' => null, 'days_remaining' => 0, 'can_show_discount' => true, ]; } $expireDate = Carbon::parse($customer->vip_expire_date); $isExpired = $expireDate->isPast(); $daysRemaining = $isExpired ? 0 : now()->diffInDays($expireDate, false); return [ 'is_vip' => !$isExpired, 'vip_expire_date' => $customer->vip_expire_date, 'days_remaining' => $daysRemaining, 'can_show_discount' => $isExpired, ]; } }