How to get product stock status on the listing page in Magento 2?how to get the stock status without loading the whole product-efficient wayMagento 2 : How to get the product attributes based on attribute set id on listing pageCustom Attribute Value not getting in Category Page in Magento 2Getting value from product attributes in Magento 2Stock status and back orders in Magento 2Magento 1.9 Update stock product status with sql queryProduct doesn't change stock status until after the page reloadMagento2 Showing a custom attribute on category listing pageHow to truncate product name properly in Magento 2?Magento 2 Inventory and Stock Status

Markov-chain sentence generator in Python

Symbol: Put a smile symbol under a plus

What is the farthest a camera can see?

The cat exchanges places with a drawing of the cat

Failover strategy for SQL Server 2016 Standard Edition

Reimplementation of min() in Python

Why am I not billed for EOB balance?

Is it okay to write non-offensive humor into meeting minutes?

Simplification of numbers

Can lodestones be used to magnetize crude iron weapons?

Who invented Monoid?

How much can I judge a company based on a phone screening?

How do you deal with the emotions of not being the one to find the cause of a bug?

How should I write this passage to make it the most readable?

Boss asked a co-worker to assault me

Why is there a large performance impact when looping over an array over 240 elements?

Why is statically linking glibc discouraged?

Why command hierarchy, if the chain of command is standing next to each other?

How is являться different from есть and быть

What is the hottest thing in the universe?

Do Reform Jews believe in a theistic God?

How was the murder committed?

Do beef farmed pastures net remove carbon emissions?

Case Condition for two lines



How to get product stock status on the listing page in Magento 2?


how to get the stock status without loading the whole product-efficient wayMagento 2 : How to get the product attributes based on attribute set id on listing pageCustom Attribute Value not getting in Category Page in Magento 2Getting value from product attributes in Magento 2Stock status and back orders in Magento 2Magento 1.9 Update stock product status with sql queryProduct doesn't change stock status until after the page reloadMagento2 Showing a custom attribute on category listing pageHow to truncate product name properly in Magento 2?Magento 2 Inventory and Stock Status






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








0















I am using Magento 2.3.1



I want to display stock status on the listing page. So, how can I get "Stock Status" attribute value on the listing page?



I have tried below code:



<?php 
$_productCollection = $block->getLoadedProductCollection();
foreach ($_productCollection as $_product)

$stock_status = $_product->getResource()->getAttribute('quantity_and_stock_status')->getFrontend()->getValue($_product);


?>


And tried below as well:



<?php 
$_productCollection = $block->getLoadedProductCollection();
foreach ($_productCollection as $_product)

$default_stock_status = $_product->getData('quantity_and_stock_status');


?>


But for each scenario, I got "Out of stock" even though the product is in stock
here quantity_and_stock_status is the default "Stock Status" attribute.



enter image description here










share|improve this question
































    0















    I am using Magento 2.3.1



    I want to display stock status on the listing page. So, how can I get "Stock Status" attribute value on the listing page?



    I have tried below code:



    <?php 
    $_productCollection = $block->getLoadedProductCollection();
    foreach ($_productCollection as $_product)

    $stock_status = $_product->getResource()->getAttribute('quantity_and_stock_status')->getFrontend()->getValue($_product);


    ?>


    And tried below as well:



    <?php 
    $_productCollection = $block->getLoadedProductCollection();
    foreach ($_productCollection as $_product)

    $default_stock_status = $_product->getData('quantity_and_stock_status');


    ?>


    But for each scenario, I got "Out of stock" even though the product is in stock
    here quantity_and_stock_status is the default "Stock Status" attribute.



    enter image description here










    share|improve this question




























      0












      0








      0








      I am using Magento 2.3.1



      I want to display stock status on the listing page. So, how can I get "Stock Status" attribute value on the listing page?



      I have tried below code:



      <?php 
      $_productCollection = $block->getLoadedProductCollection();
      foreach ($_productCollection as $_product)

      $stock_status = $_product->getResource()->getAttribute('quantity_and_stock_status')->getFrontend()->getValue($_product);


      ?>


      And tried below as well:



      <?php 
      $_productCollection = $block->getLoadedProductCollection();
      foreach ($_productCollection as $_product)

      $default_stock_status = $_product->getData('quantity_and_stock_status');


      ?>


      But for each scenario, I got "Out of stock" even though the product is in stock
      here quantity_and_stock_status is the default "Stock Status" attribute.



      enter image description here










      share|improve this question
















      I am using Magento 2.3.1



      I want to display stock status on the listing page. So, how can I get "Stock Status" attribute value on the listing page?



      I have tried below code:



      <?php 
      $_productCollection = $block->getLoadedProductCollection();
      foreach ($_productCollection as $_product)

      $stock_status = $_product->getResource()->getAttribute('quantity_and_stock_status')->getFrontend()->getValue($_product);


      ?>


      And tried below as well:



      <?php 
      $_productCollection = $block->getLoadedProductCollection();
      foreach ($_productCollection as $_product)

      $default_stock_status = $_product->getData('quantity_and_stock_status');


      ?>


      But for each scenario, I got "Out of stock" even though the product is in stock
      here quantity_and_stock_status is the default "Stock Status" attribute.



      enter image description here







      magento2 product inventory stock-status stock-availability






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 2 at 7:13









      Sameer Bhayani

      9475 silver badges21 bronze badges




      9475 silver badges21 bronze badges










      asked Aug 2 at 7:03









      Chintan KaneriyaChintan Kaneriya

      4232 silver badges14 bronze badges




      4232 silver badges14 bronze badges























          4 Answers
          4






          active

          oldest

          votes


















          3














          Inject MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository, in constructor



          e.g:



          protected $_stockItemRepository;

          public function __construct(
          MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
          )

          $this->_stockItemRepository = $stockItemRepository;



          Use function to get stock data using product id



          public function getStockItem($productId)

          return $this->_stockItemRepository->get($productId);



          Then you may call in your phtml file



          $id = YOUR_PRODUCT_ID;
          $productStock = $block->getStockItem(1225);
          echo $productStock->getQty(); echo '<br />';
          echo $productStock->getMinQty(); echo '<br />';
          echo $productStock->getMinSaleQty(); echo '<br />';
          echo $productStock->getMaxSaleQty(); echo '<br />';
          echo $productStock->getIsInStock(); echo '<br />';


          Source: http://blog.chapagain.com.np/magento-2-get-product-stock-quantity-and-other-stock-information/






          share|improve this answer
































            3














            Note:- Object Manager is not recommended way.




            You can inject class in your constructor this way




            <?php 
            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $_productCollection = $block->getLoadedProductCollection();

            foreach ($_productCollection as $_product)

            $StockState = $objectManager->get('MagentoCatalogInventoryModelStockStockItemRepository');

            $StockState->get($_product->getId());
            echo $StockState->getIsInStock();


            ?>





            share|improve this answer
































              3














              You can try the following code



              public function __construct(
              MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
              )
              $this->stockRegistry = $stockRegistry;

              // you can pass $product object to the function
              public function getStockStatus($product)

              return $this->stockRegistry->getStockItem($product->getId());



              You can get all the stock details by



              $stockItem = $this->stockRegistry->getStockItem($product->getId());
              $stockData = $stockItem->getData();
              $stockItem->getIsInStock();


              Hope it helps.






              share|improve this answer



























              • I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                – Chintan Kaneriya
                Aug 2 at 7:09











              • you can use getIsInStock() method

                – Mohit Rane
                Aug 2 at 7:14











              • to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                – Mohit Rane
                Aug 2 at 7:16











              • check updated answer

                – Mohit Rane
                Aug 2 at 7:46


















              3














              If you are using the only simple products at your system then using Stock Status field check then Product status is Ok.



              But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status.



              That is this, use of $_product->isAvailable() and $_product->isSaleable() is the best idea.See at https://github.com/devamitbera/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/list.phtml#L80






              share|improve this answer

























              • correct! need to check for $_product->isSaleable()

                – Ketan Borada
                Aug 2 at 9:40











              • @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                – Chintan Kaneriya
                Aug 3 at 3:30













              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%2f284176%2fhow-to-get-product-stock-status-on-the-listing-page-in-magento-2%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Inject MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository, in constructor



              e.g:



              protected $_stockItemRepository;

              public function __construct(
              MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
              )

              $this->_stockItemRepository = $stockItemRepository;



              Use function to get stock data using product id



              public function getStockItem($productId)

              return $this->_stockItemRepository->get($productId);



              Then you may call in your phtml file



              $id = YOUR_PRODUCT_ID;
              $productStock = $block->getStockItem(1225);
              echo $productStock->getQty(); echo '<br />';
              echo $productStock->getMinQty(); echo '<br />';
              echo $productStock->getMinSaleQty(); echo '<br />';
              echo $productStock->getMaxSaleQty(); echo '<br />';
              echo $productStock->getIsInStock(); echo '<br />';


              Source: http://blog.chapagain.com.np/magento-2-get-product-stock-quantity-and-other-stock-information/






              share|improve this answer





























                3














                Inject MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository, in constructor



                e.g:



                protected $_stockItemRepository;

                public function __construct(
                MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
                )

                $this->_stockItemRepository = $stockItemRepository;



                Use function to get stock data using product id



                public function getStockItem($productId)

                return $this->_stockItemRepository->get($productId);



                Then you may call in your phtml file



                $id = YOUR_PRODUCT_ID;
                $productStock = $block->getStockItem(1225);
                echo $productStock->getQty(); echo '<br />';
                echo $productStock->getMinQty(); echo '<br />';
                echo $productStock->getMinSaleQty(); echo '<br />';
                echo $productStock->getMaxSaleQty(); echo '<br />';
                echo $productStock->getIsInStock(); echo '<br />';


                Source: http://blog.chapagain.com.np/magento-2-get-product-stock-quantity-and-other-stock-information/






                share|improve this answer



























                  3












                  3








                  3







                  Inject MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository, in constructor



                  e.g:



                  protected $_stockItemRepository;

                  public function __construct(
                  MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
                  )

                  $this->_stockItemRepository = $stockItemRepository;



                  Use function to get stock data using product id



                  public function getStockItem($productId)

                  return $this->_stockItemRepository->get($productId);



                  Then you may call in your phtml file



                  $id = YOUR_PRODUCT_ID;
                  $productStock = $block->getStockItem(1225);
                  echo $productStock->getQty(); echo '<br />';
                  echo $productStock->getMinQty(); echo '<br />';
                  echo $productStock->getMinSaleQty(); echo '<br />';
                  echo $productStock->getMaxSaleQty(); echo '<br />';
                  echo $productStock->getIsInStock(); echo '<br />';


                  Source: http://blog.chapagain.com.np/magento-2-get-product-stock-quantity-and-other-stock-information/






                  share|improve this answer













                  Inject MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository, in constructor



                  e.g:



                  protected $_stockItemRepository;

                  public function __construct(
                  MagentoCatalogInventoryModelStockStockItemRepository $stockItemRepository
                  )

                  $this->_stockItemRepository = $stockItemRepository;



                  Use function to get stock data using product id



                  public function getStockItem($productId)

                  return $this->_stockItemRepository->get($productId);



                  Then you may call in your phtml file



                  $id = YOUR_PRODUCT_ID;
                  $productStock = $block->getStockItem(1225);
                  echo $productStock->getQty(); echo '<br />';
                  echo $productStock->getMinQty(); echo '<br />';
                  echo $productStock->getMinSaleQty(); echo '<br />';
                  echo $productStock->getMaxSaleQty(); echo '<br />';
                  echo $productStock->getIsInStock(); echo '<br />';


                  Source: http://blog.chapagain.com.np/magento-2-get-product-stock-quantity-and-other-stock-information/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 2 at 7:10









                  Sameer BhayaniSameer Bhayani

                  9475 silver badges21 bronze badges




                  9475 silver badges21 bronze badges


























                      3














                      Note:- Object Manager is not recommended way.




                      You can inject class in your constructor this way




                      <?php 
                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $_productCollection = $block->getLoadedProductCollection();

                      foreach ($_productCollection as $_product)

                      $StockState = $objectManager->get('MagentoCatalogInventoryModelStockStockItemRepository');

                      $StockState->get($_product->getId());
                      echo $StockState->getIsInStock();


                      ?>





                      share|improve this answer





























                        3














                        Note:- Object Manager is not recommended way.




                        You can inject class in your constructor this way




                        <?php 
                        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                        $_productCollection = $block->getLoadedProductCollection();

                        foreach ($_productCollection as $_product)

                        $StockState = $objectManager->get('MagentoCatalogInventoryModelStockStockItemRepository');

                        $StockState->get($_product->getId());
                        echo $StockState->getIsInStock();


                        ?>





                        share|improve this answer



























                          3












                          3








                          3







                          Note:- Object Manager is not recommended way.




                          You can inject class in your constructor this way




                          <?php 
                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $_productCollection = $block->getLoadedProductCollection();

                          foreach ($_productCollection as $_product)

                          $StockState = $objectManager->get('MagentoCatalogInventoryModelStockStockItemRepository');

                          $StockState->get($_product->getId());
                          echo $StockState->getIsInStock();


                          ?>





                          share|improve this answer













                          Note:- Object Manager is not recommended way.




                          You can inject class in your constructor this way




                          <?php 
                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $_productCollection = $block->getLoadedProductCollection();

                          foreach ($_productCollection as $_product)

                          $StockState = $objectManager->get('MagentoCatalogInventoryModelStockStockItemRepository');

                          $StockState->get($_product->getId());
                          echo $StockState->getIsInStock();


                          ?>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 2 at 7:16









                          Limbani HimanshuLimbani Himanshu

                          3321 silver badge9 bronze badges




                          3321 silver badge9 bronze badges
























                              3














                              You can try the following code



                              public function __construct(
                              MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
                              )
                              $this->stockRegistry = $stockRegistry;

                              // you can pass $product object to the function
                              public function getStockStatus($product)

                              return $this->stockRegistry->getStockItem($product->getId());



                              You can get all the stock details by



                              $stockItem = $this->stockRegistry->getStockItem($product->getId());
                              $stockData = $stockItem->getData();
                              $stockItem->getIsInStock();


                              Hope it helps.






                              share|improve this answer



























                              • I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                                – Chintan Kaneriya
                                Aug 2 at 7:09











                              • you can use getIsInStock() method

                                – Mohit Rane
                                Aug 2 at 7:14











                              • to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                                – Mohit Rane
                                Aug 2 at 7:16











                              • check updated answer

                                – Mohit Rane
                                Aug 2 at 7:46















                              3














                              You can try the following code



                              public function __construct(
                              MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
                              )
                              $this->stockRegistry = $stockRegistry;

                              // you can pass $product object to the function
                              public function getStockStatus($product)

                              return $this->stockRegistry->getStockItem($product->getId());



                              You can get all the stock details by



                              $stockItem = $this->stockRegistry->getStockItem($product->getId());
                              $stockData = $stockItem->getData();
                              $stockItem->getIsInStock();


                              Hope it helps.






                              share|improve this answer



























                              • I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                                – Chintan Kaneriya
                                Aug 2 at 7:09











                              • you can use getIsInStock() method

                                – Mohit Rane
                                Aug 2 at 7:14











                              • to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                                – Mohit Rane
                                Aug 2 at 7:16











                              • check updated answer

                                – Mohit Rane
                                Aug 2 at 7:46













                              3












                              3








                              3







                              You can try the following code



                              public function __construct(
                              MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
                              )
                              $this->stockRegistry = $stockRegistry;

                              // you can pass $product object to the function
                              public function getStockStatus($product)

                              return $this->stockRegistry->getStockItem($product->getId());



                              You can get all the stock details by



                              $stockItem = $this->stockRegistry->getStockItem($product->getId());
                              $stockData = $stockItem->getData();
                              $stockItem->getIsInStock();


                              Hope it helps.






                              share|improve this answer















                              You can try the following code



                              public function __construct(
                              MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
                              )
                              $this->stockRegistry = $stockRegistry;

                              // you can pass $product object to the function
                              public function getStockStatus($product)

                              return $this->stockRegistry->getStockItem($product->getId());



                              You can get all the stock details by



                              $stockItem = $this->stockRegistry->getStockItem($product->getId());
                              $stockData = $stockItem->getData();
                              $stockItem->getIsInStock();


                              Hope it helps.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 2 at 8:05

























                              answered Aug 2 at 7:07









                              Mohit RaneMohit Rane

                              1,20718 bronze badges




                              1,20718 bronze badges















                              • I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                                – Chintan Kaneriya
                                Aug 2 at 7:09











                              • you can use getIsInStock() method

                                – Mohit Rane
                                Aug 2 at 7:14











                              • to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                                – Mohit Rane
                                Aug 2 at 7:16











                              • check updated answer

                                – Mohit Rane
                                Aug 2 at 7:46

















                              • I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                                – Chintan Kaneriya
                                Aug 2 at 7:09











                              • you can use getIsInStock() method

                                – Mohit Rane
                                Aug 2 at 7:14











                              • to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                                – Mohit Rane
                                Aug 2 at 7:16











                              • check updated answer

                                – Mohit Rane
                                Aug 2 at 7:46
















                              I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                              – Chintan Kaneriya
                              Aug 2 at 7:09





                              I tried this as well and it only gives the product quantity but I need to display the stock status values e.g. In Stock, Out of Stock.

                              – Chintan Kaneriya
                              Aug 2 at 7:09













                              you can use getIsInStock() method

                              – Mohit Rane
                              Aug 2 at 7:14





                              you can use getIsInStock() method

                              – Mohit Rane
                              Aug 2 at 7:14













                              to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                              – Mohit Rane
                              Aug 2 at 7:16





                              to get all the stock details you can use this class MagentoCatalogInventoryApiStockRegistryInterface

                              – Mohit Rane
                              Aug 2 at 7:16













                              check updated answer

                              – Mohit Rane
                              Aug 2 at 7:46





                              check updated answer

                              – Mohit Rane
                              Aug 2 at 7:46











                              3














                              If you are using the only simple products at your system then using Stock Status field check then Product status is Ok.



                              But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status.



                              That is this, use of $_product->isAvailable() and $_product->isSaleable() is the best idea.See at https://github.com/devamitbera/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/list.phtml#L80






                              share|improve this answer

























                              • correct! need to check for $_product->isSaleable()

                                – Ketan Borada
                                Aug 2 at 9:40











                              • @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                                – Chintan Kaneriya
                                Aug 3 at 3:30















                              3














                              If you are using the only simple products at your system then using Stock Status field check then Product status is Ok.



                              But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status.



                              That is this, use of $_product->isAvailable() and $_product->isSaleable() is the best idea.See at https://github.com/devamitbera/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/list.phtml#L80






                              share|improve this answer

























                              • correct! need to check for $_product->isSaleable()

                                – Ketan Borada
                                Aug 2 at 9:40











                              • @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                                – Chintan Kaneriya
                                Aug 3 at 3:30













                              3












                              3








                              3







                              If you are using the only simple products at your system then using Stock Status field check then Product status is Ok.



                              But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status.



                              That is this, use of $_product->isAvailable() and $_product->isSaleable() is the best idea.See at https://github.com/devamitbera/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/list.phtml#L80






                              share|improve this answer













                              If you are using the only simple products at your system then using Stock Status field check then Product status is Ok.



                              But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status.



                              That is this, use of $_product->isAvailable() and $_product->isSaleable() is the best idea.See at https://github.com/devamitbera/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/list.phtml#L80







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 2 at 9:24









                              Amit BeraAmit Bera

                              62.9k16 gold badges84 silver badges183 bronze badges




                              62.9k16 gold badges84 silver badges183 bronze badges















                              • correct! need to check for $_product->isSaleable()

                                – Ketan Borada
                                Aug 2 at 9:40











                              • @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                                – Chintan Kaneriya
                                Aug 3 at 3:30

















                              • correct! need to check for $_product->isSaleable()

                                – Ketan Borada
                                Aug 2 at 9:40











                              • @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                                – Chintan Kaneriya
                                Aug 3 at 3:30
















                              correct! need to check for $_product->isSaleable()

                              – Ketan Borada
                              Aug 2 at 9:40





                              correct! need to check for $_product->isSaleable()

                              – Ketan Borada
                              Aug 2 at 9:40













                              @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                              – Chintan Kaneriya
                              Aug 3 at 3:30





                              @Amit What exactly do $_product->isAvailable() mean? is it says that products is enabled or disabled?

                              – Chintan Kaneriya
                              Aug 3 at 3:30

















                              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%2f284176%2fhow-to-get-product-stock-status-on-the-listing-page-in-magento-2%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?