|
@@ -15,6 +15,7 @@ use Webkul\BagistoApi\Facades\TokenHeaderFacade;
|
|
|
use Webkul\CartRule\Repositories\CartRuleCouponRepository;
|
|
use Webkul\CartRule\Repositories\CartRuleCouponRepository;
|
|
|
use Webkul\Checkout\Facades\Cart;
|
|
use Webkul\Checkout\Facades\Cart;
|
|
|
use Webkul\Shipping\Facades\Shipping;
|
|
use Webkul\Shipping\Facades\Shipping;
|
|
|
|
|
+use Longyi\Gift\Services\GiftCardService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* GraphQL processor for the SaveCheckoutCart mutation.
|
|
* GraphQL processor for the SaveCheckoutCart mutation.
|
|
@@ -32,6 +33,7 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
|
|
|
|
|
public function __construct(
|
|
public function __construct(
|
|
|
protected CartRuleCouponRepository $cartRuleCouponRepository,
|
|
protected CartRuleCouponRepository $cartRuleCouponRepository,
|
|
|
|
|
+ protected GiftCardService $giftCardService,
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -71,6 +73,10 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
$this->applyCoupon((string) $data->couponCode);
|
|
$this->applyCoupon((string) $data->couponCode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($this->shouldUpdate($data->giftCardNumber)) {
|
|
|
|
|
+ $this->applyGiftCard((string) $data->giftCardNumber);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Cart::collectTotals();
|
|
Cart::collectTotals();
|
|
|
} catch (OperationFailedException $e) {
|
|
} catch (OperationFailedException $e) {
|
|
|
throw $e;
|
|
throw $e;
|
|
@@ -161,4 +167,25 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
throw new OperationFailedException(trans('shop::app.checkout.coupon.error'));
|
|
throw new OperationFailedException(trans('shop::app.checkout.coupon.error'));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Apply or remove a gift card. An empty string removes the active gift card.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function applyGiftCard(string $code): void
|
|
|
|
|
+ {
|
|
|
|
|
+ // GiftController::activateGiftCard(); // destroyGiftCard
|
|
|
|
|
+
|
|
|
|
|
+ $code = trim($code);
|
|
|
|
|
+
|
|
|
|
|
+ if ($code === '') {
|
|
|
|
|
+ $this->giftCardService->remove();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (Cart::getCart()?->giftcard_number === $code) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->giftCardService->activate($code);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|