Skip to content

Commit

Permalink
Merge pull request #6000 from spryker/bugfix/cc-6256-zed-exception-on…
Browse files Browse the repository at this point in the history
…-clicking-actions-of-state-machine

CC-6256: Zed, Exception on clicking actions of state machine
  • Loading branch information
tamasnyulas authored Sep 11, 2019
2 parents 2231ffa + 2d47571 commit fecd046
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions src/Spryker/Zed/Oms/Communication/Controller/TriggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,13 @@ class TriggerController extends AbstractController
*/
public function triggerEventForOrderItemsAction(Request $request)
{
$idOrderItems = $request->query->get(static::REQUEST_PARAMETER_ITEMS);

/**
* Exists for Backward Compatibility reasons only.
*/
$idOrderItem = $request->query->get(static::REQUEST_PARAMETER_ID_SALES_ORDER_ITEM);
if ($idOrderItems === null && $idOrderItem !== null) {
$idOrderItems = [$idOrderItem];
$redirect = $request->query->get(static::REQUEST_PARAMETER_REDIRECT, static::ROUTE_REDIRECT_DEFAULT);
$idOrderItems = $this->getRequestIdSalesOrderItems($request);
if ($idOrderItems === []) {
return $this->redirectResponse($redirect);
}

$event = $request->query->get(static::REQUEST_PARAMETER_EVENT);
$redirect = $request->query->get(static::REQUEST_PARAMETER_REDIRECT, '/');

$this->getFacade()->triggerEventForOrderItems($event, $idOrderItems);
$this->addInfoMessage(static::MESSAGE_STATUS_CHANGED_SUCCESSFULLY);

Expand All @@ -68,19 +62,21 @@ public function triggerEventForOrderItemsAction(Request $request)
*/
public function submitTriggerEventForOrderItemsAction(Request $request)
{
$redirect = $request->query->get('redirect', static::ROUTE_REDIRECT_DEFAULT);

$redirect = $request->query->get(static::REQUEST_PARAMETER_REDIRECT, static::ROUTE_REDIRECT_DEFAULT);
if (!$this->isValidPostRequest($request)) {
$this->addErrorMessage(static::ERROR_INVALID_FORM);

return $this->redirectResponse($redirect);
}

$idOrderItem = $this->castId($request->query->getInt('id-sales-order-item'));
$event = $request->query->get('event');
$idOrderItems = $this->getRequestIdSalesOrderItems($request);
if ($idOrderItems === []) {
return $this->redirectResponse($redirect);
}

$this->getFacade()->triggerEventForOrderItems($event, [$idOrderItem]);
$this->addInfoMessage('Status change triggered successfully.');
$event = $request->query->get(static::REQUEST_PARAMETER_EVENT);
$this->getFacade()->triggerEventForOrderItems($event, $idOrderItems);
$this->addInfoMessage(static::MESSAGE_STATUS_CHANGED_SUCCESSFULLY);

return $this->redirectResponse($redirect);
}
Expand Down Expand Up @@ -178,4 +174,27 @@ protected function isTriggerFormValid(Request $request): bool

return $form->isSubmitted() && $form->isValid();
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return array
*/
protected function getRequestIdSalesOrderItems(Request $request): array
{
$idOrderItems = $request->query->get(static::REQUEST_PARAMETER_ITEMS);
if (is_array($idOrderItems) === false) {
$idOrderItems = [];
}

/**
* Exists for Backward Compatibility reasons only.
*/
$idOrderItem = $request->query->get(static::REQUEST_PARAMETER_ID_SALES_ORDER_ITEM);
if ($idOrderItems === [] && $idOrderItem !== null) {
$idOrderItems = [$idOrderItem];
}

return $idOrderItems;
}
}

0 comments on commit fecd046

Please sign in to comment.