|
@@ -21,6 +21,7 @@ use Webkul\Sales\Repositories\OrderRepository;
|
|
|
* CancelOrderProcessor — Handles the cancel order mutation
|
|
* CancelOrderProcessor — Handles the cancel order mutation
|
|
|
*
|
|
*
|
|
|
* Strategy:
|
|
* Strategy:
|
|
|
|
|
+ * - userManual=true: always cancel immediately (customer clicked cancel).
|
|
|
* - Guest cancel: cancel immediately + reactivate the original cart so
|
|
* - Guest cancel: cancel immediately + reactivate the original cart so
|
|
|
* the buyer can keep going if they change their mind.
|
|
* the buyer can keep going if they change their mind.
|
|
|
* - Customer with a real shipping address: keep order PENDING so the
|
|
* - Customer with a real shipping address: keep order PENDING so the
|
|
@@ -66,7 +67,11 @@ class CancelOrderProcessor implements ProcessorInterface
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $strategy = $this->paymentService->decideCancelStrategy($order, $isGuest);
|
|
|
|
|
|
|
+ $strategy = $this->paymentService->decideCancelStrategy(
|
|
|
|
|
+ $order,
|
|
|
|
|
+ $isGuest,
|
|
|
|
|
+ (bool) $input->userManual,
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
if ($strategy['action'] === 'keep_pending') {
|
|
if ($strategy['action'] === 'keep_pending') {
|
|
|
Event::dispatch('bagistoapi.order.cancel.kept-pending', [
|
|
Event::dispatch('bagistoapi.order.cancel.kept-pending', [
|
|
@@ -185,27 +190,44 @@ class CancelOrderProcessor implements ProcessorInterface
|
|
|
*/
|
|
*/
|
|
|
private function hydrateInputFromContext(CancelOrderInput $data, array $context): void
|
|
private function hydrateInputFromContext(CancelOrderInput $data, array $context): void
|
|
|
{
|
|
{
|
|
|
- if (! empty($data->orderId)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
$input = $context['args']['input'] ?? $context['args'] ?? null;
|
|
$input = $context['args']['input'] ?? $context['args'] ?? null;
|
|
|
|
|
|
|
|
- $orderId = $this->extractOrderId($input);
|
|
|
|
|
|
|
+ if (empty($data->orderId)) {
|
|
|
|
|
+ $orderId = $this->extractOrderId($input);
|
|
|
|
|
|
|
|
- if ($orderId === null) {
|
|
|
|
|
- $request = Request::instance();
|
|
|
|
|
|
|
+ if ($orderId === null) {
|
|
|
|
|
+ $request = Request::instance();
|
|
|
|
|
+
|
|
|
|
|
+ if ($request) {
|
|
|
|
|
+ $orderId = $this->extractOrderId($request->input('variables.input'))
|
|
|
|
|
+ ?? $this->extractOrderId($request->input('input'))
|
|
|
|
|
+ ?? $this->extractOrderId($request->input('extensions.variables.input'))
|
|
|
|
|
+ ?? $this->extractOrderId($request->all());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if ($request) {
|
|
|
|
|
- $orderId = $this->extractOrderId($request->input('variables.input'))
|
|
|
|
|
- ?? $this->extractOrderId($request->input('input'))
|
|
|
|
|
- ?? $this->extractOrderId($request->input('extensions.variables.input'))
|
|
|
|
|
- ?? $this->extractOrderId($request->all());
|
|
|
|
|
|
|
+ if ($orderId !== null) {
|
|
|
|
|
+ $data->orderId = $orderId;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ($orderId !== null) {
|
|
|
|
|
- $data->orderId = $orderId;
|
|
|
|
|
|
|
+ if ($data->userManual === null) {
|
|
|
|
|
+ $userManual = $this->extractUserManual($input);
|
|
|
|
|
+
|
|
|
|
|
+ if ($userManual === null) {
|
|
|
|
|
+ $request = Request::instance();
|
|
|
|
|
+
|
|
|
|
|
+ if ($request) {
|
|
|
|
|
+ $userManual = $this->extractUserManual($request->input('variables.input'))
|
|
|
|
|
+ ?? $this->extractUserManual($request->input('input'))
|
|
|
|
|
+ ?? $this->extractUserManual($request->input('extensions.variables.input'))
|
|
|
|
|
+ ?? $this->extractUserManual($request->all());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($userManual !== null) {
|
|
|
|
|
+ $data->userManual = $userManual;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -225,4 +247,25 @@ class CancelOrderProcessor implements ProcessorInterface
|
|
|
|
|
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private function extractUserManual(mixed $input): ?bool
|
|
|
|
|
+ {
|
|
|
|
|
+ if (is_array($input)) {
|
|
|
|
|
+ $value = $input['userManual'] ?? $input['user_manual'] ?? null;
|
|
|
|
|
+ } elseif (is_object($input)) {
|
|
|
|
|
+ $value = $input->userManual ?? $input->user_manual ?? null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($value === null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (is_bool($value)) {
|
|
|
|
|
+ return $value;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|