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..52afb64b14d
--- /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 get a more focused view while managing some channel's products
+ As an Administrator
+ 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" 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
+ 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 Spectre"
+
+ @ui
+ 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 Spectre"
diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php
index 15d49685478..3fafa051c71 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 :productName in channel :channel
+ * @Given the store also has a product :productName in 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..d43613723a3 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): void
+ {
+ $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..54beda571f9 100644
--- a/src/Sylius/Behat/Page/Admin/Product/IndexPage.php
+++ b/src/Sylius/Behat/Page/Admin/Product/IndexPage.php
@@ -37,11 +37,21 @@ 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('channel_filter')->selectOption($channelName);
+ }
+
public function hasProductAccessibleImage(string $productCode): bool
{
$productRow = $this->getTableAccessor()->getRowWithFields($this->getElement('table'), ['code' => $productCode]);
@@ -62,6 +72,7 @@ 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%")',
]);
}
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/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 df11eec590a..3af4945119c 100644
--- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml
+++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/product.yml
@@ -44,6 +44,13 @@ sylius_grid:
enabled:
type: boolean
label: sylius.ui.enabled
+ channel:
+ type: entities
+ label: sylius.ui.channel
+ form_options:
+ class: "%sylius.model.channel.class%"
+ options:
+ field: "channels.id"
actions:
main:
create:
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..0e2c2a3db58
--- /dev/null
+++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Grid/Filter/EntitiesFilterType.php
@@ -0,0 +1,45 @@
+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..d8070d61842
--- /dev/null
+++ b/src/Sylius/Component/Core/Grid/Filter/EntitiesFilter.php
@@ -0,0 +1,28 @@
+getExpressionBuilder();
+
+ $dataSource->restrict($expressionBuilder->equals($options['field'], $data));
+ }
+}