From 27f312e0cc263daf41417241a0df37ee60289ea8 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Mon, 11 May 2020 12:26:48 +0200 Subject: [PATCH 1/5] [Behat] Products filtering by channel --- .../filtering_products_by_channel.feature | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 features/product/managing_products/filtering_products_by_channel.feature diff --git a/features/product/managing_products/filtering_products_by_channel.feature b/features/product/managing_products/filtering_products_by_channel.feature new file mode 100644 index 00000000000..6799f1e6ec5 --- /dev/null +++ b/features/product/managing_products/filtering_products_by_channel.feature @@ -0,0 +1,33 @@ +@managing_products +Feature: Filtering products by a channel + In order to filter products by a specific channel + As an Administrator + I want to be able to filter products on the list + + Background: + Given the store operates on a channel named "Web-EU" + And the store also operates on a channel named "Web-US" + And the store has a product "Macbook-air" with channel "Web-EU" + And the store also has a product "Macbook-pro" with channel "Web-EU" + And the store also has a product "Hp" with channel "Web-US" + And I am logged in as an administrator + + @todo + Scenario: Filtering products by a chosen channel + When I browse products + And I choose "Web-EU" as a channel filter + And I filter + Then I should see 2 products in the list + And I should see a product with name "Macbook-air" + And I should see a product with name "Macbook-pro" + But I should not see any product with name "Hp" + + @todo + Scenario: Filtering products by a chosen channel + When I browse products + And I choose "Web-US" as a channel filter + And I filter + Then I should see a single product in the list + And I should not see any product with name "Macbook-air" + And I should not see any product with name "Macbook-pro" + But I should see a product with name "Hp" From b4d26771c30862b7e5845ffab1900d01e552419a Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 12 May 2020 11:43:32 +0200 Subject: [PATCH 2/5] filtering products by channel feature --- .../filtering_products_by_channel.feature | 4 +- .../Behat/Context/Setup/ProductContext.php | 11 +++++ .../Ui/Admin/ManagingProductsContext.php | 16 +++++++ .../Behat/Page/Admin/Product/IndexPage.php | 13 ++++++ .../Page/Admin/Product/IndexPageInterface.php | 5 +++ .../Resources/config/grids/product.yml | 11 +++++ .../Doctrine/ORM/ProductRepository.php | 1 - .../Type/Grid/Filter/EntitiesFilterType.php | 42 +++++++++++++++++++ .../CoreBundle/Resources/config/services.xml | 4 ++ .../views/Grid/Filter/entities.html.twig | 3 ++ .../Core/Grid/Filter/EntitiesFilter.php | 25 +++++++++++ 11 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php create mode 100644 src/Sylius/Bundle/UiBundle/Resources/views/Grid/Filter/entities.html.twig create mode 100644 src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php diff --git a/features/product/managing_products/filtering_products_by_channel.feature b/features/product/managing_products/filtering_products_by_channel.feature index 6799f1e6ec5..4b273d5bf09 100644 --- a/features/product/managing_products/filtering_products_by_channel.feature +++ b/features/product/managing_products/filtering_products_by_channel.feature @@ -12,7 +12,7 @@ Feature: Filtering products by a channel And the store also has a product "Hp" with channel "Web-US" And I am logged in as an administrator - @todo + @ui Scenario: Filtering products by a chosen channel When I browse products And I choose "Web-EU" as a channel filter @@ -22,7 +22,7 @@ Feature: Filtering products by a channel And I should see a product with name "Macbook-pro" But I should not see any product with name "Hp" - @todo + @ui Scenario: Filtering products by a chosen channel When I browse products And I choose "Web-US" as a channel filter diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 15d49685478..068cf754440 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -869,6 +869,17 @@ public function productHasVariant(ProductInterface $product, string $productVari $this->createProductVariant($product, $productVariantName, $priceValue, $code, $channel, null, true, $currentStock); } + /** + * @Given the store has a product :product with channel :channel + * @Given the store also has a product :product with channel :channel + */ + public function theStoreHasAProductWithChannel(String $productName, ChannelInterface $channel): void + { + $product = $this->createProduct($productName, 0, $channel); + + $this->saveProduct($product); + } + private function getPriceFromString(string $price): int { return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2); diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php index efaebad2fed..2e290156809 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php @@ -248,6 +248,22 @@ public function iEnableSlugModification($localeCode = 'en_US') $this->updateSimpleProductPage->enableSlugModification($localeCode); } + /** + * @When I choose :channelName as a channel filter + */ + public function iChooseChannelAsAChannelFilter(string $channelName) + { + $this->indexPage->chooseChannelFilter($channelName); + } + + /** + * @When I filter + */ + public function iFilter(): void + { + $this->indexPage->filter(); + } + /** * @Then I should see the product :productName in the list * @Then the product :productName should appear in the store diff --git a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php index f98cf61db06..3e4ec1ddb92 100644 --- a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php @@ -37,11 +37,23 @@ public function __construct( $this->imageExistenceChecker = $imageExistenceChecker; } + public function filter(): void + { + $this->getElement('filter')->press(); + } + public function filterByTaxon(string $taxonName): void { $this->getElement('taxon_filter', ['%taxon%' => $taxonName])->click(); } + public function chooseChannelFilter(string $channelName): void + { +// $this->getElement('criteria_channel', ) + $this->getElement('filter_channel')->selectOption($channelName); + + } + public function hasProductAccessibleImage(string $productCode): bool { $productRow = $this->getTableAccessor()->getRowWithFields($this->getElement('table'), ['code' => $productCode]); @@ -63,6 +75,7 @@ protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'taxon_filter' => '.sylius-tree__item a:contains("%taxon%")', + 'filter_channel' => '#criteria_channel', ]); } } diff --git a/src/Sylius/Behat/Page/Admin/Product/IndexPageInterface.php b/src/Sylius/Behat/Page/Admin/Product/IndexPageInterface.php index c94e8b325bc..f31d2a2c646 100644 --- a/src/Sylius/Behat/Page/Admin/Product/IndexPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Product/IndexPageInterface.php @@ -14,6 +14,7 @@ namespace Sylius\Behat\Page\Admin\Product; use Sylius\Behat\Page\Admin\Crud\IndexPageInterface as CrudIndexPageInterface; +use Sylius\Component\Core\Model\ChannelInterface; interface IndexPageInterface extends CrudIndexPageInterface { @@ -22,4 +23,8 @@ public function filterByTaxon(string $taxonName): void; public function hasProductAccessibleImage(string $productCode): bool; public function showProductPage(string $productName): void; + + public function chooseChannelFilter(string $channelName) :void; + + public function filter(): void; } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml index df11eec590a..91fe66ce2ed 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml @@ -44,6 +44,14 @@ sylius_grid: enabled: type: boolean label: sylius.ui.enabled + channel: + type: entities + label: sylius.ui.channel + form_options: + class: "%sylius.model.channel.class%" + options: + class: "%sylius.model.channel.class%" + field: "channels.id" actions: main: create: @@ -101,3 +109,6 @@ sylius_grid: bulk: delete: type: delete + templates: + filter: + entities: '@SyliusUi/Grid/Filter/entities.html.twig' diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php index f37bae7c66a..5c801391a58 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php @@ -56,7 +56,6 @@ public function createListQueryBuilder(string $locale, $taxonId = null): QueryBu ->setParameter('taxonId', $taxonId) ; } - return $queryBuilder; } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php new file mode 100644 index 00000000000..5cfb6342a23 --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php @@ -0,0 +1,42 @@ +setDefaults([ + 'class' => null, + 'label' => false, + 'placeholder' => 'sylius.ui.all', + ]) + ; + } + + /** + * {@inheritdoc} + */ + public function getParent(): string + { + return EntityType::class; + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix(): string + { + return 'sylius_grid_filter_entities'; + } +} diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml index e9c740084f2..ded4ff1028c 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services.xml @@ -209,5 +209,9 @@ + + + + diff --git a/src/Sylius/Bundle/UiBundle/Resources/views/Grid/Filter/entities.html.twig b/src/Sylius/Bundle/UiBundle/Resources/views/Grid/Filter/entities.html.twig new file mode 100644 index 00000000000..0daf498ad64 --- /dev/null +++ b/src/Sylius/Bundle/UiBundle/Resources/views/Grid/Filter/entities.html.twig @@ -0,0 +1,3 @@ +{% form_theme form '@SyliusUi/Form/theme.html.twig' %} + +{{ form_row(form, {'label': filter.label}) }} diff --git a/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php b/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php new file mode 100644 index 00000000000..f20c7a572f7 --- /dev/null +++ b/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php @@ -0,0 +1,25 @@ +getExpressionBuilder(); + + $dataSource->restrict($expressionBuilder->equals($options['field'], $data)); + } +} From 43ddb1750d4fe58537d297b47232c3dfbdd2bcdd Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 12 May 2020 15:21:32 +0200 Subject: [PATCH 3/5] features more user friendly, pr fixes --- .../filtering_products_by_channel.feature | 22 +++++++++---------- .../Behat/Page/Admin/Product/IndexPage.php | 2 -- .../Resources/config/app/config.yml | 4 +++- .../Resources/config/grids/product.yml | 4 ---- .../Doctrine/ORM/ProductRepository.php | 1 + 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/features/product/managing_products/filtering_products_by_channel.feature b/features/product/managing_products/filtering_products_by_channel.feature index 4b273d5bf09..ee74552a6c3 100644 --- a/features/product/managing_products/filtering_products_by_channel.feature +++ b/features/product/managing_products/filtering_products_by_channel.feature @@ -1,15 +1,15 @@ @managing_products Feature: Filtering products by a channel - In order to filter products by a specific channel + In order to get a more focused view while managing some channel's products As an Administrator - I want to be able to filter products on the list + I want to be able to filter products by channel Background: Given the store operates on a channel named "Web-EU" And the store also operates on a channel named "Web-US" - And the store has a product "Macbook-air" with channel "Web-EU" - And the store also has a product "Macbook-pro" with channel "Web-EU" - And the store also has a product "Hp" with channel "Web-US" + And the store has a product "MacBook Air" with channel "Web-EU" + And the store also has a product "MacBook Pro" with channel "Web-EU" + And the store also has a product "HP Spectre" with channel "Web-US" And I am logged in as an administrator @ui @@ -18,9 +18,9 @@ Feature: Filtering products by a channel And I choose "Web-EU" as a channel filter And I filter Then I should see 2 products in the list - And I should see a product with name "Macbook-air" - And I should see a product with name "Macbook-pro" - But I should not see any product with name "Hp" + And I should see a product with name "MacBook Air" + And I should see a product with name "MacBook Pro" + But I should not see any product with name "HP Spectre" @ui Scenario: Filtering products by a chosen channel @@ -28,6 +28,6 @@ Feature: Filtering products by a channel And I choose "Web-US" as a channel filter And I filter Then I should see a single product in the list - And I should not see any product with name "Macbook-air" - And I should not see any product with name "Macbook-pro" - But I should see a product with name "Hp" + And I should not see any product with name "MacBook Air" + And I should not see any product with name "MacBook Pro" + But I should see a product with name "HP Spectre" diff --git a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php index 3e4ec1ddb92..5fe81977d80 100644 --- a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php @@ -49,9 +49,7 @@ public function filterByTaxon(string $taxonName): void public function chooseChannelFilter(string $channelName): void { -// $this->getElement('criteria_channel', ) $this->getElement('filter_channel')->selectOption($channelName); - } public function hasProductAccessibleImage(string $productCode): bool diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml index cc547674c56..bcb6c672e21 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml @@ -42,7 +42,9 @@ sylius_grid: ship_with_tracking_code: "@SyliusAdmin/Shipment/Grid/Action/shipWithTrackingCode.html.twig" update_product_positions: "@SyliusAdmin/Product/Grid/Action/updatePositions.html.twig" update_product_variant_positions: "@SyliusAdmin/ProductVariant/Grid/Action/updatePositions.html.twig" - + filter: + entities: '@SyliusUi/Grid/Filter/entities.html.twig' + liip_imagine: filter_sets: sylius_admin_product_original: ~ diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml index 91fe66ce2ed..3af4945119c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml @@ -50,7 +50,6 @@ sylius_grid: form_options: class: "%sylius.model.channel.class%" options: - class: "%sylius.model.channel.class%" field: "channels.id" actions: main: @@ -109,6 +108,3 @@ sylius_grid: bulk: delete: type: delete - templates: - filter: - entities: '@SyliusUi/Grid/Filter/entities.html.twig' diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php index 5c801391a58..f37bae7c66a 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php @@ -56,6 +56,7 @@ public function createListQueryBuilder(string $locale, $taxonId = null): QueryBu ->setParameter('taxonId', $taxonId) ; } + return $queryBuilder; } From a407b571f843030fdce12491822862f5de2be8ab Mon Sep 17 00:00:00 2001 From: SirDomin Date: Wed, 13 May 2020 08:26:44 +0200 Subject: [PATCH 4/5] pr fix --- .../managing_products/filtering_products_by_channel.feature | 6 +++--- src/Sylius/Behat/Context/Setup/ProductContext.php | 6 +++--- .../Behat/Context/Ui/Admin/ManagingProductsContext.php | 2 +- src/Sylius/Behat/Page/Admin/Product/IndexPage.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/features/product/managing_products/filtering_products_by_channel.feature b/features/product/managing_products/filtering_products_by_channel.feature index ee74552a6c3..52afb64b14d 100644 --- a/features/product/managing_products/filtering_products_by_channel.feature +++ b/features/product/managing_products/filtering_products_by_channel.feature @@ -7,9 +7,9 @@ Feature: Filtering products by a channel Background: Given the store operates on a channel named "Web-EU" And the store also operates on a channel named "Web-US" - And the store has a product "MacBook Air" with channel "Web-EU" - And the store also has a product "MacBook Pro" with channel "Web-EU" - And the store also has a product "HP Spectre" with channel "Web-US" + And the store has a product "MacBook Air" in channel "Web-EU" + And the store also has a product "MacBook Pro" in channel "Web-EU" + And the store also has a product "HP Spectre" in channel "Web-US" And I am logged in as an administrator @ui diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 068cf754440..3fafa051c71 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -870,10 +870,10 @@ public function productHasVariant(ProductInterface $product, string $productVari } /** - * @Given the store has a product :product with channel :channel - * @Given the store also has a product :product with channel :channel + * @Given the store has a product :productName in channel :channel + * @Given the store also has a product :productName in channel :channel */ - public function theStoreHasAProductWithChannel(String $productName, ChannelInterface $channel): void + public function theStoreHasAProductWithChannel(string $productName, ChannelInterface $channel): void { $product = $this->createProduct($productName, 0, $channel); diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php index 2e290156809..d43613723a3 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php @@ -251,7 +251,7 @@ public function iEnableSlugModification($localeCode = 'en_US') /** * @When I choose :channelName as a channel filter */ - public function iChooseChannelAsAChannelFilter(string $channelName) + public function iChooseChannelAsAChannelFilter(string $channelName): void { $this->indexPage->chooseChannelFilter($channelName); } diff --git a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php index 5fe81977d80..54beda571f9 100644 --- a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php @@ -49,7 +49,7 @@ public function filterByTaxon(string $taxonName): void public function chooseChannelFilter(string $channelName): void { - $this->getElement('filter_channel')->selectOption($channelName); + $this->getElement('channel_filter')->selectOption($channelName); } public function hasProductAccessibleImage(string $productCode): bool @@ -72,8 +72,8 @@ public function showProductPage(string $productName): void protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ + 'channel_filter' => '#criteria_channel', 'taxon_filter' => '.sylius-tree__item a:contains("%taxon%")', - 'filter_channel' => '#criteria_channel', ]); } } From 7ac9df912f7b7cf3c0aae4cea7c0efe5d9e567d9 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Wed, 13 May 2020 09:39:41 +0200 Subject: [PATCH 5/5] experimental doc block added --- .../CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php | 3 +++ src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php index 5cfb6342a23..0e2c2a3db58 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php @@ -8,6 +8,9 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @experimental + */ final class EntitiesFilterType extends AbstractType { /** diff --git a/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php b/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php index f20c7a572f7..d8070d61842 100644 --- a/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php +++ b/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php @@ -7,6 +7,9 @@ use Sylius\Component\Grid\Data\DataSourceInterface; use Sylius\Component\Grid\Filtering\FilterInterface; +/** + * @experimental + */ final class EntitiesFilter implements FilterInterface { /**