Set default filter for Customer grid during order creation in Magento2How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento - Set default filter of customer attribute in order gridMagento 2.2.5: Overriding Admin Controller sales/orderFilter Magento2 customer grid before it's loadedMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento2 filter not working for request parameter for order gridAdd a new column of “Customer Group” in a Customer grid during order creation

I want to ask company flying me out for office tour if I can bring my fiance

Can I render satellite deployment impossible, or at least impractical, by exploiting the Kessler syndrome?

How to write numbers and percentage?

How to deceive the MC

Status of proof by contradiction and excluded middle throughout the history of mathematics?

Are there guidelines for finding good names for LaTeX 2e packages and control sequences defined in these packages?

To exponential digit growth and beyond!

How can I minimize the damage of an unstable nuclear reactor to the surrounding area?

Did Game of Thrones end the way that George RR Martin intended?

Why do testers need root cause analysis?

Can flying creatures choose to hover, even if they don't have hover in their flying speed?

Is it safe to redirect stdout and stderr to the same file without file descriptor copies?

Papers on ArXiv as main references

Who wrote “A writer only begins a book. A reader finishes it.”?

Why is 'additive' EQ more difficult to use than 'subtractive'?

Are cells guaranteed to get at least one mitochondrion when they divide?

Reduce size of sum sub/superscript?

Writing "hahaha" versus describing the laugh

Moons and messages

How did the Allies achieve air superiority on Sicily?

Storing voxels for a voxel Engine in C++

How to escape dependency hell?

Why is unzipped directory exactly 4.0K (much smaller than zipped file)?

Why is this integration method not valid?



Set default filter for Customer grid during order creation in Magento2


How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento - Set default filter of customer attribute in order gridMagento 2.2.5: Overriding Admin Controller sales/orderFilter Magento2 customer grid before it's loadedMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento2 filter not working for request parameter for order gridAdd a new column of “Customer Group” in a Customer grid during order creation






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








0















I added a Customer Group column in Customer grid during order creation for Magento2, Then I filtered this grid base on Customer Group.



Customer grid filtered and it is working fine but module affected on some other grids of admin. For example "Customer Groups" grid in Customer menu doesn't load. Also "Themes" grid and "Configuration" grid in "Content" menu are not loading.



Layout file is



[vendor][module]viewadminhtmllayoutsales_order_create_customer_block.xml


Like this



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="adminhtml.customer.grid.container">
<arguments>
<argument name="dataSource" xsi:type="object">[vendor][module]ModelResourceModelOrderCustomerCollection</argument>
</arguments>
</referenceBlock>
<referenceBlock name="adminhtml.customer.grid.columnSet">
<block class="MagentoBackendBlockWidgetGridColumn" as="group" after="name">
<arguments>
<argument name="header" xsi:type="string" translate="true">Group</argument>
<argument name="index" xsi:type="string">customer_group</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>


dataSource class is



[vendor][module]ModelResourceModelOrderCustomerCollection.php


Like this:



<?php
namespace [vendor][module]ModelResourceModelOrderCustomer;
class Collection extends MagentoSalesModelResourceModelOrderCustomerCollection

protected function _initSelect()

parent::_initSelect();
$this->joinField(
'customer_group',
'customer_group',
'customer_group_code',
'customer_group_id=group_id',
null,
'left'
);
return $this;




di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoBackendBlockWidgetGrid" type="[vendor][module]BlockAdminhtmlCustomGrid" />
</config>


and this class is for filtering:



Grid.php



<?php
namespace [vendor][module]BlockAdminhtmlCustom;
use MagentoBackendBlockWidgetGrid as WidgetGrid;
class Grid extends WidgetGrid

protected function _construct()

parent::_construct();



protected function _prepareCollection()

if(!$this->getParam($this->getVarNameFilter(), null))
$this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

parent::_prepareCollection();











share|improve this question






























    0















    I added a Customer Group column in Customer grid during order creation for Magento2, Then I filtered this grid base on Customer Group.



    Customer grid filtered and it is working fine but module affected on some other grids of admin. For example "Customer Groups" grid in Customer menu doesn't load. Also "Themes" grid and "Configuration" grid in "Content" menu are not loading.



    Layout file is



    [vendor][module]viewadminhtmllayoutsales_order_create_customer_block.xml


    Like this



    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceBlock name="adminhtml.customer.grid.container">
    <arguments>
    <argument name="dataSource" xsi:type="object">[vendor][module]ModelResourceModelOrderCustomerCollection</argument>
    </arguments>
    </referenceBlock>
    <referenceBlock name="adminhtml.customer.grid.columnSet">
    <block class="MagentoBackendBlockWidgetGridColumn" as="group" after="name">
    <arguments>
    <argument name="header" xsi:type="string" translate="true">Group</argument>
    <argument name="index" xsi:type="string">customer_group</argument>
    </arguments>
    </block>
    </referenceBlock>
    </body>
    </page>


    dataSource class is



    [vendor][module]ModelResourceModelOrderCustomerCollection.php


    Like this:



    <?php
    namespace [vendor][module]ModelResourceModelOrderCustomer;
    class Collection extends MagentoSalesModelResourceModelOrderCustomerCollection

    protected function _initSelect()

    parent::_initSelect();
    $this->joinField(
    'customer_group',
    'customer_group',
    'customer_group_code',
    'customer_group_id=group_id',
    null,
    'left'
    );
    return $this;




    di.xml



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="MagentoBackendBlockWidgetGrid" type="[vendor][module]BlockAdminhtmlCustomGrid" />
    </config>


    and this class is for filtering:



    Grid.php



    <?php
    namespace [vendor][module]BlockAdminhtmlCustom;
    use MagentoBackendBlockWidgetGrid as WidgetGrid;
    class Grid extends WidgetGrid

    protected function _construct()

    parent::_construct();



    protected function _prepareCollection()

    if(!$this->getParam($this->getVarNameFilter(), null))
    $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

    parent::_prepareCollection();











    share|improve this question


























      0












      0








      0








      I added a Customer Group column in Customer grid during order creation for Magento2, Then I filtered this grid base on Customer Group.



      Customer grid filtered and it is working fine but module affected on some other grids of admin. For example "Customer Groups" grid in Customer menu doesn't load. Also "Themes" grid and "Configuration" grid in "Content" menu are not loading.



      Layout file is



      [vendor][module]viewadminhtmllayoutsales_order_create_customer_block.xml


      Like this



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
      <referenceBlock name="adminhtml.customer.grid.container">
      <arguments>
      <argument name="dataSource" xsi:type="object">[vendor][module]ModelResourceModelOrderCustomerCollection</argument>
      </arguments>
      </referenceBlock>
      <referenceBlock name="adminhtml.customer.grid.columnSet">
      <block class="MagentoBackendBlockWidgetGridColumn" as="group" after="name">
      <arguments>
      <argument name="header" xsi:type="string" translate="true">Group</argument>
      <argument name="index" xsi:type="string">customer_group</argument>
      </arguments>
      </block>
      </referenceBlock>
      </body>
      </page>


      dataSource class is



      [vendor][module]ModelResourceModelOrderCustomerCollection.php


      Like this:



      <?php
      namespace [vendor][module]ModelResourceModelOrderCustomer;
      class Collection extends MagentoSalesModelResourceModelOrderCustomerCollection

      protected function _initSelect()

      parent::_initSelect();
      $this->joinField(
      'customer_group',
      'customer_group',
      'customer_group_code',
      'customer_group_id=group_id',
      null,
      'left'
      );
      return $this;




      di.xml



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoBackendBlockWidgetGrid" type="[vendor][module]BlockAdminhtmlCustomGrid" />
      </config>


      and this class is for filtering:



      Grid.php



      <?php
      namespace [vendor][module]BlockAdminhtmlCustom;
      use MagentoBackendBlockWidgetGrid as WidgetGrid;
      class Grid extends WidgetGrid

      protected function _construct()

      parent::_construct();



      protected function _prepareCollection()

      if(!$this->getParam($this->getVarNameFilter(), null))
      $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

      parent::_prepareCollection();











      share|improve this question
















      I added a Customer Group column in Customer grid during order creation for Magento2, Then I filtered this grid base on Customer Group.



      Customer grid filtered and it is working fine but module affected on some other grids of admin. For example "Customer Groups" grid in Customer menu doesn't load. Also "Themes" grid and "Configuration" grid in "Content" menu are not loading.



      Layout file is



      [vendor][module]viewadminhtmllayoutsales_order_create_customer_block.xml


      Like this



      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <body>
      <referenceBlock name="adminhtml.customer.grid.container">
      <arguments>
      <argument name="dataSource" xsi:type="object">[vendor][module]ModelResourceModelOrderCustomerCollection</argument>
      </arguments>
      </referenceBlock>
      <referenceBlock name="adminhtml.customer.grid.columnSet">
      <block class="MagentoBackendBlockWidgetGridColumn" as="group" after="name">
      <arguments>
      <argument name="header" xsi:type="string" translate="true">Group</argument>
      <argument name="index" xsi:type="string">customer_group</argument>
      </arguments>
      </block>
      </referenceBlock>
      </body>
      </page>


      dataSource class is



      [vendor][module]ModelResourceModelOrderCustomerCollection.php


      Like this:



      <?php
      namespace [vendor][module]ModelResourceModelOrderCustomer;
      class Collection extends MagentoSalesModelResourceModelOrderCustomerCollection

      protected function _initSelect()

      parent::_initSelect();
      $this->joinField(
      'customer_group',
      'customer_group',
      'customer_group_code',
      'customer_group_id=group_id',
      null,
      'left'
      );
      return $this;




      di.xml



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <preference for="MagentoBackendBlockWidgetGrid" type="[vendor][module]BlockAdminhtmlCustomGrid" />
      </config>


      and this class is for filtering:



      Grid.php



      <?php
      namespace [vendor][module]BlockAdminhtmlCustom;
      use MagentoBackendBlockWidgetGrid as WidgetGrid;
      class Grid extends WidgetGrid

      protected function _construct()

      parent::_construct();



      protected function _prepareCollection()

      if(!$this->getParam($this->getVarNameFilter(), null))
      $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

      parent::_prepareCollection();








      magento2 sales-order order-grid customer-group customer-grid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 17 at 4:28







      samurai_code

















      asked May 16 at 2:54









      samurai_codesamurai_code

      135




      135




















          1 Answer
          1






          active

          oldest

          votes


















          0














          I solved the issue. I just added if ($layoutName == "adminhtml.customer.grid.container") in filtering function. It checks the layout, then filters only if current grid is "Customer Grid":



          Grid.php



          <?php
          namespace [vendor][module]BlockAdminhtmlCustom;
          use MagentoBackendBlockWidgetGrid as WidgetGrid;
          class Grid extends WidgetGrid

          protected function _construct()

          parent::_construct();



          protected function _prepareCollection()

          $layoutName = $this->getNameInLayout();
          if ($layoutName == "adminhtml.customer.grid.container")
          if(!$this->getParam($this->getVarNameFilter(), null))
          $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

          parent::_prepareCollection();








          share|improve this answer

























            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%2f274784%2fset-default-filter-for-customer-grid-during-order-creation-in-magento2%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









            0














            I solved the issue. I just added if ($layoutName == "adminhtml.customer.grid.container") in filtering function. It checks the layout, then filters only if current grid is "Customer Grid":



            Grid.php



            <?php
            namespace [vendor][module]BlockAdminhtmlCustom;
            use MagentoBackendBlockWidgetGrid as WidgetGrid;
            class Grid extends WidgetGrid

            protected function _construct()

            parent::_construct();



            protected function _prepareCollection()

            $layoutName = $this->getNameInLayout();
            if ($layoutName == "adminhtml.customer.grid.container")
            if(!$this->getParam($this->getVarNameFilter(), null))
            $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

            parent::_prepareCollection();








            share|improve this answer





























              0














              I solved the issue. I just added if ($layoutName == "adminhtml.customer.grid.container") in filtering function. It checks the layout, then filters only if current grid is "Customer Grid":



              Grid.php



              <?php
              namespace [vendor][module]BlockAdminhtmlCustom;
              use MagentoBackendBlockWidgetGrid as WidgetGrid;
              class Grid extends WidgetGrid

              protected function _construct()

              parent::_construct();



              protected function _prepareCollection()

              $layoutName = $this->getNameInLayout();
              if ($layoutName == "adminhtml.customer.grid.container")
              if(!$this->getParam($this->getVarNameFilter(), null))
              $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

              parent::_prepareCollection();








              share|improve this answer



























                0












                0








                0







                I solved the issue. I just added if ($layoutName == "adminhtml.customer.grid.container") in filtering function. It checks the layout, then filters only if current grid is "Customer Grid":



                Grid.php



                <?php
                namespace [vendor][module]BlockAdminhtmlCustom;
                use MagentoBackendBlockWidgetGrid as WidgetGrid;
                class Grid extends WidgetGrid

                protected function _construct()

                parent::_construct();



                protected function _prepareCollection()

                $layoutName = $this->getNameInLayout();
                if ($layoutName == "adminhtml.customer.grid.container")
                if(!$this->getParam($this->getVarNameFilter(), null))
                $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

                parent::_prepareCollection();








                share|improve this answer















                I solved the issue. I just added if ($layoutName == "adminhtml.customer.grid.container") in filtering function. It checks the layout, then filters only if current grid is "Customer Grid":



                Grid.php



                <?php
                namespace [vendor][module]BlockAdminhtmlCustom;
                use MagentoBackendBlockWidgetGrid as WidgetGrid;
                class Grid extends WidgetGrid

                protected function _construct()

                parent::_construct();



                protected function _prepareCollection()

                $layoutName = $this->getNameInLayout();
                if ($layoutName == "adminhtml.customer.grid.container")
                if(!$this->getParam($this->getVarNameFilter(), null))
                $this->getCollection()->addFieldToFilter('customer_group', array('in' => ['retailer','wholesale']));

                parent::_prepareCollection();









                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited yesterday

























                answered May 17 at 23:26









                samurai_codesamurai_code

                135




                135



























                    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%2f274784%2fset-default-filter-for-customer-grid-during-order-creation-in-magento2%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?