Get products where multiselect value is false The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to set selected value in multiselect attributeCollection with FIND_IN_SET on multiselect attributes, but some has only one valueGet selected multiselect attribute values for one producthow to get attribute values (select type) from a product collection?Set multiple multiselect values for productIs it possible to use text swatches as multiselect on category pages? (Magento 2)product grid renderer multiselect attribute valueRetrieve multiselect values for all productsMagento Get Attribute values Collection by filterM1.9x How can I reset 1 multiselect attribute for *all* products

What force causes entropy to increase?

What's the point in a preamp?

Did the new image of black hole confirm the general theory of relativity?

Was credit for the black hole image misappropriated?

Student Loan from years ago pops up and is taking my salary

"... to apply for a visa" or "... and applied for a visa"?

Can the Right Ascension and Argument of Perigee of a spacecraft's orbit keep varying by themselves with time?

Why are PDP-7-style microprogrammed instructions out of vogue?

University's motivation for having tenure-track positions

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Why can't wing-mounted spoilers be used to steepen approaches?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Using dividends to reduce short term capital gains?

Working through the single responsibility principle (SRP) in Python when calls are expensive

Single author papers against my advisor's will?

What is the padding with red substance inside of steak packaging?

Keeping a retro style to sci-fi spaceships?

Simulating Exploding Dice

Do warforged have souls?

"is" operation returns false even though two objects have same id

Word for: a synonym with a positive connotation?

Can the DM override racial traits?

Do I have Disadvantage attacking with an off-hand weapon?

How to support a colleague who finds meetings extremely tiring?



Get products where multiselect value is false



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to set selected value in multiselect attributeCollection with FIND_IN_SET on multiselect attributes, but some has only one valueGet selected multiselect attribute values for one producthow to get attribute values (select type) from a product collection?Set multiple multiselect values for productIs it possible to use text swatches as multiselect on category pages? (Magento 2)product grid renderer multiselect attribute valueRetrieve multiselect values for all productsMagento Get Attribute values Collection by filterM1.9x How can I reset 1 multiselect attribute for *all* products



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








0















how can I get products where the value of a multiselect is not set ?



I've got these so far :



$filter =
array(
array('eq' => array("378")), //multiselect with one value
array('eq' => array("378,379")), //multiselect with 2 values
array('eq' => false), //multiselect with no value, need to make this work
);

$collection->addAttributeToFilter( "multiselect", $filter );









share|improve this question




























    0















    how can I get products where the value of a multiselect is not set ?



    I've got these so far :



    $filter =
    array(
    array('eq' => array("378")), //multiselect with one value
    array('eq' => array("378,379")), //multiselect with 2 values
    array('eq' => false), //multiselect with no value, need to make this work
    );

    $collection->addAttributeToFilter( "multiselect", $filter );









    share|improve this question
























      0












      0








      0








      how can I get products where the value of a multiselect is not set ?



      I've got these so far :



      $filter =
      array(
      array('eq' => array("378")), //multiselect with one value
      array('eq' => array("378,379")), //multiselect with 2 values
      array('eq' => false), //multiselect with no value, need to make this work
      );

      $collection->addAttributeToFilter( "multiselect", $filter );









      share|improve this question














      how can I get products where the value of a multiselect is not set ?



      I've got these so far :



      $filter =
      array(
      array('eq' => array("378")), //multiselect with one value
      array('eq' => array("378,379")), //multiselect with 2 values
      array('eq' => false), //multiselect with no value, need to make this work
      );

      $collection->addAttributeToFilter( "multiselect", $filter );






      magento2 attributes multiselect-attribute






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 9 at 9:13









      Morgan TartreauMorgan Tartreau

      408112




      408112




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Try this:



          $filter =
          array(
          array('eq' => array("378")), // multiselect with one value
          array('eq' => array("378,379")), // multiselect with 2 values
          array('null' => true), // multiselect with no value (null value)
          );

          $collection->addAttributeToFilter( "multiselect", $filter );


          Update:



          here is how it will work using the SearchCriteria with the product repository (tested on the custom attribute available_shipping_methods having a multiselect input type):



          use MagentoCatalogApiProductRepositoryInterface;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchFilterGroupBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilderFactory;
          use MagentoFrameworkAppActionAction;
          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkAppResponseInterface;

          /**
          * Class Search
          */
          class Search extends Action

          /**
          * @var ProductRepositoryInterface
          */
          private $productRepository;

          /**
          * @var SearchCriteriaBuilderFactory
          */
          private $searchCriteriaBuilderFactory;

          /**
          * @var FilterBuilder
          */
          private $filterBuilder;

          /**
          * @var FilterGroupBuilder
          */
          private $filterGroupBuilder;

          /**
          * Search constructor.
          *
          * @param Context $context
          * @param ProductRepositoryInterface $productRepository
          * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
          * @param FilterBuilder $filterBuilder
          * @param FilterGroupBuilder $filterGroupBuilder
          */
          public function __construct(
          Context $context,
          ProductRepositoryInterface $productRepository,
          SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
          FilterBuilder $filterBuilder,
          FilterGroupBuilder $filterGroupBuilder
          )
          parent::__construct($context);
          $this->productRepository = $productRepository;
          $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
          $this->filterBuilder = $filterBuilder;
          $this->filterGroupBuilder = $filterGroupBuilder;


          /**
          * Execute action based on request and return result
          *
          * Note: Request will be added as operation argument in future
          *
          * @return MagentoFrameworkControllerResultInterface


          Result query looks like this (our conditions at the last line):



          SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status`, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) AS `available_shipping_methods`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
          INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`row_id` = `e`.`row_id`) AND (`at_visibility_default`.`attribute_id` = '99') AND `at_visibility_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`row_id` = `e`.`row_id`) AND (`at_visibility`.`attribute_id` = '99') AND (`at_visibility`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_text` AS `at_available_shipping_methods_default` ON (`at_available_shipping_methods_default`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods_default`.`attribute_id` = '265') AND `at_available_shipping_methods_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_text` AS `at_available_shipping_methods` ON (`at_available_shipping_methods`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods`.`attribute_id` = '265') AND (`at_available_shipping_methods`.`store_id` = 1)
          INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (((IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%shipping_shipping%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%flatrate_flatrate%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) IS NULL))) AND (e.created_in <= 1) AND (e.updated_in > 1)


          and result itself contains products with desired attribute value and without value at all (null).



          PS: a comma-separated value of the multiselect attribute is the main problem, because of that we need to use %LIKE% condition, what is not a good idea.






          share|improve this answer

























          • Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

            – Morgan Tartreau
            Apr 9 at 12:41











          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%2f269338%2fget-products-where-multiselect-value-is-false%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














          Try this:



          $filter =
          array(
          array('eq' => array("378")), // multiselect with one value
          array('eq' => array("378,379")), // multiselect with 2 values
          array('null' => true), // multiselect with no value (null value)
          );

          $collection->addAttributeToFilter( "multiselect", $filter );


          Update:



          here is how it will work using the SearchCriteria with the product repository (tested on the custom attribute available_shipping_methods having a multiselect input type):



          use MagentoCatalogApiProductRepositoryInterface;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchFilterGroupBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilderFactory;
          use MagentoFrameworkAppActionAction;
          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkAppResponseInterface;

          /**
          * Class Search
          */
          class Search extends Action

          /**
          * @var ProductRepositoryInterface
          */
          private $productRepository;

          /**
          * @var SearchCriteriaBuilderFactory
          */
          private $searchCriteriaBuilderFactory;

          /**
          * @var FilterBuilder
          */
          private $filterBuilder;

          /**
          * @var FilterGroupBuilder
          */
          private $filterGroupBuilder;

          /**
          * Search constructor.
          *
          * @param Context $context
          * @param ProductRepositoryInterface $productRepository
          * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
          * @param FilterBuilder $filterBuilder
          * @param FilterGroupBuilder $filterGroupBuilder
          */
          public function __construct(
          Context $context,
          ProductRepositoryInterface $productRepository,
          SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
          FilterBuilder $filterBuilder,
          FilterGroupBuilder $filterGroupBuilder
          )
          parent::__construct($context);
          $this->productRepository = $productRepository;
          $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
          $this->filterBuilder = $filterBuilder;
          $this->filterGroupBuilder = $filterGroupBuilder;


          /**
          * Execute action based on request and return result
          *
          * Note: Request will be added as operation argument in future
          *
          * @return MagentoFrameworkControllerResultInterface


          Result query looks like this (our conditions at the last line):



          SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status`, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) AS `available_shipping_methods`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
          INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`row_id` = `e`.`row_id`) AND (`at_visibility_default`.`attribute_id` = '99') AND `at_visibility_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`row_id` = `e`.`row_id`) AND (`at_visibility`.`attribute_id` = '99') AND (`at_visibility`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_text` AS `at_available_shipping_methods_default` ON (`at_available_shipping_methods_default`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods_default`.`attribute_id` = '265') AND `at_available_shipping_methods_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_text` AS `at_available_shipping_methods` ON (`at_available_shipping_methods`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods`.`attribute_id` = '265') AND (`at_available_shipping_methods`.`store_id` = 1)
          INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (((IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%shipping_shipping%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%flatrate_flatrate%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) IS NULL))) AND (e.created_in <= 1) AND (e.updated_in > 1)


          and result itself contains products with desired attribute value and without value at all (null).



          PS: a comma-separated value of the multiselect attribute is the main problem, because of that we need to use %LIKE% condition, what is not a good idea.






          share|improve this answer

























          • Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

            – Morgan Tartreau
            Apr 9 at 12:41















          0














          Try this:



          $filter =
          array(
          array('eq' => array("378")), // multiselect with one value
          array('eq' => array("378,379")), // multiselect with 2 values
          array('null' => true), // multiselect with no value (null value)
          );

          $collection->addAttributeToFilter( "multiselect", $filter );


          Update:



          here is how it will work using the SearchCriteria with the product repository (tested on the custom attribute available_shipping_methods having a multiselect input type):



          use MagentoCatalogApiProductRepositoryInterface;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchFilterGroupBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilderFactory;
          use MagentoFrameworkAppActionAction;
          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkAppResponseInterface;

          /**
          * Class Search
          */
          class Search extends Action

          /**
          * @var ProductRepositoryInterface
          */
          private $productRepository;

          /**
          * @var SearchCriteriaBuilderFactory
          */
          private $searchCriteriaBuilderFactory;

          /**
          * @var FilterBuilder
          */
          private $filterBuilder;

          /**
          * @var FilterGroupBuilder
          */
          private $filterGroupBuilder;

          /**
          * Search constructor.
          *
          * @param Context $context
          * @param ProductRepositoryInterface $productRepository
          * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
          * @param FilterBuilder $filterBuilder
          * @param FilterGroupBuilder $filterGroupBuilder
          */
          public function __construct(
          Context $context,
          ProductRepositoryInterface $productRepository,
          SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
          FilterBuilder $filterBuilder,
          FilterGroupBuilder $filterGroupBuilder
          )
          parent::__construct($context);
          $this->productRepository = $productRepository;
          $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
          $this->filterBuilder = $filterBuilder;
          $this->filterGroupBuilder = $filterGroupBuilder;


          /**
          * Execute action based on request and return result
          *
          * Note: Request will be added as operation argument in future
          *
          * @return MagentoFrameworkControllerResultInterface


          Result query looks like this (our conditions at the last line):



          SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status`, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) AS `available_shipping_methods`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
          INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`row_id` = `e`.`row_id`) AND (`at_visibility_default`.`attribute_id` = '99') AND `at_visibility_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`row_id` = `e`.`row_id`) AND (`at_visibility`.`attribute_id` = '99') AND (`at_visibility`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_text` AS `at_available_shipping_methods_default` ON (`at_available_shipping_methods_default`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods_default`.`attribute_id` = '265') AND `at_available_shipping_methods_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_text` AS `at_available_shipping_methods` ON (`at_available_shipping_methods`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods`.`attribute_id` = '265') AND (`at_available_shipping_methods`.`store_id` = 1)
          INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (((IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%shipping_shipping%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%flatrate_flatrate%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) IS NULL))) AND (e.created_in <= 1) AND (e.updated_in > 1)


          and result itself contains products with desired attribute value and without value at all (null).



          PS: a comma-separated value of the multiselect attribute is the main problem, because of that we need to use %LIKE% condition, what is not a good idea.






          share|improve this answer

























          • Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

            – Morgan Tartreau
            Apr 9 at 12:41













          0












          0








          0







          Try this:



          $filter =
          array(
          array('eq' => array("378")), // multiselect with one value
          array('eq' => array("378,379")), // multiselect with 2 values
          array('null' => true), // multiselect with no value (null value)
          );

          $collection->addAttributeToFilter( "multiselect", $filter );


          Update:



          here is how it will work using the SearchCriteria with the product repository (tested on the custom attribute available_shipping_methods having a multiselect input type):



          use MagentoCatalogApiProductRepositoryInterface;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchFilterGroupBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilderFactory;
          use MagentoFrameworkAppActionAction;
          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkAppResponseInterface;

          /**
          * Class Search
          */
          class Search extends Action

          /**
          * @var ProductRepositoryInterface
          */
          private $productRepository;

          /**
          * @var SearchCriteriaBuilderFactory
          */
          private $searchCriteriaBuilderFactory;

          /**
          * @var FilterBuilder
          */
          private $filterBuilder;

          /**
          * @var FilterGroupBuilder
          */
          private $filterGroupBuilder;

          /**
          * Search constructor.
          *
          * @param Context $context
          * @param ProductRepositoryInterface $productRepository
          * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
          * @param FilterBuilder $filterBuilder
          * @param FilterGroupBuilder $filterGroupBuilder
          */
          public function __construct(
          Context $context,
          ProductRepositoryInterface $productRepository,
          SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
          FilterBuilder $filterBuilder,
          FilterGroupBuilder $filterGroupBuilder
          )
          parent::__construct($context);
          $this->productRepository = $productRepository;
          $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
          $this->filterBuilder = $filterBuilder;
          $this->filterGroupBuilder = $filterGroupBuilder;


          /**
          * Execute action based on request and return result
          *
          * Note: Request will be added as operation argument in future
          *
          * @return MagentoFrameworkControllerResultInterface


          Result query looks like this (our conditions at the last line):



          SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status`, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) AS `available_shipping_methods`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
          INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`row_id` = `e`.`row_id`) AND (`at_visibility_default`.`attribute_id` = '99') AND `at_visibility_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`row_id` = `e`.`row_id`) AND (`at_visibility`.`attribute_id` = '99') AND (`at_visibility`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_text` AS `at_available_shipping_methods_default` ON (`at_available_shipping_methods_default`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods_default`.`attribute_id` = '265') AND `at_available_shipping_methods_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_text` AS `at_available_shipping_methods` ON (`at_available_shipping_methods`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods`.`attribute_id` = '265') AND (`at_available_shipping_methods`.`store_id` = 1)
          INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (((IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%shipping_shipping%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%flatrate_flatrate%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) IS NULL))) AND (e.created_in <= 1) AND (e.updated_in > 1)


          and result itself contains products with desired attribute value and without value at all (null).



          PS: a comma-separated value of the multiselect attribute is the main problem, because of that we need to use %LIKE% condition, what is not a good idea.






          share|improve this answer















          Try this:



          $filter =
          array(
          array('eq' => array("378")), // multiselect with one value
          array('eq' => array("378,379")), // multiselect with 2 values
          array('null' => true), // multiselect with no value (null value)
          );

          $collection->addAttributeToFilter( "multiselect", $filter );


          Update:



          here is how it will work using the SearchCriteria with the product repository (tested on the custom attribute available_shipping_methods having a multiselect input type):



          use MagentoCatalogApiProductRepositoryInterface;
          use MagentoFrameworkApiFilterBuilder;
          use MagentoFrameworkApiSearchFilterGroupBuilder;
          use MagentoFrameworkApiSearchCriteriaBuilderFactory;
          use MagentoFrameworkAppActionAction;
          use MagentoFrameworkAppActionContext;
          use MagentoFrameworkAppResponseInterface;

          /**
          * Class Search
          */
          class Search extends Action

          /**
          * @var ProductRepositoryInterface
          */
          private $productRepository;

          /**
          * @var SearchCriteriaBuilderFactory
          */
          private $searchCriteriaBuilderFactory;

          /**
          * @var FilterBuilder
          */
          private $filterBuilder;

          /**
          * @var FilterGroupBuilder
          */
          private $filterGroupBuilder;

          /**
          * Search constructor.
          *
          * @param Context $context
          * @param ProductRepositoryInterface $productRepository
          * @param SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory
          * @param FilterBuilder $filterBuilder
          * @param FilterGroupBuilder $filterGroupBuilder
          */
          public function __construct(
          Context $context,
          ProductRepositoryInterface $productRepository,
          SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
          FilterBuilder $filterBuilder,
          FilterGroupBuilder $filterGroupBuilder
          )
          parent::__construct($context);
          $this->productRepository = $productRepository;
          $this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
          $this->filterBuilder = $filterBuilder;
          $this->filterGroupBuilder = $filterGroupBuilder;


          /**
          * Execute action based on request and return result
          *
          * Note: Request will be added as operation argument in future
          *
          * @return MagentoFrameworkControllerResultInterface


          Result query looks like this (our conditions at the last line):



          SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status`, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`, IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) AS `available_shipping_methods`, `stock_status_index`.`stock_status` AS `is_salable` FROM `catalog_product_entity` AS `e`
          INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '97') AND `at_status_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '97') AND (`at_status`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`row_id` = `e`.`row_id`) AND (`at_visibility_default`.`attribute_id` = '99') AND `at_visibility_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`row_id` = `e`.`row_id`) AND (`at_visibility`.`attribute_id` = '99') AND (`at_visibility`.`store_id` = 1)
          INNER JOIN `catalog_product_entity_text` AS `at_available_shipping_methods_default` ON (`at_available_shipping_methods_default`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods_default`.`attribute_id` = '265') AND `at_available_shipping_methods_default`.`store_id` = 0
          LEFT JOIN `catalog_product_entity_text` AS `at_available_shipping_methods` ON (`at_available_shipping_methods`.`row_id` = `e`.`row_id`) AND (`at_available_shipping_methods`.`attribute_id` = '265') AND (`at_available_shipping_methods`.`store_id` = 1)
          INNER JOIN `cataloginventory_stock_status` AS `stock_status_index` ON e.entity_id = stock_status_index.product_id WHERE (((IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%shipping_shipping%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) LIKE '%flatrate_flatrate%') OR (IF(at_available_shipping_methods.value_id > 0, at_available_shipping_methods.value, at_available_shipping_methods_default.value) IS NULL))) AND (e.created_in <= 1) AND (e.updated_in > 1)


          and result itself contains products with desired attribute value and without value at all (null).



          PS: a comma-separated value of the multiselect attribute is the main problem, because of that we need to use %LIKE% condition, what is not a good idea.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 9 at 10:54

























          answered Apr 9 at 9:22









          Siarhey UchukhlebauSiarhey Uchukhlebau

          10.1k93058




          10.1k93058












          • Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

            – Morgan Tartreau
            Apr 9 at 12:41

















          • Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

            – Morgan Tartreau
            Apr 9 at 12:41
















          Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

          – Morgan Tartreau
          Apr 9 at 12:41





          Ok I'll try, but I think I'll just add the two options for each of my concerned products (like 2 options == 0 options)

          – Morgan Tartreau
          Apr 9 at 12:41

















          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%2f269338%2fget-products-where-multiselect-value-is-false%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

          Sum ergo cogito? 1 nng

          三茅街道4182Guuntc Dn precexpngmageondP