Skip to content

Commit

Permalink
Add pending state (#25)
Browse files Browse the repository at this point in the history
* Add "allow-plugins" section

* Swap Assert:eq() arguments

* Allow marking export's state as pending

* Cover pending state with using behat

* Add Polish translation of pending

* Revert findAllWithNewState method and deprecate it
  • Loading branch information
jakubtobiasz authored Feb 8, 2022
1 parent b619380 commit 7030758
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 6 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 8 additions & 0 deletions features/exporting_shipping_data_to_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/ShippingExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/Entity/ShippingExportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/Repository/ShippingExportRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,38 @@

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')
->leftJoin('o.shipment', 'shipment')
;
}

/**
* @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()
;
Expand Down
5 changes: 5 additions & 0 deletions src/Repository/ShippingExportRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/messages.pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
<span class="shipping-export-state ui green label"><i class="check icon"></i> {{ value|trans }}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<form action="{{ path('bitbag_admin_export_single_shipment', {'id' : data.id}) }}" method="POST">
<input type="hidden" name="_method" value="PUT">
<button class="ui labeled icon primary button mini shipping-export-state"><i class="arrow up icon"></i> {{ value|trans }}</button>
<button class="ui labeled icon {% if data.state == 'new' %} primary {% endif %} {% if data.state == 'pending' %} yellow {% endif %} button mini shipping-export-state">
<i class="{% if data.state == 'new' %} arrow up {% endif %} {% if data.state == 'pending' %} clock outline {% endif %} icon"></i>
{{ value|trans }}
</button>
</form>
15 changes: 15 additions & 0 deletions tests/Behat/Context/Setup/ShippingExportContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion tests/Behat/Context/Ui/Admin/ShippingExportContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 7030758

Please sign in to comment.