Generic Class override and Problems for others Grid
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
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
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 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
add a comment |
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
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
17 hours ago
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
15 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
});
}
});
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
17 hours ago
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
15 hours ago
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
17 hours ago
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
15 hours ago
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 15 hours ago
answered 18 hours ago
Amit Bera♦Amit Bera
59.4k1676177
59.4k1676177
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
17 hours ago
Yes it work . i overridesales_order_grid.xml
and pastdatasource
tag in this file.
– HaFiz Umer
15 hours ago
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
17 hours ago
Yes it work . i overridesales_order_grid.xml
and pastdatasource
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
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
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