Skip to content

Commit 4d109f5

Browse files
mstrzyzewskiMaksymilian Strzyżewski
andauthored
Fix order importer (#94)
-Log checkout form ID to allegro_orders_with_error table when checkout form does not exist Co-authored-by: Maksymilian Strzyżewski <m.strzyzewski@macopedia.pl>
1 parent fe90a85 commit 4d109f5

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Model/AbstractOrderImporter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Macopedia\Allegro\Logger\Logger;
99
use Macopedia\Allegro\Model\OrderImporter\Info;
1010
use Macopedia\Allegro\Model\OrderImporter\Processor;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112

1213
abstract class AbstractOrderImporter
1314
{
@@ -53,7 +54,12 @@ public function __construct(
5354
protected function tryToProcessOrder($checkoutFormId)
5455
{
5556
try {
56-
$checkoutForm = $this->checkoutFormRepository->get($checkoutFormId);
57+
try {
58+
$checkoutForm = $this->checkoutFormRepository->get($checkoutFormId);
59+
} catch (Api\ClientException | NoSuchEntityException $e) {
60+
$this->processor->addOrderWithErrorToTable($checkoutFormId, $e);
61+
throw $e;
62+
}
5763
if ($this->processor->validateCheckoutFormBoughtAtDate($checkoutForm)) {
5864
$this->processor->processOrder($checkoutForm);
5965
$this->successIds[] = $checkoutFormId;

Model/OrderImporter/Processor.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,17 @@ public function __construct(
9292
public function processOrder(CheckoutFormInterface $checkoutForm): void
9393
{
9494
$connection = $this->resource->getConnection();
95+
$checkoutFormId = $checkoutForm->getId();
9596
try {
9697
$connection->beginTransaction();
9798

9899
if ($checkoutForm->getStatus() === Status::ALLEGRO_READY_FOR_PROCESSING) {
99-
if (!$this->tryToGetOrder($checkoutForm->getId())) {
100-
$this->allegroReservation->compensateReservation($checkoutForm->getId());
100+
if (!$this->tryToGetOrder($checkoutFormId)) {
101+
$this->allegroReservation->compensateReservation($checkoutFormId);
101102
$this->tryCreateOrder($checkoutForm);
102103
}
103104
} elseif ($checkoutForm->getStatus() === Status::ALLEGRO_CANCELLED) {
104-
$this->allegroReservation->compensateReservation($checkoutForm->getId());
105+
$this->allegroReservation->compensateReservation($checkoutFormId);
105106
} else {
106107
$this->allegroReservation->placeReservation($checkoutForm);
107108
}
@@ -110,7 +111,7 @@ public function processOrder(CheckoutFormInterface $checkoutForm): void
110111
$connection->commit();
111112
} catch (\Exception $e) {
112113
$connection->rollBack();
113-
$this->addOrderWithErrorToTable($checkoutForm, $e);
114+
$this->addOrderWithErrorToTable($checkoutFormId, $e);
114115
throw $e;
115116
}
116117
}
@@ -129,14 +130,12 @@ protected function tryToGetOrder($id): ?OrderInterface
129130
}
130131

131132
/**
132-
* @param CheckoutFormInterface $checkoutForm
133+
* @param string $checkoutFormId
133134
* @param \Exception $e
134-
* @throws \Exception
135+
* @throws OrderProcessingException
135136
*/
136-
private function addOrderWithErrorToTable(CheckoutFormInterface $checkoutForm, \Exception $e): void
137+
public function addOrderWithErrorToTable(string $checkoutFormId, \Exception $e): void
137138
{
138-
$checkoutFormId = $checkoutForm->getId();
139-
140139
$date = $this->date->gmtDate();
141140

142141
try {

0 commit comments

Comments
 (0)