[Admin] Sort shipping methods by their positions

This commit is contained in:
Kamil Kokot 2016-10-18 14:15:03 +02:00
parent 822d08525a
commit 520abc59fe
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
5 changed files with 53 additions and 13 deletions

View file

@ -1,5 +1,5 @@
@managing_shipping_methods
Feature: Sorting listed shipping methods
Feature: Sorting listed shipping methods by name or code
In order to change the order by which shipping methods are displayed
As an Administrator
I want to sort shipping methods

View file

@ -0,0 +1,19 @@
@managing_shipping_methods
Feature: Sorting listed shipping methods by position
In order to change the order by which shipping methods are displayed
As an Administrator
I want to sort shipping methods by their positions
Background:
Given the store operates on a single channel in "United States"
And the store allows shipping with "Aardvark Stagecoach" with position 2
And the store also allows shipping with "Narwhal Submarine" with position 0
And the store also allows shipping with "Pug Blimp" with position 1
And I am logged in as an administrator
@ui
Scenario: Shipping methods are sorted by position in ascending order by default
When I am browsing shipping methods
Then I should see 3 shipping methods in the list
And the first shipping method on the list should have name "Narwhal Submarine"
And the last shipping method on the list should have name "Aardvark Stagecoach"

View file

@ -88,7 +88,7 @@ final class ShippingContext implements Context
*/
public function storeShipsEverythingForFree(ZoneInterface $zone = null)
{
$this->createShippingMethod('Free', null, $zone);
$this->createShippingMethod('Free', null, null, $zone);
}
/**
@ -97,17 +97,18 @@ final class ShippingContext implements Context
public function theStoreShipsEverywhereForFree()
{
foreach ($this->zoneRepository->findAll() as $zone) {
$this->createShippingMethod('Free', null, $zone);
$this->createShippingMethod('Free', null, null, $zone);
}
}
/**
* @Given the store allows shipping with :name
* @Given the store( also) allows shipping with :name identified by :code
* @Given the store (also) allows shipping with :name
* @Given the store (also) allows shipping with :name identified by :code
* @Given the store (also) allows shipping with :name with position :position
*/
public function theStoreAllowsShippingMethod($name, $code = null)
public function theStoreAllowsShippingMethod($name, $code = null, $position = null)
{
$this->createShippingMethod($name, $code);
$this->createShippingMethod($name, $code, $position);
}
/**
@ -141,7 +142,7 @@ final class ShippingContext implements Context
*/
public function storeHasShippingMethodWithFee($shippingMethodName, $fee, ZoneInterface $zone = null)
{
$this->createShippingMethod($shippingMethodName, null, $zone, 'en', ['amount' => $fee]);
$this->createShippingMethod($shippingMethodName, null, null, $zone, 'en', ['amount' => $fee]);
}
/**
@ -149,7 +150,7 @@ final class ShippingContext implements Context
*/
public function storeHasDisabledShippingMethodWithFee($shippingMethodName, $fee)
{
$this->createShippingMethod($shippingMethodName, null, null, 'en', ['amount' => $fee], DefaultCalculators::FLAT_RATE, false);
$this->createShippingMethod($shippingMethodName, null, null, null, 'en', ['amount' => $fee], DefaultCalculators::FLAT_RATE, false);
}
/**
@ -157,7 +158,7 @@ final class ShippingContext implements Context
*/
public function theStoreHasShippingMethodWithFeePerUnit($shippingMethodName, $fee)
{
$this->createShippingMethod($shippingMethodName, null, null, 'en', ['amount' => $fee], DefaultCalculators::PER_UNIT_RATE);
$this->createShippingMethod($shippingMethodName, null, null, null, 'en', ['amount' => $fee], DefaultCalculators::PER_UNIT_RATE);
}
/**
@ -169,6 +170,7 @@ final class ShippingContext implements Context
$shippingMethodName,
null,
null,
null,
'en',
['first_unit_cost' => $fee, 'additional_unit_cost' => $perUnitFee, 'additional_unit_limit' => $limit],
DefaultCalculators::FLEXIBLE_RATE
@ -180,7 +182,7 @@ final class ShippingContext implements Context
*/
public function storeHasShippingMethodWithFeeNotAssignedToAnyChannel($shippingMethodName, $fee)
{
$this->createShippingMethod($shippingMethodName, null, null, 'en', ['amount' => $fee], DefaultCalculators::FLAT_RATE, false, false);
$this->createShippingMethod($shippingMethodName, null, null, null, 'en', ['amount' => $fee], DefaultCalculators::FLAT_RATE, false, false);
}
/**
@ -213,6 +215,7 @@ final class ShippingContext implements Context
/**
* @param string $name
* @param string|null $code
* @param int|null $position
* @param ZoneInterface|null $zone
* @param string $locale
* @param array $configuration
@ -223,6 +226,7 @@ final class ShippingContext implements Context
private function createShippingMethod(
$name,
$code = null,
$position = null,
ZoneInterface $zone = null,
$locale = 'en',
$configuration = ['amount' => 0],
@ -242,6 +246,7 @@ final class ShippingContext implements Context
$shippingMethod = $this->shippingMethodFactory->createNew();
$shippingMethod->setCode($code);
$shippingMethod->setName($name);
$shippingMethod->setPosition($position);
$shippingMethod->setCurrentLocale($locale);
$shippingMethod->setConfiguration($configuration);
$shippingMethod->setCalculator($calculator);

View file

@ -315,7 +315,8 @@ final class ManagingShippingMethodsContext implements Context
*/
public function theFirstShippingMethodOnTheListShouldHave($field, $value)
{
$actualValue = $this->indexPage->getColumnFields($field)[0];
$fields = $this->indexPage->getColumnFields($field);
$actualValue = reset($fields);
Assert::same(
$actualValue,
@ -324,6 +325,21 @@ final class ManagingShippingMethodsContext implements Context
);
}
/**
* @Then the last shipping method on the list should have :field :value
*/
public function theLastShippingMethodOnTheListShouldHave($field, $value)
{
$fields = $this->indexPage->getColumnFields($field);
$actualValue = end($fields);
Assert::same(
$actualValue,
$value,
sprintf('Expected last shipping method\'s %s to be "%s", but it is "%s".', $field, $value, $actualValue)
);
}
/**
* @When I switch the way shipping methods are sorted by :field
* @When I start sorting shipping methods by :field

View file

@ -9,7 +9,7 @@ sylius_grid:
method: createListQueryBuilder
arguments: ["%locale%"]
sorting:
code: asc
position: asc
fields:
code:
type: string