Generic Class override and Problems for others Grid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Actually i had override the generic class to filter the orders for sales order grid.
<preference for="MagentoFrameworkViewElementUiComponentDataProviderDataProvider" type="VendorNameModuleNameViewElementUiComponentDataProviderDataProvider"/>
It create problem for me in others grid like invoice grid
, Shipment grid
etc
My code is there for filter order
protected function searchResultToOutput(SearchResultInterface $searchResult)
{
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser=$this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null){
if (in_array($currentUser, explode(",", $row['current_seller_id']))){
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords']=$this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
These lines of code work perfectly order filter as i neend. But create problem for other grids. it can be solve by 2 way.
1 ) To put if() condition for custom code it should true if request come from Sales>Order and false
if request come from other pages invoice
or shipment
how can get order page URL
for making codition.
2 ) Second is don't override the generic
class . Try to filter order array an others way . In Which class::method we can filter orders array like i filter inDataProvider
class.
Please guide me which is better in my case and how do that .
Thanks in advance
magento2 filter orderarray
add a comment |
Actually i had override the generic class to filter the orders for sales order grid.
<preference for="MagentoFrameworkViewElementUiComponentDataProviderDataProvider" type="VendorNameModuleNameViewElementUiComponentDataProviderDataProvider"/>
It create problem for me in others grid like invoice grid
, Shipment grid
etc
My code is there for filter order
protected function searchResultToOutput(SearchResultInterface $searchResult)
{
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser=$this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null){
if (in_array($currentUser, explode(",", $row['current_seller_id']))){
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords']=$this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
These lines of code work perfectly order filter as i neend. But create problem for other grids. it can be solve by 2 way.
1 ) To put if() condition for custom code it should true if request come from Sales>Order and false
if request come from other pages invoice
or shipment
how can get order page URL
for making codition.
2 ) Second is don't override the generic
class . Try to filter order array an others way . In Which class::method we can filter orders array like i filter inDataProvider
class.
Please guide me which is better in my case and how do that .
Thanks in advance
magento2 filter orderarray
what is your main goal?
– magefms
Mar 26 at 8:07
1
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42
add a comment |
Actually i had override the generic class to filter the orders for sales order grid.
<preference for="MagentoFrameworkViewElementUiComponentDataProviderDataProvider" type="VendorNameModuleNameViewElementUiComponentDataProviderDataProvider"/>
It create problem for me in others grid like invoice grid
, Shipment grid
etc
My code is there for filter order
protected function searchResultToOutput(SearchResultInterface $searchResult)
{
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser=$this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null){
if (in_array($currentUser, explode(",", $row['current_seller_id']))){
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords']=$this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
These lines of code work perfectly order filter as i neend. But create problem for other grids. it can be solve by 2 way.
1 ) To put if() condition for custom code it should true if request come from Sales>Order and false
if request come from other pages invoice
or shipment
how can get order page URL
for making codition.
2 ) Second is don't override the generic
class . Try to filter order array an others way . In Which class::method we can filter orders array like i filter inDataProvider
class.
Please guide me which is better in my case and how do that .
Thanks in advance
magento2 filter orderarray
Actually i had override the generic class to filter the orders for sales order grid.
<preference for="MagentoFrameworkViewElementUiComponentDataProviderDataProvider" type="VendorNameModuleNameViewElementUiComponentDataProviderDataProvider"/>
It create problem for me in others grid like invoice grid
, Shipment grid
etc
My code is there for filter order
protected function searchResultToOutput(SearchResultInterface $searchResult)
{
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser=$this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null){
if (in_array($currentUser, explode(",", $row['current_seller_id']))){
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords']=$this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
These lines of code work perfectly order filter as i neend. But create problem for other grids. it can be solve by 2 way.
1 ) To put if() condition for custom code it should true if request come from Sales>Order and false
if request come from other pages invoice
or shipment
how can get order page URL
for making codition.
2 ) Second is don't override the generic
class . Try to filter order array an others way . In Which class::method we can filter orders array like i filter inDataProvider
class.
Please guide me which is better in my case and how do that .
Thanks in advance
magento2 filter orderarray
magento2 filter orderarray
asked Mar 26 at 8:02
HaFiz UmerHaFiz Umer
4319
4319
what is your main goal?
– magefms
Mar 26 at 8:07
1
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42
add a comment |
what is your main goal?
– magefms
Mar 26 at 8:07
1
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42
what is your main goal?
– magefms
Mar 26 at 8:07
what is your main goal?
– magefms
Mar 26 at 8:07
1
1
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42
add a comment |
1 Answer
1
active
oldest
votes
As per, my idea first one is not a good idea to override a class.
My suggestion to change the data provider the class of this grid
.
means changes like
<dataProvider class="MagentoFrameworkViewElementUiComponentDataProviderDataProvider"
to
<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider"
that is the best process.
Code of New UI Data provider class:
<?php
namespace StackExchangeMagentoUiElementUiComponentDataProvider;
class DataProvider extends MagentoFrameworkViewElementUiComponentDataProviderDataProvider {
protected function searchResultToOutput(MagentoFrameworkApiSearchSearchResultInterface $searchResult) {
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser = $this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null) {
if (in_array($currentUser, explode(",", $row['current_seller_id']))) {
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords'] = $this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
}
Also override sales_order_grid.xml
and past datasource tag in this file.
you mean to say override thevendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?
– HaFiz Umer
Mar 26 at 9:41
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
Mar 26 at 10:48
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
});
}
});
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%2f267375%2fgeneric-class-override-and-problems-for-others-grid%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
As per, my idea first one is not a good idea to override a class.
My suggestion to change the data provider the class of this grid
.
means changes like
<dataProvider class="MagentoFrameworkViewElementUiComponentDataProviderDataProvider"
to
<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider"
that is the best process.
Code of New UI Data provider class:
<?php
namespace StackExchangeMagentoUiElementUiComponentDataProvider;
class DataProvider extends MagentoFrameworkViewElementUiComponentDataProviderDataProvider {
protected function searchResultToOutput(MagentoFrameworkApiSearchSearchResultInterface $searchResult) {
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser = $this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null) {
if (in_array($currentUser, explode(",", $row['current_seller_id']))) {
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords'] = $this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
}
Also override sales_order_grid.xml
and past datasource tag in this file.
you mean to say override thevendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?
– HaFiz Umer
Mar 26 at 9:41
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
Mar 26 at 10:48
add a comment |
As per, my idea first one is not a good idea to override a class.
My suggestion to change the data provider the class of this grid
.
means changes like
<dataProvider class="MagentoFrameworkViewElementUiComponentDataProviderDataProvider"
to
<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider"
that is the best process.
Code of New UI Data provider class:
<?php
namespace StackExchangeMagentoUiElementUiComponentDataProvider;
class DataProvider extends MagentoFrameworkViewElementUiComponentDataProviderDataProvider {
protected function searchResultToOutput(MagentoFrameworkApiSearchSearchResultInterface $searchResult) {
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser = $this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null) {
if (in_array($currentUser, explode(",", $row['current_seller_id']))) {
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords'] = $this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
}
Also override sales_order_grid.xml
and past datasource tag in this file.
you mean to say override thevendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?
– HaFiz Umer
Mar 26 at 9:41
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
Mar 26 at 10:48
add a comment |
As per, my idea first one is not a good idea to override a class.
My suggestion to change the data provider the class of this grid
.
means changes like
<dataProvider class="MagentoFrameworkViewElementUiComponentDataProviderDataProvider"
to
<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider"
that is the best process.
Code of New UI Data provider class:
<?php
namespace StackExchangeMagentoUiElementUiComponentDataProvider;
class DataProvider extends MagentoFrameworkViewElementUiComponentDataProviderDataProvider {
protected function searchResultToOutput(MagentoFrameworkApiSearchSearchResultInterface $searchResult) {
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser = $this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null) {
if (in_array($currentUser, explode(",", $row['current_seller_id']))) {
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords'] = $this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
}
Also override sales_order_grid.xml
and past datasource tag in this file.
As per, my idea first one is not a good idea to override a class.
My suggestion to change the data provider the class of this grid
.
means changes like
<dataProvider class="MagentoFrameworkViewElementUiComponentDataProviderDataProvider"
to
<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider"
that is the best process.
Code of New UI Data provider class:
<?php
namespace StackExchangeMagentoUiElementUiComponentDataProvider;
class DataProvider extends MagentoFrameworkViewElementUiComponentDataProviderDataProvider {
protected function searchResultToOutput(MagentoFrameworkApiSearchSearchResultInterface $searchResult) {
$arrItems = ;
$arrItems['items'] = ;
foreach ($searchResult->getItems() as $item) {
$itemData = ;
foreach ($item->getCustomAttributes() as $attribute) {
$itemData[$attribute->getAttributeCode()] = $attribute->getValue();
}
$arrItems['items'] = $itemData;
$arrItems['totalRecords'] = $searchResult->getTotalCount();
}
//custom code//
$currentUser = $this->getCurrentUserId();
$seller_order_arr = ;
foreach ($arrItems['items'] as $row) {
if ($row['current_seller_id'] != null) {
if (in_array($currentUser, explode(",", $row['current_seller_id']))) {
$seller_order_arr = $row;
}
}
}
$arrItems['items'] = $seller_order_arr;
$arrItems['totalRecords'] = $this->getTotalOrder($seller_order_arr);
// end custom code//
return $arrItems;
}
}
Also override sales_order_grid.xml
and past datasource tag in this file.
edited Mar 26 at 10:58
answered Mar 26 at 8:13
Amit Bera♦Amit Bera
60k1677178
60k1677178
you mean to say override thevendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?
– HaFiz Umer
Mar 26 at 9:41
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
Mar 26 at 10:48
add a comment |
you mean to say override thevendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line<dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?
– HaFiz Umer
Mar 26 at 9:41
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
Mar 26 at 10:48
you mean to say override the
vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line <dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?– HaFiz Umer
Mar 26 at 9:41
you mean to say override the
vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml
file and give past this line <dataProvider class="{Vendor}{ModuleName}UiElementUiComponentDataProviderDataProvider
?– HaFiz Umer
Mar 26 at 9:41
Yes it work . i override
sales_order_grid.xml
and past datasource
tag in this file.– HaFiz Umer
Mar 26 at 10:48
Yes it work . i override
sales_order_grid.xml
and past datasource
tag in this file.– HaFiz Umer
Mar 26 at 10:48
add a comment |
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.
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%2f267375%2fgeneric-class-override-and-problems-for-others-grid%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
what is your main goal?
– magefms
Mar 26 at 8:07
1
Actually i make multi vendor site. i filter orders as my code show every seller can view own product order. in the quest i upload code that filter. each seller see own order not others order
– HaFiz Umer
Mar 26 at 8:11
Your code has you overriding EVERY data provider. You rarely, if ever, need to override any data provider, certainly not everyone of them. Depending on which one it is, you can just add your ModifierInterface and do what you need with minimal intrusion.
– Shawn Abramson
Mar 27 at 4:42