Generic Class override and Problems for others Grid












4















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
    18 hours ago






  • 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
    18 hours ago
















4















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
    18 hours ago






  • 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
    18 hours ago














4












4








4








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 18 hours ago









HaFiz UmerHaFiz Umer

3829




3829













  • what is your main goal?

    – magefms
    18 hours ago






  • 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
    18 hours ago



















  • what is your main goal?

    – magefms
    18 hours ago






  • 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
    18 hours ago

















what is your main goal?

– magefms
18 hours ago





what is your main goal?

– magefms
18 hours ago




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
18 hours ago





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
18 hours ago










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
    17 hours ago











  • Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

    – HaFiz Umer
    15 hours ago











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
    17 hours ago











  • Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

    – HaFiz Umer
    15 hours ago
















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
    17 hours ago











  • Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

    – HaFiz Umer
    15 hours ago














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 15 hours ago

























answered 18 hours ago









Amit BeraAmit Bera

59.4k1676177




59.4k1676177













  • 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
    17 hours ago











  • Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

    – HaFiz Umer
    15 hours ago



















  • 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
    17 hours ago











  • Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

    – HaFiz Umer
    15 hours ago

















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
17 hours ago





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
17 hours ago













Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

– HaFiz Umer
15 hours ago





Yes it work . i override sales_order_grid.xml and past datasource tag in this file.

– HaFiz Umer
15 hours ago


















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

He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

Bunad

Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum