Magento 2: Get list of products on basis of attribute codeGet color values used in productsCode for filtering products by attributes?Get Products list with all product attributes in MagentoCan't get custom attribute from getUsedProductsCreate Dropdown Attribute for ProductsHow to list attributes for all SKUs in the system? My code only shows half productsGet product attribute on product list in one queryList products by dropdown attributeMagento 2.2 - How can I pass the color attribute from the category list to the product detail page?Get list of all modules using code in Magento 2

What is the meaning of "prairie-dog" in this sentence?

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

Can one block with a protection from color creature?

Category-theoretic treatment of diffs, patches and merging?

Is there an In-Universe reason why Thor and the Asgardians think Rocket is a rabbit?

Writing an ace/aro character?

Why did Robert F. Kennedy loathe Lyndon B. Johnson?

US citizen traveling with Peruvian passport

Findminimum of Integral

Chilling water in copper vessel

How can I know how much authority/decision making power etc I have as an employee?

My previous employer committed a severe violation of the law and is also being sued by me. How do I explain the situation to future employers?

Run Bash scripts in folder all at the same time

This LM317 diagram doesn't make any sense to me

Did depressed people far more accurately estimate how many monsters they killed in a video game?

With a data transfer of 50 GB estimated 5 hours, are USB-C claimed speeds inaccurate or to blame?

Matrices with shadows

When do flights get cancelled due to fog?

What is the average number of draws it takes before you can not draw any more cards from the Deck of Many Things?

Appropriate conduit for several data cables underground over 300' run

Is there a formal/better word than "skyrocket" for the given context?

What factors could lead to bishops establishing monastic armies?

Is this really the Saturn V computer only, or are there other systems here as well?

Blocks from @ jafe



Magento 2: Get list of products on basis of attribute code


Get color values used in productsCode for filtering products by attributes?Get Products list with all product attributes in MagentoCan't get custom attribute from getUsedProductsCreate Dropdown Attribute for ProductsHow to list attributes for all SKUs in the system? My code only shows half productsGet product attribute on product list in one queryList products by dropdown attributeMagento 2.2 - How can I pass the color attribute from the category list to the product detail page?Get list of all modules using code in Magento 2






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








0















Is there any way I can fetch list of products having a attribute_code.



For eg:
Getting list of all products which has attribute color










share|improve this question




























    0















    Is there any way I can fetch list of products having a attribute_code.



    For eg:
    Getting list of all products which has attribute color










    share|improve this question
























      0












      0








      0








      Is there any way I can fetch list of products having a attribute_code.



      For eg:
      Getting list of all products which has attribute color










      share|improve this question














      Is there any way I can fetch list of products having a attribute_code.



      For eg:
      Getting list of all products which has attribute color







      product-attribute magento2.2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 16 '17 at 9:37









      DEEP JOSHIDEEP JOSHI

      3561 gold badge5 silver badges24 bronze badges




      3561 gold badge5 silver badges24 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use below code to filter your product collection if the product has color attribute.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $productCollection = $objectManager->get("MagentoCatalogModelProduct")->getCollection();

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter(
          array(
          array('attribute'=> 'color','notnull' => true),
          array('attribute'=> 'color','neq' => ''),
          array('attribute'=> 'color','neq' => 'NO FIELD'),
          ),'','left'
          );

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);


          If you want to filter specific option of any attribute. (red option of color attribute), then you can simply filter your products as below.



          $attributes = $objectManager->create('MagentoEavApiAttributeRepositoryInterface');
          $color = $attributes->get(MagentoCatalogModelProduct::ENTITY, 'color');
          $optionId = $color->getSource()->getOptionId('red');

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter('color',$optionId);

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);



          Note : It's a good practice to use objectManager by dependency
          injection.







          share|improve this answer

























          • Can you please elaborate your code?

            – DEEP JOSHI
            Oct 16 '17 at 10:14











          • Above code will filter those products which have not null or blank value in color attribute.

            – Dinesh Yadav
            Oct 16 '17 at 10:23











          • I am not getting list of product ids here.

            – DEEP JOSHI
            Oct 16 '17 at 10:26











          • post your code in question.

            – Dinesh Yadav
            Oct 16 '17 at 10:33











          • I need help with code to get product ids on from attribute code.

            – DEEP JOSHI
            Oct 16 '17 at 11:13














          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%2f197408%2fmagento-2-get-list-of-products-on-basis-of-attribute-code%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














          You can use below code to filter your product collection if the product has color attribute.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $productCollection = $objectManager->get("MagentoCatalogModelProduct")->getCollection();

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter(
          array(
          array('attribute'=> 'color','notnull' => true),
          array('attribute'=> 'color','neq' => ''),
          array('attribute'=> 'color','neq' => 'NO FIELD'),
          ),'','left'
          );

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);


          If you want to filter specific option of any attribute. (red option of color attribute), then you can simply filter your products as below.



          $attributes = $objectManager->create('MagentoEavApiAttributeRepositoryInterface');
          $color = $attributes->get(MagentoCatalogModelProduct::ENTITY, 'color');
          $optionId = $color->getSource()->getOptionId('red');

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter('color',$optionId);

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);



          Note : It's a good practice to use objectManager by dependency
          injection.







          share|improve this answer

























          • Can you please elaborate your code?

            – DEEP JOSHI
            Oct 16 '17 at 10:14











          • Above code will filter those products which have not null or blank value in color attribute.

            – Dinesh Yadav
            Oct 16 '17 at 10:23











          • I am not getting list of product ids here.

            – DEEP JOSHI
            Oct 16 '17 at 10:26











          • post your code in question.

            – Dinesh Yadav
            Oct 16 '17 at 10:33











          • I need help with code to get product ids on from attribute code.

            – DEEP JOSHI
            Oct 16 '17 at 11:13
















          0














          You can use below code to filter your product collection if the product has color attribute.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $productCollection = $objectManager->get("MagentoCatalogModelProduct")->getCollection();

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter(
          array(
          array('attribute'=> 'color','notnull' => true),
          array('attribute'=> 'color','neq' => ''),
          array('attribute'=> 'color','neq' => 'NO FIELD'),
          ),'','left'
          );

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);


          If you want to filter specific option of any attribute. (red option of color attribute), then you can simply filter your products as below.



          $attributes = $objectManager->create('MagentoEavApiAttributeRepositoryInterface');
          $color = $attributes->get(MagentoCatalogModelProduct::ENTITY, 'color');
          $optionId = $color->getSource()->getOptionId('red');

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter('color',$optionId);

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);



          Note : It's a good practice to use objectManager by dependency
          injection.







          share|improve this answer

























          • Can you please elaborate your code?

            – DEEP JOSHI
            Oct 16 '17 at 10:14











          • Above code will filter those products which have not null or blank value in color attribute.

            – Dinesh Yadav
            Oct 16 '17 at 10:23











          • I am not getting list of product ids here.

            – DEEP JOSHI
            Oct 16 '17 at 10:26











          • post your code in question.

            – Dinesh Yadav
            Oct 16 '17 at 10:33











          • I need help with code to get product ids on from attribute code.

            – DEEP JOSHI
            Oct 16 '17 at 11:13














          0












          0








          0







          You can use below code to filter your product collection if the product has color attribute.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $productCollection = $objectManager->get("MagentoCatalogModelProduct")->getCollection();

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter(
          array(
          array('attribute'=> 'color','notnull' => true),
          array('attribute'=> 'color','neq' => ''),
          array('attribute'=> 'color','neq' => 'NO FIELD'),
          ),'','left'
          );

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);


          If you want to filter specific option of any attribute. (red option of color attribute), then you can simply filter your products as below.



          $attributes = $objectManager->create('MagentoEavApiAttributeRepositoryInterface');
          $color = $attributes->get(MagentoCatalogModelProduct::ENTITY, 'color');
          $optionId = $color->getSource()->getOptionId('red');

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter('color',$optionId);

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);



          Note : It's a good practice to use objectManager by dependency
          injection.







          share|improve this answer















          You can use below code to filter your product collection if the product has color attribute.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $productCollection = $objectManager->get("MagentoCatalogModelProduct")->getCollection();

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter(
          array(
          array('attribute'=> 'color','notnull' => true),
          array('attribute'=> 'color','neq' => ''),
          array('attribute'=> 'color','neq' => 'NO FIELD'),
          ),'','left'
          );

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);


          If you want to filter specific option of any attribute. (red option of color attribute), then you can simply filter your products as below.



          $attributes = $objectManager->create('MagentoEavApiAttributeRepositoryInterface');
          $color = $attributes->get(MagentoCatalogModelProduct::ENTITY, 'color');
          $optionId = $color->getSource()->getOptionId('red');

          $productCollection->addAttributeToSelect("color")->addAttributeToFilter('color',$optionId);

          $productIds = array();

          foreach ($productCollection as $product)
          $productIds[] = $product->getId();


          print_r($productIds);



          Note : It's a good practice to use objectManager by dependency
          injection.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 17 '17 at 9:07

























          answered Oct 16 '17 at 10:06









          Dinesh YadavDinesh Yadav

          4,2641 gold badge9 silver badges37 bronze badges




          4,2641 gold badge9 silver badges37 bronze badges












          • Can you please elaborate your code?

            – DEEP JOSHI
            Oct 16 '17 at 10:14











          • Above code will filter those products which have not null or blank value in color attribute.

            – Dinesh Yadav
            Oct 16 '17 at 10:23











          • I am not getting list of product ids here.

            – DEEP JOSHI
            Oct 16 '17 at 10:26











          • post your code in question.

            – Dinesh Yadav
            Oct 16 '17 at 10:33











          • I need help with code to get product ids on from attribute code.

            – DEEP JOSHI
            Oct 16 '17 at 11:13


















          • Can you please elaborate your code?

            – DEEP JOSHI
            Oct 16 '17 at 10:14











          • Above code will filter those products which have not null or blank value in color attribute.

            – Dinesh Yadav
            Oct 16 '17 at 10:23











          • I am not getting list of product ids here.

            – DEEP JOSHI
            Oct 16 '17 at 10:26











          • post your code in question.

            – Dinesh Yadav
            Oct 16 '17 at 10:33











          • I need help with code to get product ids on from attribute code.

            – DEEP JOSHI
            Oct 16 '17 at 11:13

















          Can you please elaborate your code?

          – DEEP JOSHI
          Oct 16 '17 at 10:14





          Can you please elaborate your code?

          – DEEP JOSHI
          Oct 16 '17 at 10:14













          Above code will filter those products which have not null or blank value in color attribute.

          – Dinesh Yadav
          Oct 16 '17 at 10:23





          Above code will filter those products which have not null or blank value in color attribute.

          – Dinesh Yadav
          Oct 16 '17 at 10:23













          I am not getting list of product ids here.

          – DEEP JOSHI
          Oct 16 '17 at 10:26





          I am not getting list of product ids here.

          – DEEP JOSHI
          Oct 16 '17 at 10:26













          post your code in question.

          – Dinesh Yadav
          Oct 16 '17 at 10:33





          post your code in question.

          – Dinesh Yadav
          Oct 16 '17 at 10:33













          I need help with code to get product ids on from attribute code.

          – DEEP JOSHI
          Oct 16 '17 at 11:13






          I need help with code to get product ids on from attribute code.

          – DEEP JOSHI
          Oct 16 '17 at 11:13


















          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%2f197408%2fmagento-2-get-list-of-products-on-basis-of-attribute-code%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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form