Filtering with magento2





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







1















I have problem with magento2 FilterGroupBuilder. I need to set filter where active_until date is between today and March 3 OR active_until before January 5. My code looks like:



public function dot4()
{
$filter = $this->filterBuilder
->setConditionType('gteq')
->setField('active_until')
->setValue(date("Y-m-d H:i:s"))
->create();
$filter = $this->filterBuilder
->setConditionType('lteq')
->setField('active_until')
->setValue(date("Y-m-d H:i:s", strtotime('March 3')))
->create();
$filter = $this->filterBuilder
->setConditionType('lt')
->setField('active_until')
->setValue(date("Y-m-d H:i:s", strtotime('January 5')))
->create();

$filter_group = [
$this->filterGroupBuilder
->addFilter($filter[0])
->create(),
$this->filterGroupBuilder
->addFilter($filter[1])
->create(),
$this->filterGroupBuilder
->addFilter($filter[2])
->create(),
];

$this->searchCriteriaBuilder->setFilterGroups($filter_group);

$list = $this->vendorInterface->getList(
$this->searchCriteriaBuilder->create()
)->getItems();

return $list;
}


And MySQL query shows:



'SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:06:25')) AND ((`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))' (length=216)


If i change $filter_group to that structure:



    $filter_group = [
$this->filterGroupBuilder
->addFilter($filter[0])
->addFilter($filter[1])
->create(),
$this->filterGroupBuilder
->addFilter($filter[2])
->create(),
];


Query:



SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') OR (`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))


But still it's not a solution...
So how to group filters to show query like this:



SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') AND (`active_until` <= '2016-03-03 00:00:00')) OR ((`active_until` < '2016-01-05 00:00:00'))









share|improve this question














bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    1















    I have problem with magento2 FilterGroupBuilder. I need to set filter where active_until date is between today and March 3 OR active_until before January 5. My code looks like:



    public function dot4()
    {
    $filter = $this->filterBuilder
    ->setConditionType('gteq')
    ->setField('active_until')
    ->setValue(date("Y-m-d H:i:s"))
    ->create();
    $filter = $this->filterBuilder
    ->setConditionType('lteq')
    ->setField('active_until')
    ->setValue(date("Y-m-d H:i:s", strtotime('March 3')))
    ->create();
    $filter = $this->filterBuilder
    ->setConditionType('lt')
    ->setField('active_until')
    ->setValue(date("Y-m-d H:i:s", strtotime('January 5')))
    ->create();

    $filter_group = [
    $this->filterGroupBuilder
    ->addFilter($filter[0])
    ->create(),
    $this->filterGroupBuilder
    ->addFilter($filter[1])
    ->create(),
    $this->filterGroupBuilder
    ->addFilter($filter[2])
    ->create(),
    ];

    $this->searchCriteriaBuilder->setFilterGroups($filter_group);

    $list = $this->vendorInterface->getList(
    $this->searchCriteriaBuilder->create()
    )->getItems();

    return $list;
    }


    And MySQL query shows:



    'SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:06:25')) AND ((`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))' (length=216)


    If i change $filter_group to that structure:



        $filter_group = [
    $this->filterGroupBuilder
    ->addFilter($filter[0])
    ->addFilter($filter[1])
    ->create(),
    $this->filterGroupBuilder
    ->addFilter($filter[2])
    ->create(),
    ];


    Query:



    SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') OR (`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))


    But still it's not a solution...
    So how to group filters to show query like this:



    SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') AND (`active_until` <= '2016-03-03 00:00:00')) OR ((`active_until` < '2016-01-05 00:00:00'))









    share|improve this question














    bumped to the homepage by Community 1 hour ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1








      I have problem with magento2 FilterGroupBuilder. I need to set filter where active_until date is between today and March 3 OR active_until before January 5. My code looks like:



      public function dot4()
      {
      $filter = $this->filterBuilder
      ->setConditionType('gteq')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s"))
      ->create();
      $filter = $this->filterBuilder
      ->setConditionType('lteq')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s", strtotime('March 3')))
      ->create();
      $filter = $this->filterBuilder
      ->setConditionType('lt')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s", strtotime('January 5')))
      ->create();

      $filter_group = [
      $this->filterGroupBuilder
      ->addFilter($filter[0])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[1])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[2])
      ->create(),
      ];

      $this->searchCriteriaBuilder->setFilterGroups($filter_group);

      $list = $this->vendorInterface->getList(
      $this->searchCriteriaBuilder->create()
      )->getItems();

      return $list;
      }


      And MySQL query shows:



      'SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:06:25')) AND ((`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))' (length=216)


      If i change $filter_group to that structure:



          $filter_group = [
      $this->filterGroupBuilder
      ->addFilter($filter[0])
      ->addFilter($filter[1])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[2])
      ->create(),
      ];


      Query:



      SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') OR (`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))


      But still it's not a solution...
      So how to group filters to show query like this:



      SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') AND (`active_until` <= '2016-03-03 00:00:00')) OR ((`active_until` < '2016-01-05 00:00:00'))









      share|improve this question














      I have problem with magento2 FilterGroupBuilder. I need to set filter where active_until date is between today and March 3 OR active_until before January 5. My code looks like:



      public function dot4()
      {
      $filter = $this->filterBuilder
      ->setConditionType('gteq')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s"))
      ->create();
      $filter = $this->filterBuilder
      ->setConditionType('lteq')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s", strtotime('March 3')))
      ->create();
      $filter = $this->filterBuilder
      ->setConditionType('lt')
      ->setField('active_until')
      ->setValue(date("Y-m-d H:i:s", strtotime('January 5')))
      ->create();

      $filter_group = [
      $this->filterGroupBuilder
      ->addFilter($filter[0])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[1])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[2])
      ->create(),
      ];

      $this->searchCriteriaBuilder->setFilterGroups($filter_group);

      $list = $this->vendorInterface->getList(
      $this->searchCriteriaBuilder->create()
      )->getItems();

      return $list;
      }


      And MySQL query shows:



      'SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:06:25')) AND ((`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))' (length=216)


      If i change $filter_group to that structure:



          $filter_group = [
      $this->filterGroupBuilder
      ->addFilter($filter[0])
      ->addFilter($filter[1])
      ->create(),
      $this->filterGroupBuilder
      ->addFilter($filter[2])
      ->create(),
      ];


      Query:



      SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') OR (`active_until` <= '2016-03-03 00:00:00')) AND ((`active_until` < '2016-01-05 00:00:00'))


      But still it's not a solution...
      So how to group filters to show query like this:



      SELECT `main_table`.* FROM `Training5_VendorRepository` AS `main_table` WHERE ((`active_until` >= '2016-01-29 12:13:38') AND (`active_until` <= '2016-03-03 00:00:00')) OR ((`active_until` < '2016-01-05 00:00:00'))






      magento2 database






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 29 '16 at 12:47









      Szymon SzczypkowskiSzymon Szczypkowski

      61




      61





      bumped to the homepage by Community 1 hour ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 1 hour ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          try this



          $filter_group = [
          $this->filterGroupBuilder
          ->addFilter($filter[0])
          ->create(),
          $this->filterGroupBuilder
          ->addFilter($filter[1])
          ->addFilter($filter[2])
          ->create(),
          ];





          share|improve this answer
























          • It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

            – Szymon Szczypkowski
            Jan 29 '16 at 13:42











          • I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

            – ciemin
            Jan 29 '16 at 15:46



















          0














          This doesnt work anymore on 2.1.3
          https://github.com/magento/magento2/issues/8300



          Please reference that ticket






          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%2f99575%2ffiltering-with-magento2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            try this



            $filter_group = [
            $this->filterGroupBuilder
            ->addFilter($filter[0])
            ->create(),
            $this->filterGroupBuilder
            ->addFilter($filter[1])
            ->addFilter($filter[2])
            ->create(),
            ];





            share|improve this answer
























            • It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

              – Szymon Szczypkowski
              Jan 29 '16 at 13:42











            • I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

              – ciemin
              Jan 29 '16 at 15:46
















            0














            try this



            $filter_group = [
            $this->filterGroupBuilder
            ->addFilter($filter[0])
            ->create(),
            $this->filterGroupBuilder
            ->addFilter($filter[1])
            ->addFilter($filter[2])
            ->create(),
            ];





            share|improve this answer
























            • It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

              – Szymon Szczypkowski
              Jan 29 '16 at 13:42











            • I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

              – ciemin
              Jan 29 '16 at 15:46














            0












            0








            0







            try this



            $filter_group = [
            $this->filterGroupBuilder
            ->addFilter($filter[0])
            ->create(),
            $this->filterGroupBuilder
            ->addFilter($filter[1])
            ->addFilter($filter[2])
            ->create(),
            ];





            share|improve this answer













            try this



            $filter_group = [
            $this->filterGroupBuilder
            ->addFilter($filter[0])
            ->create(),
            $this->filterGroupBuilder
            ->addFilter($filter[1])
            ->addFilter($filter[2])
            ->create(),
            ];






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 29 '16 at 13:27









            cieminciemin

            120129




            120129













            • It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

              – Szymon Szczypkowski
              Jan 29 '16 at 13:42











            • I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

              – ciemin
              Jan 29 '16 at 15:46



















            • It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

              – Szymon Szczypkowski
              Jan 29 '16 at 13:42











            • I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

              – ciemin
              Jan 29 '16 at 15:46

















            It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

            – Szymon Szczypkowski
            Jan 29 '16 at 13:42





            It shows: SELECT main_table.* FROM Training5_VendorRepository AS main_table WHERE ((active_until >= '2016-01-29 13:31:12')) AND ((active_until <= '2016-03-03 00:00:00') OR (active_until < '2016-01-05 00:00:00')) but still don't show (active_until < '2016-01-05 00:00:00') rows.

            – Szymon Szczypkowski
            Jan 29 '16 at 13:42













            I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

            – ciemin
            Jan 29 '16 at 15:46





            I believe your query is [p v (q ^ r)]. Its equal to [(p v q) ^ (p v r)] and this one you can create with searchCriteriaBuilder.

            – ciemin
            Jan 29 '16 at 15:46













            0














            This doesnt work anymore on 2.1.3
            https://github.com/magento/magento2/issues/8300



            Please reference that ticket






            share|improve this answer




























              0














              This doesnt work anymore on 2.1.3
              https://github.com/magento/magento2/issues/8300



              Please reference that ticket






              share|improve this answer


























                0












                0








                0







                This doesnt work anymore on 2.1.3
                https://github.com/magento/magento2/issues/8300



                Please reference that ticket






                share|improve this answer













                This doesnt work anymore on 2.1.3
                https://github.com/magento/magento2/issues/8300



                Please reference that ticket







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 27 '17 at 0:23









                CodeNinjaCodeNinja

                111




                111






























                    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%2f99575%2ffiltering-with-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

                    What other Star Trek series did the main TNG cast show up in?

                    Berlina muro

                    Berlina aerponto