|
@@ -5,6 +5,7 @@ namespace Webkul\BagistoApi\State;
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\Metadata\Operation;
|
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
|
use Illuminate\Support\Facades\Request;
|
|
use Illuminate\Support\Facades\Request;
|
|
|
|
|
+use Longyi\Gift\Models\GiftCards;
|
|
|
use Webkul\BagistoApi\Dto\CartData;
|
|
use Webkul\BagistoApi\Dto\CartData;
|
|
|
use Webkul\BagistoApi\Dto\SaveCheckoutCartInput;
|
|
use Webkul\BagistoApi\Dto\SaveCheckoutCartInput;
|
|
|
use Webkul\BagistoApi\Exception\AuthenticationException;
|
|
use Webkul\BagistoApi\Exception\AuthenticationException;
|
|
@@ -16,6 +17,7 @@ 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;
|
|
use Longyi\Gift\Services\GiftCardService;
|
|
|
|
|
+use Longyi\Member\Services\MemberDiscountService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* GraphQL processor for the SaveCheckoutCart mutation.
|
|
* GraphQL processor for the SaveCheckoutCart mutation.
|
|
@@ -34,6 +36,7 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
public function __construct(
|
|
public function __construct(
|
|
|
protected CartRuleCouponRepository $cartRuleCouponRepository,
|
|
protected CartRuleCouponRepository $cartRuleCouponRepository,
|
|
|
protected GiftCardService $giftCardService,
|
|
protected GiftCardService $giftCardService,
|
|
|
|
|
+ protected MemberDiscountService $memberDiscountService,
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -77,6 +80,10 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
$this->applyGiftCard((string) $data->giftCardNumber);
|
|
$this->applyGiftCard((string) $data->giftCardNumber);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($this->shouldUpdate($data->memberDiscount)) {
|
|
|
|
|
+ $this->applyMemberDiscount((string) $data->memberDiscount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Cart::collectTotals();
|
|
Cart::collectTotals();
|
|
|
} catch (OperationFailedException $e) {
|
|
} catch (OperationFailedException $e) {
|
|
|
throw $e;
|
|
throw $e;
|
|
@@ -173,8 +180,6 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
*/
|
|
*/
|
|
|
private function applyGiftCard(string $code): void
|
|
private function applyGiftCard(string $code): void
|
|
|
{
|
|
{
|
|
|
- // GiftController::activateGiftCard(); // destroyGiftCard
|
|
|
|
|
-
|
|
|
|
|
$code = trim($code);
|
|
$code = trim($code);
|
|
|
|
|
|
|
|
if ($code === '') {
|
|
if ($code === '') {
|
|
@@ -186,6 +191,35 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
|
|
|
if (Cart::getCart()?->giftcard_number === $code) {
|
|
if (Cart::getCart()?->giftcard_number === $code) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- $this->giftCardService->activate($code);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $customerId = Cart::getCart()?->customer_id;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $customerId) {
|
|
|
|
|
+ throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.customer-not-found'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->giftCardService->activate($code, $customerId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Apply or remove member discount. "1" applies, empty string removes.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function applyMemberDiscount(string $value): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $value = trim($value);
|
|
|
|
|
+
|
|
|
|
|
+ if ($value === '') {
|
|
|
|
|
+ $this->memberDiscountService->remove();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $customerId = Cart::getCart()?->customer_id;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $customerId) {
|
|
|
|
|
+ throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.customer-not-found'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->memberDiscountService->apply();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|