Skip to content

Commit

Permalink
OP-319 - Select parcel template fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkalon committed Aug 6, 2024
1 parent fa04c2e commit b97d4a0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Api/WebClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface WebClientInterface

public const ROD_ADDITIONAL_SERVICE = 'rod';

public const TEMPLATE_SELECT_EVENT = 'export_shipping_select_parcel_template';
public const SELECT_PARCEL_TEMPLATE_EVENT = 'export_shipping_select_parcel_template';

public function setShippingGateway(ShippingGatewayInterface $shippingGateway): self;

Expand Down
7 changes: 2 additions & 5 deletions src/Controller/ShippingExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace BitBag\SyliusInPostPlugin\Controller;

use BitBag\SyliusInPostPlugin\Api\WebClientInterface;
use BitBag\SyliusInPostPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Event\ExportShipmentEvent;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
Expand Down Expand Up @@ -74,12 +73,10 @@ public function selectParcelTemplate(Request $request): RedirectResponse
/** @var ResourceInterface|null $shippingExport */
$shippingExport = $this->repository->find($request->get('id'));
Assert::notNull($shippingExport);

/** @var ShippingExportInterface $shippingExport */
$shippingExport?->setParcelTemplate($request->get('template'));
$shippingExport->setParcelTemplate($request->get('template'));

$this->eventDispatcher->dispatch(
WebClientInterface::TEMPLATE_SELECT_EVENT,
WebClientInterface::SELECT_PARCEL_TEMPLATE_EVENT,
$configuration,
$shippingExport,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener;

use BitBag\SyliusInPostPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;

class SelectParcelTemplateAction implements SelectParcelTemplateActionInterface
{
private const INFO = 'info';

private const TRANSLATION_KEY = 'bitbag_sylius_inpost_plugin.ui.parcel_template.select_action_performed';

private ShippingExportRepositoryInterface $shippingExportRepository;

private RequestStack $requestStack;

public function __construct(ShippingExportRepositoryInterface $shippingExportRepository, RequestStack $requestStack)
{
private TranslatorInterface $translator;

public function __construct(
ShippingExportRepositoryInterface $shippingExportRepository,
RequestStack $requestStack,
TranslatorInterface $translator,
) {
$this->shippingExportRepository = $shippingExportRepository;
$this->requestStack = $requestStack;
$this->translator = $translator;
}

public function execute(ShippingExportInterface $shippingExport): void
{
$message = $this->translator->trans(self::TRANSLATION_KEY);
$this->shippingExportRepository->add($shippingExport);
$this->requestStack->getSession()->getBag('flashes')->add(self::INFO, self::TRANSLATION_KEY);
$this->requestStack->getSession()->getBag('flashes')->add(self::INFO, $message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
>
<argument type="service" id="bitbag.repository.shipping_export" />
<argument type="service" id="request_stack" />
<argument type="service" id="translator" />
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions tests/Spec/Builder/ShippingExportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Tests\BitBag\SyliusInPostPlugin\Spec\Builder;

use BitBag\SyliusShippingExportPlugin\Entity\ShippingExport;
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusInPostPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Tests\BitBag\SyliusInPostPlugin\Application\src\Entity\ShippingExport;

class ShippingExportBuilder
{
Expand Down

0 comments on commit b97d4a0

Please sign in to comment.