Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Product][API][Bug] Fixed product sorting by translated names #13684

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Product][API][Bug] Fixed product sorting by translated names
  • Loading branch information
Rafikooo committed Feb 23, 2022
commit f60a373a3ec225feb08c95b5e59d9eb3dc438ff7
23 changes: 13 additions & 10 deletions features/product/viewing_products/viewing_sorted_products.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,52 @@ Feature: Sorting listed products
And the store also has a product "Xtreme Pug" with code "X_PUG", created at "07-09-2016"
And this product belongs to "Fluffy Pets"
And this product's price is "$12.51"
And the store also has a product "Unreal Pug" with code "U_PUG", created at "04-10-2016"
And this product belongs to "Fluffy Pets"
And this product's price is "$13.27"

@ui
Scenario: Sorting products by their dates with descending order
When I view newest products from taxon "Fluffy Pets"
Then I should see 3 products in the list
Then I should see 4 products in the list
And I should see a product with name "Xtreme Pug"
But the first product on the list should have name "Pug of Love"

@ui
Scenario: Sorting products by their dates with ascending order
When I view oldest products from taxon "Fluffy Pets"
Then I should see 3 products in the list
Then I should see 4 products in the list
And I should see a product with name "Berserk Pug"
But the first product on the list should have name "Xtreme Pug"

@ui
Scenario: Sorting products by their prices with descending order
Scenario: Sorting products by their prices with ascending order
When I browse products from taxon "Fluffy Pets"
And I sort products by the lowest price first
Then I should see 3 products in the list
Then I should see 4 products in the list
And I should see a product with name "Xtreme Pug"
But the first product on the list should have name "Berserk Pug"

@ui
Scenario: Sorting products by their prices with ascending order
Scenario: Sorting products by their prices with descending order
When I browse products from taxon "Fluffy Pets"
And I sort products by the highest price first
Then I should see 3 products in the list
Then I should see 4 products in the list
And I should see a product with name "Xtreme Pug"
But the first product on the list should have name "Pug of Love"

@ui
@api @ui
Scenario: Sorting products by their names from a to z
When I browse products from taxon "Fluffy Pets"
And I sort products alphabetically from a to z
Then I should see 3 products in the list
Then I should see 4 products in the list
And the first product on the list should have name "Berserk Pug"
And the last product on the list should have name "Xtreme Pug"

@ui
@api @ui
Scenario: Sorting products by their names from z to a
When I browse products from taxon "Fluffy Pets"
And I sort products alphabetically from z to a
Then I should see 3 products in the list
Then I should see 4 products in the list
And the first product on the list should have name "Xtreme Pug"
And the last product on the list should have name "Berserk Pug"
36 changes: 36 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public function iBrowseProductsFromTaxon(TaxonInterface $taxon): void
$this->client->filter();
}

/**
* @When I sort products alphabetically from a to z
*/
public function iSortProductsAlphabeticallyFromAToZ(): void
{
$this->client->sort(['translation.name' => 'asc']);
}

/**
* @When I sort products alphabetically from z to a
*/
public function iSortProductsAlphabeticallyFromZToA(): void
{
$this->client->sort(['translation.name' => 'desc']);
}

/**
* @When I clear filter
*/
Expand Down Expand Up @@ -180,6 +196,26 @@ public function iViewProducts(): void
$this->client->index();
}

/**
* @Then the first product on the list should have name :name
*/
public function theFirstProductOnTheListShouldHaveName(string $name): void
{
$products = $this->responseChecker->getCollection($this->client->getLastResponse());

Assert::same($products[0]['translations']['en_US']['name'], $name);
}

/**
* @Then the last product on the list should have name :name
*/
public function theLastProductOnTheListShouldHaveName(string $name): void
{
$products = $this->responseChecker->getCollection($this->client->getLastResponse());

Assert::same(end($products)['translations']['en_US']['name'], $name);
}

/**
* @When /^I should see only (\d+) product(s)$/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ protected function filterProperty(
}

$queryBuilder
->addSelect('translation')
->innerJoin('o.translations', 'translation')
->orderBy('translation.name', $direction)
;
}
Expand Down