Skip to content

Commit

Permalink
Merge pull request #7239 from NeverResponse/archive/shipping-methods
Browse files Browse the repository at this point in the history
[Admin] Archiving shipping methods
  • Loading branch information
pjedrzejewski committed Jan 21, 2017
2 parents 2694707 + 6dab3de commit f117d49
Show file tree
Hide file tree
Showing 46 changed files with 1,147 additions and 12 deletions.
34 changes: 34 additions & 0 deletions app/migrations/Version20161223164558.php
@@ -0,0 +1,34 @@
<?php

namespace Sylius\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20161223164558 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_shipping_method ADD archived_at DATETIME DEFAULT NULL');
}

/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_shipping_method DROP archived_at');
}
}
12 changes: 12 additions & 0 deletions docs/bundles/SyliusGridBundle/configuration.rst
Expand Up @@ -36,6 +36,7 @@ Here you will find all configuration options of ``sylius_grid``.
options:
fields: { }
form_options: { }
default_value: ~
enabled:
type: boolean # Type of filter
label: app.ui.enabled
Expand All @@ -45,6 +46,7 @@ Here you will find all configuration options of ``sylius_grid``.
options:
field: enabled
form_options: { }
default_value: ~
date:
type: date # Type of filter
label: app.ui.created_at
Expand All @@ -54,6 +56,7 @@ Here you will find all configuration options of ``sylius_grid``.
options:
field: createdAt
form_options: { }
default_value: ~
channel:
type: entity # Type of filter
label: app.ui.channel
Expand All @@ -64,6 +67,7 @@ Here you will find all configuration options of ``sylius_grid``.
fields: [channel]
form_options:
class: "%app.model.channel%"
default_value: ~
actions:
main:
create:
Expand Down Expand Up @@ -95,3 +99,11 @@ Here you will find all configuration options of ``sylius_grid``.
icon: ~
position: 100
options: { }
archive:
type: archive
label: sylius.ui.archive
enabled: true
icon: ~
position: 100
options:
restore_label: sylius.ui.restore
16 changes: 16 additions & 0 deletions docs/bundles/SyliusGridBundle/filters.rst
Expand Up @@ -107,3 +107,19 @@ This filter checks if an amount is in range and in specific currency
.. warning::

Providing different ``scale`` between **form_options** and **options** may cause unwanted, and plausibly volatile results.

Exists
------

This filter checks if the specified field contains any value

.. code-block:: yaml
sylius_grid:
grids:
app_order:
filters:
date:
type: exists
options:
field: completedAt
Expand Up @@ -52,3 +52,13 @@ Feature: Preventing not available shipping method selection
Then I should not be able to select "Raven Post" shipping method
And I should not be able to select "Dragon Post" shipping method
And I should be informed that my order cannot be shipped to this address

@ui
Scenario: Not being able to select an archival shipping method
Given the store has "Raven Post" shipping method with "$10.00" fee
And the store has an archival "Dragon Post" shipping method with "$30.00" fee
And I have product "Targaryen T-Shirt" in the cart
When I am at the checkout addressing step
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I complete the addressing step
Then I should not be able to select "Dragon Post" shipping method
@@ -0,0 +1,36 @@
@managing_shipping_methods
Feature: Archiving obsolete shipping methods
In order to hide no longer available shipping methods from the list and customers' use
As an Administrator
I want to archive shipping methods

Background:
Given the store operates on a single channel in "United States"
And the store allows shipping with "UPS Carrier" and "FedEx Carrier"
And I am logged in as an administrator

@ui
Scenario: Archiving a shipping method
Given I am browsing shipping methods
When I archive the "UPS Carrier" shipping method
Then the only shipping method on the list should be "FedEx Carrier"

@domain
Scenario: Archiving a shipping method does not remove it from the database
When I archive the "UPS Carrier" shipping method
Then the shipping method "UPS Carrier" should still exist in the registry

@ui
Scenario: Seeing only archived shipping methods
Given the shipping method "UPS Carrier" is archival
And I am browsing shipping methods
When I filter archival shipping methods
Then the only shipping method on the list should be "UPS Carrier"

@ui
Scenario: Restoring an archival shipping method
Given the shipping method "UPS Carrier" is archival
And I am browsing archival shipping methods
When I restore the "UPS Carrier" shipping method
Then I should be viewing non archival shipping methods
And I should see 2 shipping methods on the list
62 changes: 62 additions & 0 deletions src/Sylius/Behat/Context/Domain/ManagingShippingMethodsContext.php
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Behat\Context\Domain;

use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
use Webmozart\Assert\Assert;

/**
* @author Jan Góralski <jan.goralski@lakion.com>
*/
final class ManagingShippingMethodsContext implements Context
{
/**
* @var RepositoryInterface
*/
private $shippingMethodRepository;

/**
* @var ObjectManager
*/
private $shippingMethodManager;

/**
* @param RepositoryInterface $shippingMethodRepository
* @param ObjectManager $shippingMethodManager
*/
public function __construct(RepositoryInterface $shippingMethodRepository, ObjectManager $shippingMethodManager)
{
$this->shippingMethodRepository = $shippingMethodRepository;
$this->shippingMethodManager = $shippingMethodManager;
}

/**
* @When /^I archive the ("[^"]+" shipping method)$/
*/
public function iArchiveTheShippingMethod(ShippingMethodInterface $shippingMethod)
{
$shippingMethod->setArchivedAt(new \DateTime());

$this->shippingMethodManager->flush();
}

/**
* @Then the shipping method :shippingMethod should still exist in the registry
*/
public function theShippingMethodShouldStillExistInTheRegistry(ShippingMethodInterface $shippingMethod)
{
Assert::notNull($this->shippingMethodRepository->find($shippingMethod));
}
}
30 changes: 30 additions & 0 deletions src/Sylius/Behat/Context/Setup/ShippingContext.php
Expand Up @@ -319,6 +319,27 @@ public function storeHasDisabledShippingMethodWithFee($shippingMethodName, $fee)
]));
}

/**
* @Given /^the store has an archival "([^"]+)" shipping method with ("[^"]+") fee$/
*/
public function theStoreHasArchivalShippingMethodWithFee($shippingMethodName, $fee)
{
$channel = $this->sharedStorage->get('channel');
$configuration = $this->getConfigurationByChannels([$channel], $fee);

$this->saveShippingMethod($this->shippingMethodExampleFactory->create([
'name' => $shippingMethodName,
'enabled' => true,
'zone' => $this->getShippingZone(),
'calculator' => [
'type' => DefaultCalculators::FLAT_RATE,
'configuration' => $configuration,
],
'channels' => [$this->sharedStorage->get('channel')],
'archived_at' => new \DateTime(),
]));
}

/**
* @Given /^the store has "([^"]+)" shipping method with ("[^"]+") fee per unit$/
*/
Expand Down Expand Up @@ -423,6 +444,15 @@ public function thisShippingMethodRequiresThatNoUnitsMatchToShippingCategory(
$this->shippingMethodManager->flush();
}

/**
* @Given /^the (shipping method "[^"]+") is archival$/
*/
public function theShippingMethodIsArchival(ShippingMethodInterface $shippingMethod)
{
$shippingMethod->setArchivedAt(new \DateTime());
$this->shippingMethodManager->flush();
}

/**
* @param array $channels
* @param int $amount
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\ShippingMethod\IndexPageInterface;
use Sylius\Behat\Page\Admin\ShippingMethod\CreatePageInterface;
use Sylius\Behat\Page\Admin\ShippingMethod\UpdatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
Expand Down Expand Up @@ -283,6 +283,60 @@ public function iShouldBeNotifiedThatCodeShouldContain()
);
}

/**
* @When I archive the :name shipping method
*/
public function iArchiveTheShippingMethod($name)
{
$actions = $this->indexPage->getActionsForResource(['name' => $name]);
$actions->pressButton('Archive');
}

/**
* @When I restore the :name shipping method
*/
public function iRestoreTheShippingMethod($name)
{
$actions = $this->indexPage->getActionsForResource(['name' => $name]);
$actions->pressButton('Restore');
}

/**
* @Then I should be viewing non archival shipping methods
*/
public function iShouldBeViewingNonArchivalShippingMethods()
{
Assert::false($this->indexPage->isArchivalFilterEnabled());
}

/**
* @Then I should see :count shipping methods on the list
*/
public function thereShouldBeNoShippingMethodsOnTheList($count)
{
Assert::same(
$this->indexPage->countItems(),
(int) $count,
'There should be %2$d shipping methods on the list, found %d instead.'
);
}

/**
* @Then the only shipping method on the list should be :name
*/
public function theOnlyShippingMethodOnTheListShouldBe($name)
{
Assert::same(
(int) $this->indexPage->countItems(),
1,
'There should be only one shipping method on the list, found %d instead.'
);
Assert::true(
$this->indexPage->isSingleResourceOnPage(['name' => $name]),
sprintf('Shipping method "%s" was not found on the list.', $name)
);
}

/**
* @Then shipping method with :element :name should not be added
*/
Expand Down Expand Up @@ -345,6 +399,25 @@ public function iWantToBrowseShippingMethods()
$this->indexPage->open();
}

/**
* @Given I am browsing archival shipping methods
*/
public function iAmBrowsingArchivalShippingMethods()
{
$this->indexPage->open();
$this->indexPage->chooseArchival('Yes');
$this->indexPage->filter();
}

/**
* @Given I filter archival shipping methods
*/
public function iFilterArchivalShippingMethods()
{
$this->indexPage->chooseArchival('Yes');
$this->indexPage->filter();
}

/**
* @Then the first shipping method on the list should have :field :value
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Sylius/Behat/Page/Admin/Crud/IndexPage.php
Expand Up @@ -134,6 +134,19 @@ public function deleteResourceOnPage(array $parameters)
$actionButtons->pressButton('Delete');
}

/**
* {@inheritdoc}
*/
public function getActionsForResource(array $parameters)
{
$tableAccessor = $this->getTableAccessor();
$table = $this->getElement('table');

$resourceRow = $tableAccessor->getRowWithFields($table, $parameters);

return $tableAccessor->getFieldFromRow($table, $resourceRow, 'actions');
}

public function filter()
{
$this->getElement('filter')->press();
Expand Down
8 changes: 8 additions & 0 deletions src/Sylius/Behat/Page/Admin/Crud/IndexPageInterface.php
Expand Up @@ -11,6 +11,7 @@

namespace Sylius\Behat\Page\Admin\Crud;

use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Page\SymfonyPageInterface;

/**
Expand Down Expand Up @@ -52,6 +53,13 @@ public function sortBy($fieldName);
*/
public function deleteResourceOnPage(array $parameters);

/**
* @param array $parameters
*
* @return NodeElement
*/
public function getActionsForResource(array $parameters);

/**
* @return int
*/
Expand Down

0 comments on commit f117d49

Please sign in to comment.