Skip to content

Commit

Permalink
Allow to import old orders by console command
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrzyzewski authored and cieslix committed Jun 19, 2020
1 parent 025a736 commit b50ce32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Model/AbstractOrderImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protected function tryToProcessOrder($checkoutFormId)
{
try {
$checkoutForm = $this->checkoutFormRepository->get($checkoutFormId);
if ($this->processor->processOrder($checkoutForm)) {
if ($this->processor->validateCheckoutFormBoughtAtDate($checkoutForm)) {
$this->processor->processOrder($checkoutForm);
$this->successIds[] = $checkoutFormId;
} else {
$this->skippedIds[] = $checkoutFormId;
Expand Down
11 changes: 2 additions & 9 deletions Model/OrderImporter/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,10 @@ public function __construct(

/**
* @param CheckoutFormInterface $checkoutForm
* @return bool
* @throws \Exception
*/
public function processOrder(CheckoutFormInterface $checkoutForm): bool
public function processOrder(CheckoutFormInterface $checkoutForm): void
{
if (!$this->validateCheckoutFormBoughtAtDate($checkoutForm)) {
return false;
}

$connection = $this->resource->getConnection();
try {
$connection->beginTransaction();
Expand All @@ -113,8 +108,6 @@ public function processOrder(CheckoutFormInterface $checkoutForm): bool
}

$connection->commit();
return true;

} catch (\Exception $e) {
$connection->rollBack();
$this->addOrderWithErrorToTable($checkoutForm, $e);
Expand Down Expand Up @@ -218,7 +211,7 @@ private function removeErrorLogIfExist(CheckoutFormInterface $checkoutForm): voi
* @param CheckoutFormInterface $checkoutForm
* @return bool
*/
private function validateCheckoutFormBoughtAtDate(CheckoutFormInterface $checkoutForm): bool
public function validateCheckoutFormBoughtAtDate(CheckoutFormInterface $checkoutForm): bool
{
foreach ($checkoutForm->getLineItems() as $lineItem) {
if ($lineItem->getBoughtAt() < $this->configuration->getInitializationTime()) {
Expand Down
10 changes: 1 addition & 9 deletions Model/OrderImporter/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getShippingMethodCode(CheckoutFormInterface $checkoutForm)
$methodName = $checkoutForm->getDelivery()->getMethod()->getId();

if ($methodName == '') {
return $this->getDefaultShippingMethodCode();
return $this->getDefaultMethodCode();
}

if (!isset($this->shippingCodes[$methodName])) {
Expand All @@ -62,14 +62,6 @@ public function getShippingMethodCode(CheckoutFormInterface $checkoutForm)
return $this->shippingCodes[$methodName];
}

/**
* @return string
*/
public function getDefaultShippingMethodCode()
{
return self::DEFAULT_SHIPPING_METHOD;
}

/**
* @param string $methodId
* @return string
Expand Down

0 comments on commit b50ce32

Please sign in to comment.