Skip to content

Commit

Permalink
Adding link to Peak in the order show page
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 19, 2024
1 parent 741a776 commit 3aaf30e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
55 changes: 55 additions & 0 deletions src/EventSubscriber/AddLinkToPeakSubscriber.php
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

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:19:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addLink'>' (see https://psalm.dev/197)

Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:19:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addLink'>' (see https://psalm.dev/197)

Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:19:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addLink'>' (see https://psalm.dev/197)

Check failure on line 19 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:19:51: MixedReturnTypeCoercion: The declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents is more specific than the inferred return type 'non-empty-array<array-key, 'addLink'>' (see https://psalm.dev/197)
{
return [OrderShowMenuBuilder::EVENT_NAME => 'addLink'];

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

MixedArrayOffset

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addLink'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents (see https://psalm.dev/197)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:17: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder does not exist (see https://psalm.dev/019)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedArrayOffset

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addLink'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents (see https://psalm.dev/197)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:17: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder does not exist (see https://psalm.dev/019)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

MixedArrayOffset

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addLink'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents (see https://psalm.dev/197)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:17: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder does not exist (see https://psalm.dev/019)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedArrayOffset

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedArrayOffset: Cannot create mixed offset – expecting array-key (see https://psalm.dev/031)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

MixedReturnTypeCoercion

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:16: MixedReturnTypeCoercion: The type 'non-empty-array<array-key, 'addLink'>' is more general than the declared return type 'array<string, array{0?: array{0: string, 1?: int}|string, 1?: array{0: string, 1?: int}|int, ...<int<0, max>, array{0: string, 1?: int}>}|string>' for Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber::getSubscribedEvents (see https://psalm.dev/197)

Check failure on line 21 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:21:17: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder does not exist (see https://psalm.dev/019)
}

public function addLink(OrderShowMenuBuilderEvent $event): void

Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: lowest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:24:29: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent does not exist (see https://psalm.dev/019)

Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:24:29: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent does not exist (see https://psalm.dev/019)

Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:24:29: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent does not exist (see https://psalm.dev/019)

Check failure on line 24 in src/EventSubscriber/AddLinkToPeakSubscriber.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~6.4.0)

UndefinedClass

src/EventSubscriber/AddLinkToPeakSubscriber.php:24:29: UndefinedClass: Class, interface or enum named Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent does not exist (see https://psalm.dev/019)
{
$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
Expand Up @@ -15,6 +15,7 @@
<field name="request" type="text" nullable="true"/>
<field name="response" type="text" nullable="true"/>
<field name="error" type="text" nullable="true"/>
<field name="peakOrderId" type="integer" nullable="true"/>

<one-to-one field="order" target-entity="Sylius\Component\Order\Model\OrderInterface" inversed-by="peakWMSUploadOrderRequest">
<join-column name="order_id" referenced-column-name="id" nullable="false" unique="true" on-delete="CASCADE"/>
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/services/event_subscriber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<tag name="kernel.event_subscriber"/>
</service>

<service id="setono_sylius_peak_wms.event_subscriber.add_link_to_peak"
class="Setono\SyliusPeakWMSPlugin\EventSubscriber\AddLinkToPeakSubscriber">
<argument>%kernel.debug%</argument>

<tag name="kernel.event_subscriber"/>
</service>

<service id="setono_sylius_peak_wms.event_subscriber.add_menu"
class="Setono\SyliusPeakWMSPlugin\EventSubscriber\AddMenuSubscriber">
<tag name="kernel.event_subscriber"/>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ setono_sylius_peak_wms:
peak_wms_state: Peak WMS state
uploaded: Uploaded
processing: Processing
view_order_in_peak: View order in Peak WMS
webhooks: Webhooks
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 %}

0 comments on commit 3aaf30e

Please sign in to comment.