Get products where multiselect value is false The 2019 Stack Overflow Developer Survey Results Are InHow 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

Why do UK politicians seemingly ignore opinion polls on Brexit?

Shouldn't "much" here be used instead of "more"?

If a Druid sees an animal’s corpse, can they wild shape into that animal?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

How to support a colleague who finds meetings extremely tiring?

What is the meaning of Triage in Cybersec world?

Have you ever entered Singapore using a different passport or name?

Is three citations per paragraph excessive for undergraduate research paper?

What is the most effective way of iterating a std::vector and why?

How to type this arrow in math mode?

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Aging parents with no investments

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Button changing it's text & action. Good or terrible?

Falsification in Math vs Science

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Earliest use of the term "Galois extension"?

Write faster on AT24C32

Who coined the term "madman theory"?

What is the accessibility of a package's `Private` context variables?

Multiply Two Integer Polynomials

Is bread bad for ducks?

Deal with toxic manager when you can't quit

How to deal with fear of taking dependencies



Get products where multiselect value is false



The 2019 Stack Overflow Developer Survey Results Are InHow 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 yesterday









      Morgan TartreauMorgan Tartreau

      39312




      39312




















          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
            yesterday











          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
            yesterday















          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
            yesterday













          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 yesterday

























          answered yesterday









          Siarhey UchukhlebauSiarhey Uchukhlebau

          10k93058




          10k93058












          • 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
            yesterday

















          • 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
            yesterday
















          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
          yesterday





          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
          yesterday

















          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

          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?