diff --git a/composer.json b/composer.json index 309e01a..4d15ff2 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,13 @@ "vimeo/psalm": "4.7.1" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "symfony/thanks": true, + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } }, "autoload": { "psr-4": { diff --git a/features/exporting_shipping_data_to_api.feature b/features/exporting_shipping_data_to_api.feature index 7c0e4b2..8d84371 100644 --- a/features/exporting_shipping_data_to_api.feature +++ b/features/exporting_shipping_data_to_api.feature @@ -42,6 +42,14 @@ Feature: Managing shipping gateway And I export all new shipments Then I should be notified that there are no new shipments to export + @ui + Scenario: Exporting all new and pending shipments + Given there are 2 exports marked as pending + When I go to the shipping export page + And I export all new shipments + Then I should be notified that the shipment has been exported + And all 5 shipments should have "Exported" state + @ui Scenario: Throwing an external API error while exporting shipments Given the external shipping API is down diff --git a/src/Controller/ShippingExportController.php b/src/Controller/ShippingExportController.php index 2912de4..ee10b07 100644 --- a/src/Controller/ShippingExportController.php +++ b/src/Controller/ShippingExportController.php @@ -13,6 +13,7 @@ use BitBag\SyliusShippingExportPlugin\Event\ExportShipmentEvent; use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface; use Sylius\Bundle\ResourceBundle\Controller\ResourceController; +use Sylius\Component\Resource\Model\ResourceInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Webmozart\Assert\Assert; @@ -26,7 +27,7 @@ public function exportAllNewShipmentsAction(Request $request): RedirectResponse { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); - $shippingExports = $this->repository->findAllWithNewState(); + $shippingExports = $this->repository->findAllWithNewOrPendingState(); if (0 === count($shippingExports)) { $this->addFlash('error', 'bitbag.ui.no_new_shipments_to_export'); @@ -49,6 +50,7 @@ public function exportSingleShipmentAction(Request $request): RedirectResponse { $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); + /** @var ResourceInterface|null $shippingExport */ $shippingExport = $this->repository->find($request->get('id')); Assert::notNull($shippingExport); diff --git a/src/Entity/ShippingExportInterface.php b/src/Entity/ShippingExportInterface.php index 1507577..f01fc75 100644 --- a/src/Entity/ShippingExportInterface.php +++ b/src/Entity/ShippingExportInterface.php @@ -17,6 +17,8 @@ interface ShippingExportInterface extends ResourceInterface { public const STATE_NEW = 'new'; + public const STATE_PENDING = 'pending'; + public const STATE_EXPORTED = 'exported'; public function getShipment(): ?ShipmentInterface; diff --git a/src/Repository/ShippingExportRepository.php b/src/Repository/ShippingExportRepository.php index 20e8125..aecd036 100644 --- a/src/Repository/ShippingExportRepository.php +++ b/src/Repository/ShippingExportRepository.php @@ -16,6 +16,10 @@ class ShippingExportRepository extends EntityRepository implements ShippingExportRepositoryInterface { + public const NEW_STATE_PARAMETER = 'newState'; + + public const PENDING_STATE_PARAMETER = 'pendingState'; + public function createListQueryBuilder(): QueryBuilder { return $this->createQueryBuilder('o') @@ -23,11 +27,27 @@ public function createListQueryBuilder(): QueryBuilder ; } + /** + * @inheritdoc + */ public function findAllWithNewState(): array { + trigger_deprecation('bitbag/shipping-export-plugin', '1.6', 'The "%s()" method is deprecated, use "ShippingExportRepository::findAllWithNewOrPendingState" instead.', __METHOD__); + return $this->createQueryBuilder('o') ->where('o.state = :newState') - ->setParameter('newState', ShippingExportInterface::STATE_NEW) + ->setParameter(self::NEW_STATE_PARAMETER, ShippingExportInterface::STATE_NEW) + ->getQuery() + ->getResult() + ; + } + + public function findAllWithNewOrPendingState(): array + { + return $this->createQueryBuilder('o') + ->where('o.state = :newState OR o.state = :pendingState') + ->setParameter(self::NEW_STATE_PARAMETER, ShippingExportInterface::STATE_NEW) + ->setParameter(self::PENDING_STATE_PARAMETER, ShippingExportInterface::STATE_PENDING) ->getQuery() ->getResult() ; diff --git a/src/Repository/ShippingExportRepositoryInterface.php b/src/Repository/ShippingExportRepositoryInterface.php index c7ef268..d2623ae 100644 --- a/src/Repository/ShippingExportRepositoryInterface.php +++ b/src/Repository/ShippingExportRepositoryInterface.php @@ -17,5 +17,10 @@ interface ShippingExportRepositoryInterface extends RepositoryInterface { public function createListQueryBuilder(): QueryBuilder; + /** + * @depracated since SyliusShippingExportPlugin 1.6, use ShippingExportRepository::findAllWithNewOrPendingState instead. + */ public function findAllWithNewState(): array; + + public function findAllWithNewOrPendingState(): array; } diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 8e40752..ca89716 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -10,6 +10,7 @@ bitbag: manage_shipping_exports: Manage shipping export manage_shipping_gateways: Manage shipping gateways new: New + pending: Pending no_shipping_label: No label not_exported_yet: Not exported yet shipping_export_label: Shipping label diff --git a/src/Resources/translations/messages.pl.yml b/src/Resources/translations/messages.pl.yml index dce8fa1..eb47bbd 100644 --- a/src/Resources/translations/messages.pl.yml +++ b/src/Resources/translations/messages.pl.yml @@ -10,6 +10,7 @@ bitbag: manage_shipping_exports: Zarządzaj eksportem przesyłek manage_shipping_gateways: Zarządzaj bramami dostawców new: Nowy + pending: Oczekujący no_shipping_label: Brak etykiety not_exported_yet: Nie eksportowano shipping_export_label: Etykieta przesyłki diff --git a/src/Resources/views/ShippingExport/Grid/Field/state.html.twig b/src/Resources/views/ShippingExport/Grid/Field/state.html.twig index 0d3ef0a..2a41765 100644 --- a/src/Resources/views/ShippingExport/Grid/Field/state.html.twig +++ b/src/Resources/views/ShippingExport/Grid/Field/state.html.twig @@ -1,6 +1,6 @@ {% set value = 'bitbag.ui.' ~ data.state %} -{% if data.state == 'new' %} +{% if data.state == 'new' or data.state == 'pending' %} {% include '@BitBagSyliusShippingExportPlugin/ShippingExport/Partial/_exportShipment.html.twig' %} {% else %} {{ value|trans }} diff --git a/src/Resources/views/ShippingExport/Partial/_exportShipment.html.twig b/src/Resources/views/ShippingExport/Partial/_exportShipment.html.twig index 62c3e79..055d350 100644 --- a/src/Resources/views/ShippingExport/Partial/_exportShipment.html.twig +++ b/src/Resources/views/ShippingExport/Partial/_exportShipment.html.twig @@ -1,4 +1,7 @@
- +
diff --git a/tests/Behat/Context/Setup/ShippingExportContext.php b/tests/Behat/Context/Setup/ShippingExportContext.php index d303b45..4c390ad 100644 --- a/tests/Behat/Context/Setup/ShippingExportContext.php +++ b/tests/Behat/Context/Setup/ShippingExportContext.php @@ -12,6 +12,7 @@ use Behat\Behat\Context\Context; use BitBag\SyliusShippingExportPlugin\Entity\ShippingExport; +use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface; use BitBag\SyliusShippingExportPlugin\Repository\ShippingGatewayRepositoryInterface; @@ -128,4 +129,18 @@ public function addShippingExportForGateway(ShipmentInterface $shipment, Shippin $this->shippingExportRepository->add($shippingExport); } + + /** + * @Given there are :numberOfExports exports marked as pending + */ + public function thereAreExportsMarkedAsPending(int $numberOfExports): void + { + /** @var ShippingExportInterface[] $exports */ + $exports = $this->shippingExportRepository->findBy([], null, $numberOfExports); + + foreach ($exports as $export) { + $export->setState(ShippingExportInterface::STATE_PENDING); + $this->shippingExportRepository->add($export); + } + } } diff --git a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php index ba00ee6..0d52051 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php @@ -47,7 +47,7 @@ public function iGoToTheShippingExportPage(): void */ public function iShouldSeeNewShipmentsToExportWithState(string $number, string $state): void { - Assert::eq((int) $number, count($this->indexPage->getShipmentsWithState($state))); + Assert::eq(count($this->indexPage->getShipmentsWithState($state)), (int) $number); } /**