Skip to content

Commit

Permalink
Merge branch 'stable' into fix/shopbuilder_faker_data
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdausch authored Nov 9, 2020
2 parents e6653a5 + ca17625 commit f92cb04
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
3 changes: 3 additions & 0 deletions resources/lang/en/Debug.properties
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ OrderService_orderValidationError = "Error while create new order."
OrderService_placeOrder = "New order created."
OrderService_returnStatusNotFound = "Status for new return orders does not exist. Created return order with status 9.0"

; OrderStatusService
OrderStatusService_getOrderStatus = "Cannot load status with given id."

; PlaceOrderController
PlaceOrderController_cannotCompleteOrder = "Cannot complete checkout process: An error occurred after creating the order."
PlaceOrderController_cannotPlaceOrder = "Cannot place order."
Expand Down
81 changes: 43 additions & 38 deletions src/Services/OrderStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,70 +32,75 @@ class OrderStatusService
* @param OrderStatusRepositoryContract $orderStatusRepo
* @param StatusHistoryRepositoryContract $statusHistoryRepo
*/
public function __construct(AuthHelper $authHelper, OrderStatusRepositoryContract $orderStatusRepo, StatusHistoryRepositoryContract $statusHistoryRepo)
{
public function __construct(
AuthHelper $authHelper,
OrderStatusRepositoryContract $orderStatusRepo,
StatusHistoryRepositoryContract $statusHistoryRepo
) {
$this->authHelper = $authHelper;
$this->orderStatusRepo = $orderStatusRepo;
$this->statusHistoryRepo = $statusHistoryRepo;
}

/**
* @param int $orderId
* @param float $orderStatusId
* @return mixed
*/
public function getOrderStatus($orderId, $orderStatusId)
{
$lang = Utils::getLang();
$orderStatusRepo = $this->orderStatusRepo;
$statusHistoryRepo = $this->statusHistoryRepo;
$logger = $this->getLogger(__CLASS__);
$lang = Utils::getLang();
$orderStatusRepo = $this->orderStatusRepo;
$statusHistoryRepo = $this->statusHistoryRepo;
$logger = $this->getLogger(__CLASS__)->addReference('orderId', $orderId);

$orderStatus = $this->authHelper->processUnguarded( function() use ($orderId, $orderStatusId, $lang, $orderStatusRepo, $statusHistoryRepo, $logger)
{
$orderStatus = $this->authHelper->processUnguarded(function () use (
$orderId,
$orderStatusId,
$lang,
$orderStatusRepo,
$statusHistoryRepo,
$logger
) {
$statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId);
$orderStatus = $orderStatusRepo->get($orderStatusId);
if ( !is_null($orderStatus) && $orderStatus->isFrontendVisible )
{
return str_replace('['.$orderStatus->statusId.']', '', $orderStatus->names->get($lang));
}
elseif( !is_null($orderStatus) )
{
if (!is_null($orderStatus) && $orderStatus->isFrontendVisible) {
return str_replace('[' . $orderStatus->statusId . ']', '', $orderStatus->names->get($lang));
} elseif (!is_null($orderStatus)) {
$statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId);
if(count($statusHistory))
{
if (count($statusHistory)) {
$statusHistoryNew = [];
foreach($statusHistory as $entryKey => $entry)
{
try
{
$statusHistoryNew[$entryKey] = $orderStatusRepo->get($entry->statusId);
}catch(\Exception $e)
{
$logger->error("IO::Debug.OrderStatusService_getOrderSatus", [
'code' => $e->getCode(),
'message' => $e->getMessage()
]);
foreach ($statusHistory as $entryKey => $entry) {
// status with 0 means the creation of an order is not completed, caused by an error
if ($entry->statusId > 0) {
try {
$statusHistoryNew[$entryKey] = $orderStatusRepo->get($entry->statusId);
} catch (\Exception $e) {
$logger->error("IO::Debug.OrderStatusService_getOrderStatus", [
'code' => $e->getCode(),
'message' => $e->getMessage(),
'entryKey' => $entryKey
]);

}
}
}

if(count($statusHistoryNew))
{
for($i = count($statusHistoryNew)-1; $i >= 0; $i--)
{
if (count($statusHistoryNew)) {
for ($i = count($statusHistoryNew) - 1; $i >= 0; $i--) {
$statusEntry = $statusHistoryNew[$i];
if($statusEntry instanceof OrderStatus && $statusEntry->statusId < $orderStatusId && $statusEntry->isFrontendVisible)
{
return str_replace('['.$statusEntry->statusId.']', '', $statusEntry->names->get($lang));
if ($statusEntry instanceof OrderStatus && $statusEntry->statusId < $orderStatusId && $statusEntry->isFrontendVisible) {
return str_replace('[' . $statusEntry->statusId . ']', '',
$statusEntry->names->get($lang));
}
}
}
}
}

return '';
});

return $orderStatus;
}
}
}

0 comments on commit f92cb04

Please sign in to comment.