How to check whether a product is in the cart? The 2019 Stack Overflow Developer Survey Results Are InGetting the product SKU in the header mini-cartMagento 2 : Check Static Block with same identifier in InstallData ScriptMagento 2 : How to Check Cart Items Satisfying Cart Price Rule Condition?How can I check if the module output is enabled on the Magento 2?Magento 2 check which catalog rule is applied to cart productMagento 2 not passing minimum QTY when adding related products to cartCheck bundle product magento 2Magento 2 : How to change the quantity of items in the checkout?How to get the product category id in the cart? Magento 2How to show the client pop-up when adding a product to the cart?

How to display lines in a file like ls displays files in a directory?

Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?

What information about me do stores get via my credit card?

Worn-tile Scrabble

How do you keep chess fun when your opponent constantly defeats?

Why can't devices on different VLANs, but on the same subnet, communicate?

Is it safe to harvest rainwater that fell on solar panels?

What is this business jet?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

If I can cast sorceries at instant speed, can I use sorcery-speed activated abilities at instant speed?

Output the Arecibo Message

Button changing its text & action. Good or terrible?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

APIPA and LAN Broadcast Domain

Flight paths in orbit around Ceres?

If a sorcerer casts the Banishment spell on a PC while in Avernus, does the PC return to their home plane?

Compute the product of 3 dictionaries and concatenate keys and values

Keeping a retro style to sci-fi spaceships?

How do PCB vias affect signal quality?

$EDITOR environment variable won't set

Computing the expectation of the number of balls in a box

Star Trek - X-shaped Item on Regula/Orbital Office Starbases

If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past



How to check whether a product is in the cart?



The 2019 Stack Overflow Developer Survey Results Are InGetting the product SKU in the header mini-cartMagento 2 : Check Static Block with same identifier in InstallData ScriptMagento 2 : How to Check Cart Items Satisfying Cart Price Rule Condition?How can I check if the module output is enabled on the Magento 2?Magento 2 check which catalog rule is applied to cart productMagento 2 not passing minimum QTY when adding related products to cartCheck bundle product magento 2Magento 2 : How to change the quantity of items in the checkout?How to get the product category id in the cart? Magento 2How to show the client pop-up when adding a product to the cart?



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








0















How to create a module that will check if there is an item in the basket?
Verification is needed on the product page.










share|improve this question






























    0















    How to create a module that will check if there is an item in the basket?
    Verification is needed on the product page.










    share|improve this question


























      0












      0








      0








      How to create a module that will check if there is an item in the basket?
      Verification is needed on the product page.










      share|improve this question
















      How to create a module that will check if there is an item in the basket?
      Verification is needed on the product page.







      magento2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 8 at 10:39







      Рома Лытарь

















      asked Apr 8 at 10:02









      Рома ЛытарьРома Лытарь

      1789




      1789




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Try to use this below code :



          public function __construct(
          MagentoCheckoutModelCart $cart
          )
          $this->_cart = $cart;



          public function getProductData()

          $productInfo = $this->_cart->getQuote()->getItemsCollection();
          foreach ($productInfo as $item)
          $item->getProductId();
          if($item->getProductId() == 'your_product_id')

          echo "Item available in cart";

          else

          echo "Item not available in cart";








          share|improve this answer























          • Where should I put this code?

            – Рома Лытарь
            Apr 8 at 10:14











          • you can add in your block or controller.

            – Rohan Hapani
            Apr 8 at 10:15











          • What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

            – Рома Лытарь
            Apr 8 at 10:23











          • Wherer you want to access this value?

            – Rohan Hapani
            Apr 8 at 10:30











          • On the product page

            – Рома Лытарь
            Apr 8 at 10:31











          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%2f269130%2fhow-to-check-whether-a-product-is-in-the-cart%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









          1














          Try to use this below code :



          public function __construct(
          MagentoCheckoutModelCart $cart
          )
          $this->_cart = $cart;



          public function getProductData()

          $productInfo = $this->_cart->getQuote()->getItemsCollection();
          foreach ($productInfo as $item)
          $item->getProductId();
          if($item->getProductId() == 'your_product_id')

          echo "Item available in cart";

          else

          echo "Item not available in cart";








          share|improve this answer























          • Where should I put this code?

            – Рома Лытарь
            Apr 8 at 10:14











          • you can add in your block or controller.

            – Rohan Hapani
            Apr 8 at 10:15











          • What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

            – Рома Лытарь
            Apr 8 at 10:23











          • Wherer you want to access this value?

            – Rohan Hapani
            Apr 8 at 10:30











          • On the product page

            – Рома Лытарь
            Apr 8 at 10:31















          1














          Try to use this below code :



          public function __construct(
          MagentoCheckoutModelCart $cart
          )
          $this->_cart = $cart;



          public function getProductData()

          $productInfo = $this->_cart->getQuote()->getItemsCollection();
          foreach ($productInfo as $item)
          $item->getProductId();
          if($item->getProductId() == 'your_product_id')

          echo "Item available in cart";

          else

          echo "Item not available in cart";








          share|improve this answer























          • Where should I put this code?

            – Рома Лытарь
            Apr 8 at 10:14











          • you can add in your block or controller.

            – Rohan Hapani
            Apr 8 at 10:15











          • What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

            – Рома Лытарь
            Apr 8 at 10:23











          • Wherer you want to access this value?

            – Rohan Hapani
            Apr 8 at 10:30











          • On the product page

            – Рома Лытарь
            Apr 8 at 10:31













          1












          1








          1







          Try to use this below code :



          public function __construct(
          MagentoCheckoutModelCart $cart
          )
          $this->_cart = $cart;



          public function getProductData()

          $productInfo = $this->_cart->getQuote()->getItemsCollection();
          foreach ($productInfo as $item)
          $item->getProductId();
          if($item->getProductId() == 'your_product_id')

          echo "Item available in cart";

          else

          echo "Item not available in cart";








          share|improve this answer













          Try to use this below code :



          public function __construct(
          MagentoCheckoutModelCart $cart
          )
          $this->_cart = $cart;



          public function getProductData()

          $productInfo = $this->_cart->getQuote()->getItemsCollection();
          foreach ($productInfo as $item)
          $item->getProductId();
          if($item->getProductId() == 'your_product_id')

          echo "Item available in cart";

          else

          echo "Item not available in cart";









          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 8 at 10:11









          Rohan HapaniRohan Hapani

          6,90431865




          6,90431865












          • Where should I put this code?

            – Рома Лытарь
            Apr 8 at 10:14











          • you can add in your block or controller.

            – Rohan Hapani
            Apr 8 at 10:15











          • What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

            – Рома Лытарь
            Apr 8 at 10:23











          • Wherer you want to access this value?

            – Rohan Hapani
            Apr 8 at 10:30











          • On the product page

            – Рома Лытарь
            Apr 8 at 10:31

















          • Where should I put this code?

            – Рома Лытарь
            Apr 8 at 10:14











          • you can add in your block or controller.

            – Rohan Hapani
            Apr 8 at 10:15











          • What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

            – Рома Лытарь
            Apr 8 at 10:23











          • Wherer you want to access this value?

            – Rohan Hapani
            Apr 8 at 10:30











          • On the product page

            – Рома Лытарь
            Apr 8 at 10:31
















          Where should I put this code?

          – Рома Лытарь
          Apr 8 at 10:14





          Where should I put this code?

          – Рома Лытарь
          Apr 8 at 10:14













          you can add in your block or controller.

          – Rohan Hapani
          Apr 8 at 10:15





          you can add in your block or controller.

          – Rohan Hapani
          Apr 8 at 10:15













          What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

          – Рома Лытарь
          Apr 8 at 10:23





          What structure should be? I just do not understand what should be in the model and what should be in the block, etc.

          – Рома Лытарь
          Apr 8 at 10:23













          Wherer you want to access this value?

          – Rohan Hapani
          Apr 8 at 10:30





          Wherer you want to access this value?

          – Rohan Hapani
          Apr 8 at 10:30













          On the product page

          – Рома Лытарь
          Apr 8 at 10:31





          On the product page

          – Рома Лытарь
          Apr 8 at 10:31

















          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%2f269130%2fhow-to-check-whether-a-product-is-in-the-cart%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

          Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

          Magento2 - How to hide price filter only in specific categories?Multiselect price filter attribute in layered navigationhide only some categories from layered navigation in magentoRemove Price Filter on certain categoriescustomize layered price filter?Hide Price for a particular customer groupPrice filter in layered navigation not working correctly with price including tax in magento 2.2.3Magento 2 how to hide attribute at Layered navigation?Magento 2. how to hide price only for specific categoriesMagento 2 How can I hide the price and total from cart and checkout summary?Magento2: Can we add navigation layered filter like price filter for other attribute?