diff --git a/Plugin/Customer/DisableOrderCreation.php b/Plugin/Customer/DisableOrderCreation.php new file mode 100644 index 00000000..f8eb915f --- /dev/null +++ b/Plugin/Customer/DisableOrderCreation.php @@ -0,0 +1,55 @@ +cartRepository = $cartRepository; + } + + /** + * @param PaymentInformationManagementInterface $subject + * @param callable $proceed + * @param int $cartId + * @param PaymentInterface $paymentMethod + * @param AddressInterface|null $billingAddress + * @return int + * @throws NoSuchEntityException + */ + public function aroundSavePaymentInformationAndPlaceOrder( + PaymentInformationManagementInterface $subject, + callable $proceed, + $cartId, + PaymentInterface $paymentMethod, + AddressInterface $billingAddress = null + ): int { + // Return reserved order id if Rvvup Payment. + if (strpos($paymentMethod->getMethod(), Method::PAYMENT_TITLE_PREFIX) === 0) { + $cart = $this->cartRepository->get($cartId); + $id = $cart->getReservedOrderId(); + if (!$id) { + $cart->reserveOrderId(); + $this->cartRepository->save($cart); + $id = $cart->getReservedOrderId(); + } + return $id; + } + return $proceed($cartId, $paymentMethod, $billingAddress); + } +} diff --git a/Plugin/Guest/DisableOrderCreation.php b/Plugin/Guest/DisableOrderCreation.php new file mode 100644 index 00000000..a4cb9ede --- /dev/null +++ b/Plugin/Guest/DisableOrderCreation.php @@ -0,0 +1,56 @@ +cartRepository = $cartRepository; + } + + /** + * @param GuestPaymentInformationManagementInterface $subject + * @param callable $proceed + * @param string $cartId + * @param string $email + * @param PaymentInterface $paymentMethod + * @param AddressInterface|null $billingAddress + * @return int + * @throws NoSuchEntityException + */ + public function aroundSavePaymentInformationAndPlaceOrder( + GuestPaymentInformationManagementInterface $subject, + callable $proceed, + $cartId, + $email, + PaymentInterface $paymentMethod, + AddressInterface $billingAddress = null + ): int { + // Return reserved order id if Rvvup Payment. + if (strpos($paymentMethod->getMethod(), Method::PAYMENT_TITLE_PREFIX) === 0) { + $cart = $this->cartRepository->get($cartId); + $id = $cart->getReservedOrderId(); + if (!$id) { + $cart->reserveOrderId(); + $id = $cart->getReservedOrderId(); + $this->cartRepository->save($cart); + } + return $id; + } + return $proceed($cartId, $email, $paymentMethod, $billingAddress); + } +} diff --git a/etc/di.xml b/etc/di.xml index f93a5ce5..c4df2581 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -424,4 +424,14 @@ sortOrder="1"/> + + + + + +