-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\Controller\Admin; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusPeakPlugin\Model\UploadOrderRequestInterface; | ||
use Setono\SyliusPeakPlugin\Workflow\UploadOrderRequestWorkflow; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
final class ResetUploadOrderRequestAction | ||
{ | ||
use ORMTrait; | ||
|
||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly WorkflowInterface $uploadOrderRequestWorkflow, | ||
private readonly UrlGeneratorInterface $urlGenerator, | ||
/** @var class-string<UploadOrderRequestInterface> $uploadOrderRequestClass */ | ||
private readonly string $uploadOrderRequestClass, | ||
) { | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public function __invoke(Request $request, int $id): RedirectResponse | ||
{ | ||
$manager = $this->getManager($this->uploadOrderRequestClass); | ||
|
||
/** @var UploadOrderRequestInterface|null $uploadOrderRequest */ | ||
$uploadOrderRequest = $manager->find($this->uploadOrderRequestClass, $id); | ||
if ($uploadOrderRequest === null) { | ||
throw new NotFoundHttpException(sprintf('Upload order request with id %d not found', $id)); | ||
} | ||
|
||
if ($this->uploadOrderRequestWorkflow->can($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_RESET)) { | ||
$this->uploadOrderRequestWorkflow->apply($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_RESET); | ||
} | ||
|
||
$manager->flush(); | ||
|
||
$session = $request->getSession(); | ||
if ($session instanceof Session) { | ||
$session->getFlashBag()->add('success', 'setono_sylius_peak.upload_order_request_reset'); | ||
} | ||
|
||
$referrer = $request->headers->get('referer'); | ||
if (is_string($referrer)) { | ||
return new RedirectResponse($referrer); | ||
} | ||
|
||
return new RedirectResponse($this->urlGenerator->generate('sylius_admin_order_show', [ | ||
'id' => $uploadOrderRequest->getOrder()?->getId(), | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakPlugin\EventSubscriber; | ||
|
||
use Setono\SyliusPeakPlugin\Model\OrderInterface; | ||
use Setono\SyliusPeakPlugin\Workflow\UploadOrderRequestWorkflow; | ||
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent; | ||
use Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
final class AddResetLinkSubscriber implements EventSubscriberInterface | ||
{ | ||
private const MENU_ITEM_KEY = 'reset_upload_order_request'; | ||
|
||
public function __construct(private readonly WorkflowInterface $workflow) | ||
{ | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [OrderShowMenuBuilder::EVENT_NAME => 'addLink']; | ||
} | ||
|
||
public function addLink(OrderShowMenuBuilderEvent $event): void | ||
{ | ||
$order = $event->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$uploadOrderRequest = $order->getPeakUploadOrderRequest(); | ||
if ($uploadOrderRequest === null) { | ||
return; | ||
} | ||
|
||
if (!$this->workflow->can($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_RESET)) { | ||
return; | ||
} | ||
|
||
$menu = $event->getMenu(); | ||
$sort = array_keys($menu->getChildren()); | ||
|
||
$menu | ||
->addChild(self::MENU_ITEM_KEY, [ | ||
'route' => 'setono_sylius_peak_admin_reset_upload_order_request', | ||
'routeParameters' => ['id' => $uploadOrderRequest->getId()], | ||
]) | ||
->setAttribute('type', 'link') | ||
->setLabel($uploadOrderRequest->getPeakOrderId() === null ? 'setono_sylius_peak.ui.upload_order_to_peak' : 'setono_sylius_peak.ui.re_upload_order_to_peak') | ||
->setLabelAttribute('icon', 'redo') | ||
; | ||
|
||
array_unshift($sort, self::MENU_ITEM_KEY); | ||
|
||
try { | ||
$event->getMenu()->reorderChildren($sort); | ||
} catch (\InvalidArgumentException) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
setono_sylius_peak: | ||
upload_order_request_reset: The request to upload the order has been created successfully. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
setono_sylius_peak: | ||
ui: | ||
failed: Failed | ||
pending: Pending | ||
register_webhooks: Register webhooks | ||
register_webhooks_information: Your webhooks registration is out of date. Please click the button to register webhooks with Peak. | ||
peak: Peak | ||
peak_index: Manage your Peak settings | ||
peak_state: Peak state | ||
uploaded: Uploaded | ||
pending: Pending | ||
processing: Processing | ||
re_upload_order_to_peak: Re-upload order to Peak | ||
register_webhooks: Register webhooks | ||
register_webhooks_information: Your webhooks registration is out of date. Please click the button to register webhooks with Peak. | ||
upload_order_to_peak: Upload order to Peak | ||
uploaded: Uploaded | ||
view_order_in_peak: View order in Peak | ||
webhooks: Webhooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters