Skip to content

Commit 70c65c7

Browse files
Merge pull request #1684 from buckaroo-it/BTI-1214-Magento-2-Review-and-improve-Magento-2-plugin-code-quality-through-refactoring
Bti 1214 magento 2 review and improve magento 2 plugin code quality through refactoring
2 parents 8e91490 + be8d82f commit 70c65c7

12 files changed

Lines changed: 131 additions & 44 deletions

File tree

Controller/Adminhtml/PayLink/Index.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public function execute(): ResultInterface
108108
$payment = $order->getPayment();
109109
$currentPayment = $payment->getMethod();
110110
$payment->setMethod('buckaroo_magento2_payperemail');
111-
$payment->save();
112111
$order->save();
113112

114113
try {
@@ -132,7 +131,6 @@ public function execute(): ResultInterface
132131
} finally {
133132
$payment = $order->getPayment();
134133
$payment->setMethod($currentPayment);
135-
$payment->save();
136134
$order->save();
137135
}
138136

Model/Giftcard/Response/Giftcard.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ protected function cancelOrder()
340340
$this->orderManagement->cancel($order->getEntityId());
341341
$order->addCommentToStatusHistory($this->getErrorMessage())
342342
->setIsCustomerNotified(false)
343-
->setEntityName('invoice')
344343
->save();
345344
$this->rollbackAllPartialPayments($order);
346345
}

Model/Push/DefaultProcessor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,7 @@ private function reactivateCanceledOrder(): bool
903903
));
904904
}
905905

906-
// 7. Save payment and order changes
907-
$this->payment->save();
906+
// 7. Save order changes (payment is persisted by the order save cascade)
908907
$this->order->save();
909908

910909
$this->logger->addDebug(sprintf(

Model/Push/GroupTransactionPushProcessor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ protected function cancelOrder(string $reservedOrderId, string $historyComment =
271271

272272
$order->addCommentToStatusHistory(__($historyComment))
273273
->setIsCustomerNotified(false)
274-
->setEntityName('invoice')
275274
->save();
276275
}
277276
}

Model/Push/PayPerEmailProcessor.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ private function receivePushCheckPayLink(): void
226226
&& $this->pushTransactionType->getStatusKey() == 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS'
227227
) {
228228
$this->payment->setMethod('buckaroo_magento2_payperemail');
229-
$this->payment->save();
230229
$this->order->save();
231230
}
232231
}
@@ -332,7 +331,6 @@ private function saveActualPaymentMethodAndKeyForRefund(string $transactionKey,
332331
$transactionKey
333332
);
334333
$this->payment->setMethod('buckaroo_magento2_' . $transactionMethod);
335-
$this->payment->save();
336334
$this->order->save();
337335
}
338336

Model/Service/CancelOrder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function cancelPreviousPendingOrder(PaymentDataObjectInterface $paymentDO
7373
__('Canceled on browser back button')
7474
)
7575
->setIsCustomerNotified(false)
76-
->setEntityName('invoice')
7776
->save();
7877
} finally {
7978
if ($originalRequestOnVoid !== null) {

Observer/RestoreQuote.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ public function execute(Observer $observer): void
122122
}
123123

124124
if ($this->isCartKeepAlive($lastRealOrder)) {
125-
$this->prepareQuoteShippingAddress();
126-
127125
$isNewPending = $this->isNewPendingLastOrder($lastRealOrder, $payment);
128126
$canRestoreSpam = $this->canRestoreFailedFromSpam();
129127
$isCanceledWithRedirect = $this->isCanceledLastOrderWithRedirect($lastRealOrder, $payment);
@@ -239,23 +237,6 @@ private function isCartKeepAlive($lastRealOrder): bool
239237
return $this->accountConfig->getCartKeepAlive($lastRealOrder->getStore());
240238
}
241239

242-
/**
243-
* Prepare quote and shipping address if needed
244-
*/
245-
private function prepareQuoteShippingAddress(): void
246-
{
247-
if ($this->checkoutSession->getQuote()
248-
&& $this->checkoutSession->getQuote()->getId()
249-
&& ($quote = $this->quoteRepository->getActive($this->checkoutSession->getQuote()->getId()))
250-
) {
251-
if ($shippingAddress = $quote->getShippingAddress()) {
252-
if (!$shippingAddress->getShippingMethod()) {
253-
$shippingAddress->load($shippingAddress->getAddressId());
254-
}
255-
}
256-
}
257-
}
258-
259240
/**
260241
* Skip restore quote
261242
*

Plugin/ShippingMethodManagement.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@ public function beforeGet($cartId): void
106106
if ($quote && $quote->getId()) {
107107
$quote = $this->quoteRepository->getActive((int)$quote->getId());
108108
if ($shippingAddress = $quote->getShippingAddress()) {
109-
if (!$shippingAddress->getShippingMethod()) {
110-
$this->logger->addDebug(sprintf(
111-
'[SET_SHIPPING] | [Plugin] | [%s:%s] - SET SHIPPING ADDRESS - Ensures that '
112-
. 'the shipping address is loaded. | lastRealOrder: %s | shippingAddressId: %s',
113-
__METHOD__,
114-
__LINE__,
115-
$lastRealOrder->getIncrementId(),
116-
$shippingAddress->getAddressId()
117-
));
118-
$shippingAddress->load($shippingAddress->getAddressId());
119-
}
120109
$shippingAddress->setCollectShippingRates(true);
121110
}
122111
}

Service/Push/OrderRequestService.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ public function updateOrderStatus(
339339
$this->order->setStatus($newStatus);
340340
$this->order->addCommentToStatusHistory($description)
341341
->setIsCustomerNotified(false)
342-
->setEntityName('invoice')
343-
->setStatus($newStatus)
344-
->save();
342+
->setStatus($newStatus);
345343
$this->order->save();
346344
} else {
347345
$this->order->addCommentToStatusHistory($description, $newStatus);
@@ -351,7 +349,6 @@ public function updateOrderStatus(
351349
if ($dontSaveOrderUponSuccessPush) {
352350
$this->order->addCommentToStatusHistory($description)
353351
->setIsCustomerNotified(false)
354-
->setEntityName('invoice')
355352
->save();
356353
} else {
357354
$this->order->addCommentToStatusHistory($description);

Service/Sales/Quote/Recreate.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ public function recreateById($quoteId)
205205
$this->checkoutSession->unsRedirectUrl();
206206
$this->checkoutSession->unsLastQuoteId();
207207

208-
$quote->save();
209208
$this->cartRepository->save($quote);
210209

211210
return $quote;

0 commit comments

Comments
 (0)