Custom column in Product Grid not being filtered?
I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:
[2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name:
parentid_col {"exception":"[object]
(MagentoFrameworkExceptionLocalizedException(code: 0): Invalid
attribute name: parentid_col at
/html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}
Here's my code
/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component
<?xml version="1.0" encoding="utf-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Parent id</item>
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="align" xsi:type="string">left</item>
<item name="dataType" xsi:type="string">text</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
</columns>
</listing>
app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php
<?php
namespace CustomColumnAddproductcolumnUiComponentListingColumn;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoUiComponentListingColumnsColumn;
class ParentProductId extends Column
{
protected $configurable;
protected $bundle;
protected $_productFactory;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogModelProductFactory $productFactory,
MagentoConfigurableProductModelProductTypeConfigurable $configurable,
MagentoBundleModelProductType $bundle,
array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_configurable = $configurable;
$this->_bundle = $bundle;
$this->_productFactory = $productFactory;
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
if($items['type_id'] == 'simple'){
$productId = $items['entity_id'];
$parentProducts = '';
$getParent = $this->_configurable->getParentIdsByChild($productId);
$parentData = $this->_productFactory->create()->load($getParent);
$getParentSku = $parentData->getSku();
if(isset($getParentSku)){
$parentProducts .= $getParentSku;
}
$getParent = $this->_bundle->getParentIdsByChild($productId);
if(isset($getParent)){
foreach ($getParent as $p) {
$parentData = $this->_productFactory->create()->load($p);
$getParentSku = $parentData->getSku();
$parentProducts .= $getParentSku.',';
}
$items['parentid_col'] = $parentProducts;
}
}
}
}
return $dataSource;
}
}
magento2 filter magento2.2.4 product-grid
New contributor
add a comment |
I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:
[2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name:
parentid_col {"exception":"[object]
(MagentoFrameworkExceptionLocalizedException(code: 0): Invalid
attribute name: parentid_col at
/html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}
Here's my code
/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component
<?xml version="1.0" encoding="utf-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Parent id</item>
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="align" xsi:type="string">left</item>
<item name="dataType" xsi:type="string">text</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
</columns>
</listing>
app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php
<?php
namespace CustomColumnAddproductcolumnUiComponentListingColumn;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoUiComponentListingColumnsColumn;
class ParentProductId extends Column
{
protected $configurable;
protected $bundle;
protected $_productFactory;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogModelProductFactory $productFactory,
MagentoConfigurableProductModelProductTypeConfigurable $configurable,
MagentoBundleModelProductType $bundle,
array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_configurable = $configurable;
$this->_bundle = $bundle;
$this->_productFactory = $productFactory;
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
if($items['type_id'] == 'simple'){
$productId = $items['entity_id'];
$parentProducts = '';
$getParent = $this->_configurable->getParentIdsByChild($productId);
$parentData = $this->_productFactory->create()->load($getParent);
$getParentSku = $parentData->getSku();
if(isset($getParentSku)){
$parentProducts .= $getParentSku;
}
$getParent = $this->_bundle->getParentIdsByChild($productId);
if(isset($getParent)){
foreach ($getParent as $p) {
$parentData = $this->_productFactory->create()->load($p);
$getParentSku = $parentData->getSku();
$parentProducts .= $getParentSku.',';
}
$items['parentid_col'] = $parentProducts;
}
}
}
}
return $dataSource;
}
}
magento2 filter magento2.2.4 product-grid
New contributor
How did you add this attribute?
– Anshu Mishra
yesterday
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago
add a comment |
I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:
[2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name:
parentid_col {"exception":"[object]
(MagentoFrameworkExceptionLocalizedException(code: 0): Invalid
attribute name: parentid_col at
/html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}
Here's my code
/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component
<?xml version="1.0" encoding="utf-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Parent id</item>
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="align" xsi:type="string">left</item>
<item name="dataType" xsi:type="string">text</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
</columns>
</listing>
app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php
<?php
namespace CustomColumnAddproductcolumnUiComponentListingColumn;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoUiComponentListingColumnsColumn;
class ParentProductId extends Column
{
protected $configurable;
protected $bundle;
protected $_productFactory;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogModelProductFactory $productFactory,
MagentoConfigurableProductModelProductTypeConfigurable $configurable,
MagentoBundleModelProductType $bundle,
array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_configurable = $configurable;
$this->_bundle = $bundle;
$this->_productFactory = $productFactory;
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
if($items['type_id'] == 'simple'){
$productId = $items['entity_id'];
$parentProducts = '';
$getParent = $this->_configurable->getParentIdsByChild($productId);
$parentData = $this->_productFactory->create()->load($getParent);
$getParentSku = $parentData->getSku();
if(isset($getParentSku)){
$parentProducts .= $getParentSku;
}
$getParent = $this->_bundle->getParentIdsByChild($productId);
if(isset($getParent)){
foreach ($getParent as $p) {
$parentData = $this->_productFactory->create()->load($p);
$getParentSku = $parentData->getSku();
$parentProducts .= $getParentSku.',';
}
$items['parentid_col'] = $parentProducts;
}
}
}
}
return $dataSource;
}
}
magento2 filter magento2.2.4 product-grid
New contributor
I have created a custom column in Product gird by a module, which shows Parent product's SKU there. It's working fine but when I try to filter it Magento gives "Something went wrong with processing the default view and we have restored the filter to its original state." error. and in exception.log the error is:
[2019-01-03 11:33:08] main.CRITICAL: Invalid attribute name:
parentid_col {"exception":"[object]
(MagentoFrameworkExceptionLocalizedException(code: 0): Invalid
attribute name: parentid_col at
/html/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:1383)"}
Here's my code
/new.blazingglass.com/html/app/code/CustomColumn/Addproductcolumn/view/adminhtml/ui_component
<?xml version="1.0" encoding="utf-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="parentid_col" class="CustomColumnAddproductcolumnUiComponentListingColumnParentProductId">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Parent id</item>
<item name="filter" xsi:type="string">text</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="align" xsi:type="string">left</item>
<item name="dataType" xsi:type="string">text</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
</columns>
</listing>
app/code/CustomColumn/Addproductcolumn/Ui/Component/Listing/Column/ParentProductId.php
<?php
namespace CustomColumnAddproductcolumnUiComponentListingColumn;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoUiComponentListingColumnsColumn;
class ParentProductId extends Column
{
protected $configurable;
protected $bundle;
protected $_productFactory;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
MagentoCatalogModelProductFactory $productFactory,
MagentoConfigurableProductModelProductTypeConfigurable $configurable,
MagentoBundleModelProductType $bundle,
array $components = ,
array $data =
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
$this->_configurable = $configurable;
$this->_bundle = $bundle;
$this->_productFactory = $productFactory;
}
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$items) {
if($items['type_id'] == 'simple'){
$productId = $items['entity_id'];
$parentProducts = '';
$getParent = $this->_configurable->getParentIdsByChild($productId);
$parentData = $this->_productFactory->create()->load($getParent);
$getParentSku = $parentData->getSku();
if(isset($getParentSku)){
$parentProducts .= $getParentSku;
}
$getParent = $this->_bundle->getParentIdsByChild($productId);
if(isset($getParent)){
foreach ($getParent as $p) {
$parentData = $this->_productFactory->create()->load($p);
$getParentSku = $parentData->getSku();
$parentProducts .= $getParentSku.',';
}
$items['parentid_col'] = $parentProducts;
}
}
}
}
return $dataSource;
}
}
magento2 filter magento2.2.4 product-grid
magento2 filter magento2.2.4 product-grid
New contributor
New contributor
edited 22 hours ago
Tajveez Rehman
New contributor
asked yesterday
Tajveez RehmanTajveez Rehman
135
135
New contributor
New contributor
How did you add this attribute?
– Anshu Mishra
yesterday
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago
add a comment |
How did you add this attribute?
– Anshu Mishra
yesterday
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago
How did you add this attribute?
– Anshu Mishra
yesterday
How did you add this attribute?
– Anshu Mishra
yesterday
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago
add a comment |
1 Answer
1
active
oldest
votes
You need to add this below code in your ParentProductId.php file :
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256904%2fcustom-column-in-product-grid-not-being-filtered%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to add this below code in your ParentProductId.php file :
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
add a comment |
You need to add this below code in your ParentProductId.php file :
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
add a comment |
You need to add this below code in your ParentProductId.php file :
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}
You need to add this below code in your ParentProductId.php file :
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()->joinLeft
(
['custom_table_name' => $this->getTable('custom_table_name')],
'main_table.entity_id = custom_table_name.customer_id',
['filed_you_want_to_display']
);
return $this;
}
answered yesterday
Rohan HapaniRohan Hapani
5,87721662
5,87721662
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
add a comment |
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
Thanks, Rohan but I don't have a custom table for this custom attribute. what should I do in this scenario?
– Tajveez Rehman
yesterday
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
i have added this but its still giving the same error
– Tajveez Rehman
23 hours ago
add a comment |
Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
Tajveez Rehman is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256904%2fcustom-column-in-product-grid-not-being-filtered%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How did you add this attribute?
– Anshu Mishra
yesterday
@AnshuMishra i have created module to add this attribute in product listing grid
– Tajveez Rehman
23 hours ago
Please share the code that you have written to add the custom attribute.
– Anshu Mishra
23 hours ago
@AnshuMishraI I've already did that above in question's description
– Tajveez Rehman
22 hours ago