Skip to content

Added category products grid filter by column Product Type (Issue #28885) #29366

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

Open
wants to merge 6 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
36 changes: 34 additions & 2 deletions app/code/Magento/Catalog/Block/Adminhtml/Category/Tab/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Catalog\Model\Product\Type;
use Magento\Framework\App\ObjectManager;

class Product extends \Magento\Backend\Block\Widget\Grid\Extended
Expand All @@ -42,6 +43,11 @@ class Product extends \Magento\Backend\Block\Widget\Grid\Extended
*/
private $visibility;

/**
* @var Type
*/
private $type;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
Expand All @@ -50,6 +56,7 @@ class Product extends \Magento\Backend\Block\Widget\Grid\Extended
* @param array $data
* @param Visibility|null $visibility
* @param Status|null $status
* @param Type|null $type
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
Expand All @@ -58,17 +65,19 @@ public function __construct(
\Magento\Framework\Registry $coreRegistry,
array $data = [],
Visibility $visibility = null,
Status $status = null
Status $status = null,
Type $type = null
) {
$this->_productFactory = $productFactory;
$this->_coreRegistry = $coreRegistry;
$this->visibility = $visibility ?: ObjectManager::getInstance()->get(Visibility::class);
$this->status = $status ?: ObjectManager::getInstance()->get(Status::class);
$this->type = $type ?: ObjectManager::getInstance()->get(Type::class);
parent::__construct($context, $backendHelper, $data);
}

/**
* @return void
* @inheritdoc
*/
protected function _construct()
{
Expand All @@ -79,6 +88,8 @@ protected function _construct()
}

/**
* Retrieve current category instance
*
* @return array|null
*/
public function getCategory()
Expand All @@ -87,6 +98,8 @@ public function getCategory()
}

/**
* Add column filter to collection
*
* @param Column $column
* @return $this
*/
Expand All @@ -110,6 +123,8 @@ protected function _addColumnFilterToCollection($column)
}

/**
* Prepares collection
*
* @return Grid
*/
protected function _prepareCollection()
Expand All @@ -121,6 +136,8 @@ protected function _prepareCollection()
'name'
)->addAttributeToSelect(
'sku'
)->addAttributeToSelect(
'type_id'
)->addAttributeToSelect(
'visibility'
)->addAttributeToSelect(
Expand Down Expand Up @@ -153,6 +170,8 @@ protected function _prepareCollection()
}

/**
* Prepare columns
*
* @return Extended
*/
protected function _prepareColumns()
Expand Down Expand Up @@ -182,6 +201,15 @@ protected function _prepareColumns()
);
$this->addColumn('name', ['header' => __('Name'), 'index' => 'name']);
$this->addColumn('sku', ['header' => __('SKU'), 'index' => 'sku']);
$this->addColumn(
'type_id',
[
'header' => __('Type'),
'index' => 'type_id',
'type' => 'options',
'options' => $this->type->getOptionArray()
]
);
$this->addColumn(
'visibility',
[
Expand Down Expand Up @@ -230,6 +258,8 @@ protected function _prepareColumns()
}

/**
* Retrieve grid url
*
* @return string
*/
public function getGridUrl()
Expand All @@ -238,6 +268,8 @@ public function getGridUrl()
}

/**
* Retrieve selected products
*
* @return array
*/
protected function _getSelectedProducts()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<element name="categoryPageTitle" type="text" selector="h1.page-title" />
<element name="activeCategoryInTree" type="button" selector="//li[contains(@class, 'x-tree-node')]//div[contains(.,'{{categoryName}}') and contains(@class, 'active-category')]" parameterized="true" />
<element name="productTableColumnName" type="input" selector="#catalog_category_products_filter_name"/>
<element name="productTableColumnType" type="input" selector="#catalog_category_products_filter_type_id"/>
<element name="productTableRow" type="button" selector="#catalog_category_products_table tbody tr"/>
<element name="productSearch" type="button" selector="//button[@data-action='grid-filter-apply']" timeout="30"/>
<element name="productTableColumnSku" type="input" selector="#catalog_category_products_filter_sku"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCreateCategoryWithProductsGridFilteredByTypeTest">
<annotations>
<stories value="Create categories"/>
<title value="Add category products grid filter column type"/>
<description value="#28885 Filtering products grid at category page via product type"/>
<severity value="CRITICAL"/>
<group value="Catalog"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAdminPanel"/>
<createData entity="defaultSimpleProduct" stepKey="simpleProduct" />
</before>
<after>
<actionGroup ref="DeleteCategoryActionGroup" stepKey="deleteCategory"/>
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAdminPanel"/>
</after>

<!--Create SubCategory-->
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openAdminCategoryIndexPage"/>
<click selector="{{AdminCategorySidebarActionSection.AddSubcategoryButton}}" stepKey="clickOnAddSubCategoryButton"/>
<fillField selector="{{AdminCategoryBasicFieldSection.CategoryNameInput}}" userInput="{{_defaultCategory.name}}" stepKey="fillCategoryName"/>

<!--Search the products and select the category products-->
<scrollTo selector="{{AdminCategoryBasicFieldSection.productsInCategory}}" x="0" y="-80" stepKey="scrollToProductInCategory"/>
<click selector="{{AdminCategoryBasicFieldSection.productsInCategory}}" stepKey="clickOnProductInCategory"/>

<!--Find the simple product with grid filter via product type-->
<selectOption selector="{{AdminCategoryContentSection.productTableColumnType}}" userInput="Simple Product" stepKey="filterByProductType"/>
<click selector="{{AdminCategoryContentSection.productSearch}}" stepKey="clickSearchButton"/>

<!--Add selected product and save the category-->
<click selector="{{AdminCategoryContentSection.productTableRow}}" stepKey="selectProductFromTableRow"/>
<click selector="{{AdminCategoryMainActionsSection.SaveButton}}" stepKey="clickSaveButton"/>
<waitForPageLoad stepKey="waitForCategorySaved"/>
<actionGroup ref="AssertAdminCategorySaveSuccessMessageActionGroup" stepKey="assertSuccessMessage"/>

</test>
</tests>