-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusPeakWMSPlugin\EventSubscriber; | ||
|
||
use Setono\SyliusPeakWMSPlugin\Model\OrderInterface; | ||
use Setono\SyliusPeakWMSPlugin\Model\UploadOrderRequestInterface; | ||
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent; | ||
use Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class AddLinkToPeakSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct(private readonly bool $testEnvironment) | ||
{ | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)MixedReturnTypeCoercion
Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)MixedReturnTypeCoercion
Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)MixedReturnTypeCoercion
Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)MixedReturnTypeCoercion
|
||
{ | ||
return [OrderShowMenuBuilder::EVENT_NAME => 'addLink']; | ||
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)MixedArrayOffset
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)MixedReturnTypeCoercion
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)UndefinedClass
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)MixedArrayOffset
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)MixedReturnTypeCoercion
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)UndefinedClass
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)MixedArrayOffset
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)MixedReturnTypeCoercion
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)UndefinedClass
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)MixedArrayOffset
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)MixedReturnTypeCoercion
Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)UndefinedClass
|
||
} | ||
|
||
public function addLink(OrderShowMenuBuilderEvent $event): void | ||
Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)UndefinedClass
Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)UndefinedClass
Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)UndefinedClass
Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)UndefinedClass
|
||
{ | ||
$order = $event->getOrder(); | ||
if (!$order instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$uploadOrderRequest = $order->getPeakWMSUploadOrderRequest(); | ||
if ($uploadOrderRequest === null) { | ||
return; | ||
} | ||
|
||
$peakOrderId = $uploadOrderRequest->getPeakOrderId(); | ||
|
||
if ($uploadOrderRequest->getState() !== UploadOrderRequestInterface::STATE_UPLOADED || null === $peakOrderId) { | ||
return; | ||
} | ||
|
||
$menu = $event->getMenu(); | ||
$menu | ||
->addChild('view_order_in_peak', [ | ||
'uri' => sprintf('https://app%s.peakwms.com/dialog/orderOverview/%d/details', $this->testEnvironment ? '-test' : '', $peakOrderId), | ||
]) | ||
->setAttribute('type', 'link') | ||
->setLabel('setono_sylius_peak_wms.ui.view_order_in_peak') | ||
->setLabelAttribute('icon', 'external alternate') | ||
->setLabelAttribute('color', 'blue') | ||
; | ||
|
||
$menu->reorderChildren(['view_order_in_peak', 'order_history', 'cancel']); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{# @var data \Setono\SyliusPeakWMSPlugin\Model\UploadOrderRequestInterface #} | ||
{% set state = data.state %} | ||
{% set value = 'setono_sylius_peak_wms.ui.' ~ state %} | ||
{# @var data \Setono\SyliusPeakWMSPlugin\Model\UploadOrderRequestInterface|null #} | ||
{% if data is not null %} | ||
{% set state = data.state %} | ||
{% set value = 'setono_sylius_peak_wms.ui.' ~ state %} | ||
|
||
{% if options.vars.labels is defined %} | ||
{% include [(options.vars.labels ~ '/' ~ state ~ '.html.twig'), '@SyliusUi/Label/_default.html.twig'] with {'value': value} %} | ||
{% else %} | ||
{% include '@SyliusUi/Label/_default.html.twig' with {'value': value} %} | ||
{% if options.vars.labels is defined %} | ||
{% include [(options.vars.labels ~ '/' ~ state ~ '.html.twig'), '@SyliusUi/Label/_default.html.twig'] with {'value': value} %} | ||
{% else %} | ||
{% include '@SyliusUi/Label/_default.html.twig' with {'value': value} %} | ||
{% endif %} | ||
{% endif %} |