llp před 5 dny
rodič
revize
e8a0fe8342

+ 1 - 1
packages/Longyi/Member/src/Listeners/MemberHandler.php

@@ -27,7 +27,7 @@ class MemberHandler
     public function applyMemberDiscount($cart)
     {
 
-        if (!$cart || !auth()->guard('customer')->check()) {
+        if (!$cart || !$cart->customer_id) {
             return;
         }
         if ($cart->vip_plus_amount <= 0) {

+ 6 - 2
packages/Longyi/Member/src/Listeners/VipDiscountHandler.php

@@ -3,6 +3,7 @@
 namespace Longyi\Member\Listeners;
 
 use Carbon\Carbon;
+use Webkul\Customer\Models\Customer;
 
 class VipDiscountHandler
 {
@@ -16,11 +17,14 @@ class VipDiscountHandler
      */
     public function applyVipDiscount($cart)
     {
-        if (!$cart || !auth()->guard('customer')->check()) {
+        if (!$cart || !$cart->customer_id) {
             return;
         }
         $isVip = false;
-        $customer = auth()->guard('customer')->user();
+        $customer = Customer::find($cart->customer_id);
+        if (!$customer) {
+            return;
+        }
         if ($cart->vip_plus_amount > 0 ||  $this->isValidVip($customer)) {
             $isVip = true;
         }

+ 14 - 0
packages/Webkul/BagistoApi/src/Dto/CartData.php

@@ -130,6 +130,10 @@ class CartData
     #[ApiProperty(description: 'Formatted VIP member discount amount')]
     public ?string $formattedVipPlusAmount = null;
 
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Whether the current customer is a VIP member')]
+    public ?bool $isVip = null;
+
     #[Groups(['query', 'mutation'])]
     public ?bool $success = null;
 
@@ -313,6 +317,16 @@ class CartData
         $data->baseVipPlusAmount = (float) ($cart->base_vip_plus_amount ?? 0);
         $data->formattedVipPlusAmount = core()->currency($cart->vip_plus_amount ?? 0);
 
+        // VIP status
+        $data->isVip = false;
+        if ($cart->customer_id) {
+            $customer = \Webkul\Customer\Models\Customer::find($cart->customer_id);
+            if ($customer && $customer->vip_expire_date) {
+                $expireDate = \Carbon\Carbon::parse($customer->vip_expire_date);
+                $data->isVip = !$expireDate->isPast();
+            }
+        }
+
         if ($cart->billing_address) {
             $data->billingAddress = [
                 'id'        => $cart->billing_address->id,

+ 2 - 0
packages/Webkul/BagistoApi/src/Resources/config/serializer/CartData.yaml

@@ -79,6 +79,8 @@ Webkul\BagistoApi\Dto\CartData:
       type: float
     formattedVipPlusAmount:
       type: string
+    isVip:
+      type: bool
     isGuest:
       type: bool
     itemsQty: