Generic Class override and Problems for others Grid





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















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










share|improve this question























  • 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


















5















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










share|improve this question























  • 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














5












5








5








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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










1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer


























  • 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












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
});


}
});














draft saved

draft discarded


















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









2














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.






share|improve this answer


























  • 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
















2














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.






share|improve this answer


























  • 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














2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 10:58

























answered Mar 26 at 8:13









Amit BeraAmit Bera

60k1677178




60k1677178













  • 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



















  • 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

















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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

數位音樂下載

When can things happen in Etherscan, such as the picture below?

格利澤436b