From 7f11bae12818c643a344a076f421811a61e405a0 Mon Sep 17 00:00:00 2001
From: andrii-onufriichuk
<117644505+andrii-onufriichuk@users.noreply.github.com>
Date: Tue, 30 Jan 2024 17:28:21 +0200
Subject: [PATCH] Added mocking to order creation (#73)
* Added mocking to order creation
---
Plugin/Customer/DisableOrderCreation.php | 55 +++++++++++++++++++++++
Plugin/Guest/DisableOrderCreation.php | 56 ++++++++++++++++++++++++
etc/di.xml | 10 +++++
3 files changed, 121 insertions(+)
create mode 100644 Plugin/Customer/DisableOrderCreation.php
create mode 100644 Plugin/Guest/DisableOrderCreation.php
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"/>
+
+
+
+
+
+