How to get the product category id in the cart? Magento 2Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom modulemain.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeAfter rewrite MagentoCustomerModelAccountManagement giving me fatal errorMagento 2: Add a product to the cart programmaticallyMagento offline custom Payment method with drop down listMagento 2 How to remove price filter from category if module is enable?getItemById($itemId) for Magento Quote Model not working as expected in Magento 2Choosing a delivery method, Magento 2

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

The screen of my macbook suddenly broken down how can I do to recover

What if a revenant (monster) gains fire resistance?

Does a 'pending' US visa application constitute a denial?

Why does the Sun have different day lengths, but not the gas giants?

How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?

Can I sign legal documents with a smiley face?

Count the occurrence of each unique word in the file

What should you do if you miss a job interview (deliberately)?

What was this official D&D 3.5e Lovecraft-flavored rulebook?

If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?

C++ debug/print custom type with GDB : the case of nlohmann json library

How can "mimic phobia" be cured or prevented?

Why should universal income be universal?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Are the IPv6 address space and IPv4 address space completely disjoint?

The IT department bottlenecks progress. How should I handle this?

"Spoil" vs "Ruin"

Store Credit Card Information in Password Manager?

Creepy dinosaur pc game identification

Not using 's' for he/she/it

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Non-trope happy ending?

How could a planet have erratic days?



How to get the product category id in the cart? Magento 2


Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom modulemain.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeAfter rewrite MagentoCustomerModelAccountManagement giving me fatal errorMagento 2: Add a product to the cart programmaticallyMagento offline custom Payment method with drop down listMagento 2 How to remove price filter from category if module is enable?getItemById($itemId) for Magento Quote Model not working as expected in Magento 2Choosing a delivery method, Magento 2













1















How to get a list of product categories id in the basket?
Here I get the name of the product.



use MagentoCheckoutModelSession;
class Collect extends AbstractCarrier implements CarrierInterface
{
protected $_code = 'chester_collect';
protected $_session;
public function __construct(
Session $session,
array $data = []
)
$this->_session = $session;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


public function isActive()

/** @var $item MagentoQuoteModelQuoteItem */
$items = $this->_session->getQuote()->getAllItems();
foreach ($items as $item)
var_dump($item->getName());




But how to get all the categories of goods that are in the basket?










share|improve this question


























    1















    How to get a list of product categories id in the basket?
    Here I get the name of the product.



    use MagentoCheckoutModelSession;
    class Collect extends AbstractCarrier implements CarrierInterface
    {
    protected $_code = 'chester_collect';
    protected $_session;
    public function __construct(
    Session $session,
    array $data = []
    )
    $this->_session = $session;
    parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


    public function isActive()

    /** @var $item MagentoQuoteModelQuoteItem */
    $items = $this->_session->getQuote()->getAllItems();
    foreach ($items as $item)
    var_dump($item->getName());




    But how to get all the categories of goods that are in the basket?










    share|improve this question
























      1












      1








      1








      How to get a list of product categories id in the basket?
      Here I get the name of the product.



      use MagentoCheckoutModelSession;
      class Collect extends AbstractCarrier implements CarrierInterface
      {
      protected $_code = 'chester_collect';
      protected $_session;
      public function __construct(
      Session $session,
      array $data = []
      )
      $this->_session = $session;
      parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


      public function isActive()

      /** @var $item MagentoQuoteModelQuoteItem */
      $items = $this->_session->getQuote()->getAllItems();
      foreach ($items as $item)
      var_dump($item->getName());




      But how to get all the categories of goods that are in the basket?










      share|improve this question














      How to get a list of product categories id in the basket?
      Here I get the name of the product.



      use MagentoCheckoutModelSession;
      class Collect extends AbstractCarrier implements CarrierInterface
      {
      protected $_code = 'chester_collect';
      protected $_session;
      public function __construct(
      Session $session,
      array $data = []
      )
      $this->_session = $session;
      parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


      public function isActive()

      /** @var $item MagentoQuoteModelQuoteItem */
      $items = $this->_session->getQuote()->getAllItems();
      foreach ($items as $item)
      var_dump($item->getName());




      But how to get all the categories of goods that are in the basket?







      magento2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









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

      1338




      1338




















          2 Answers
          2






          active

          oldest

          votes


















          1














          I have modified you code with below code:



          use MagentoCheckoutModelSession;
          class Collect extends AbstractCarrier implements CarrierInterface

          protected $_code = 'chester_collect';
          protected $_session;
          private $_objectManager;
          public function __construct(
          Session $session,
          MagentoFrameworkObjectManagerInterface $objectmanager,
          array $data = []
          )
          $this->_session = $session;
          $this->_objectManager = $objectmanager;
          parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


          public function isActive()

          /** @var $item MagentoQuoteModelQuoteItem */
          $items = $this->_session->getQuote()->getAllItems();
          foreach ($items as $item)
          var_dump($item->getName());
          $productid = $item->getProductId();
          $product = $this->_objectManager->create('MagentoCatalogModelProduct')- >load($productid);
          $categoriesIds = $product->getCategoryIds();
          var_dump($categoriesIds);








          share|improve this answer






























            0















            Code for Getting Cart Items and get Categories Ids and names by
            loading Products from Items




             $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $cart = $objectManager->get('MagentoCheckoutModelCart');

            // retrieve quote items collection
            $itemsCollection = $cart->getQuote()->getItemsCollection();

            // get array of all items what can be display directly
            $itemsVisible = $cart->getQuote()->getAllVisibleItems();

            // retrieve quote items array
            $items = $cart->getQuote()->getAllItems();

            foreach($items as $item)
            $productid = $item->getProductId();
            $product = $objectManager->create('MagentoCatalogModelProduct')->load($productid);
            $categoriesIds = $product->getCategoryIds(); /*will return category ids array*/

            foreach($categoriesIds as $categoryId)
            $cat = $objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
            echo $cat->getName();




            I hope this will help






            share|improve this answer






















              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%2f266978%2fhow-to-get-the-product-category-id-in-the-cart-magento-2%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              I have modified you code with below code:



              use MagentoCheckoutModelSession;
              class Collect extends AbstractCarrier implements CarrierInterface

              protected $_code = 'chester_collect';
              protected $_session;
              private $_objectManager;
              public function __construct(
              Session $session,
              MagentoFrameworkObjectManagerInterface $objectmanager,
              array $data = []
              )
              $this->_session = $session;
              $this->_objectManager = $objectmanager;
              parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


              public function isActive()

              /** @var $item MagentoQuoteModelQuoteItem */
              $items = $this->_session->getQuote()->getAllItems();
              foreach ($items as $item)
              var_dump($item->getName());
              $productid = $item->getProductId();
              $product = $this->_objectManager->create('MagentoCatalogModelProduct')- >load($productid);
              $categoriesIds = $product->getCategoryIds();
              var_dump($categoriesIds);








              share|improve this answer



























                1














                I have modified you code with below code:



                use MagentoCheckoutModelSession;
                class Collect extends AbstractCarrier implements CarrierInterface

                protected $_code = 'chester_collect';
                protected $_session;
                private $_objectManager;
                public function __construct(
                Session $session,
                MagentoFrameworkObjectManagerInterface $objectmanager,
                array $data = []
                )
                $this->_session = $session;
                $this->_objectManager = $objectmanager;
                parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


                public function isActive()

                /** @var $item MagentoQuoteModelQuoteItem */
                $items = $this->_session->getQuote()->getAllItems();
                foreach ($items as $item)
                var_dump($item->getName());
                $productid = $item->getProductId();
                $product = $this->_objectManager->create('MagentoCatalogModelProduct')- >load($productid);
                $categoriesIds = $product->getCategoryIds();
                var_dump($categoriesIds);








                share|improve this answer

























                  1












                  1








                  1







                  I have modified you code with below code:



                  use MagentoCheckoutModelSession;
                  class Collect extends AbstractCarrier implements CarrierInterface

                  protected $_code = 'chester_collect';
                  protected $_session;
                  private $_objectManager;
                  public function __construct(
                  Session $session,
                  MagentoFrameworkObjectManagerInterface $objectmanager,
                  array $data = []
                  )
                  $this->_session = $session;
                  $this->_objectManager = $objectmanager;
                  parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


                  public function isActive()

                  /** @var $item MagentoQuoteModelQuoteItem */
                  $items = $this->_session->getQuote()->getAllItems();
                  foreach ($items as $item)
                  var_dump($item->getName());
                  $productid = $item->getProductId();
                  $product = $this->_objectManager->create('MagentoCatalogModelProduct')- >load($productid);
                  $categoriesIds = $product->getCategoryIds();
                  var_dump($categoriesIds);








                  share|improve this answer













                  I have modified you code with below code:



                  use MagentoCheckoutModelSession;
                  class Collect extends AbstractCarrier implements CarrierInterface

                  protected $_code = 'chester_collect';
                  protected $_session;
                  private $_objectManager;
                  public function __construct(
                  Session $session,
                  MagentoFrameworkObjectManagerInterface $objectmanager,
                  array $data = []
                  )
                  $this->_session = $session;
                  $this->_objectManager = $objectmanager;
                  parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);


                  public function isActive()

                  /** @var $item MagentoQuoteModelQuoteItem */
                  $items = $this->_session->getQuote()->getAllItems();
                  foreach ($items as $item)
                  var_dump($item->getName());
                  $productid = $item->getProductId();
                  $product = $this->_objectManager->create('MagentoCatalogModelProduct')- >load($productid);
                  $categoriesIds = $product->getCategoryIds();
                  var_dump($categoriesIds);









                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Mohit chauhanMohit chauhan

                  45419




                  45419























                      0















                      Code for Getting Cart Items and get Categories Ids and names by
                      loading Products from Items




                       $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $cart = $objectManager->get('MagentoCheckoutModelCart');

                      // retrieve quote items collection
                      $itemsCollection = $cart->getQuote()->getItemsCollection();

                      // get array of all items what can be display directly
                      $itemsVisible = $cart->getQuote()->getAllVisibleItems();

                      // retrieve quote items array
                      $items = $cart->getQuote()->getAllItems();

                      foreach($items as $item)
                      $productid = $item->getProductId();
                      $product = $objectManager->create('MagentoCatalogModelProduct')->load($productid);
                      $categoriesIds = $product->getCategoryIds(); /*will return category ids array*/

                      foreach($categoriesIds as $categoryId)
                      $cat = $objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
                      echo $cat->getName();




                      I hope this will help






                      share|improve this answer



























                        0















                        Code for Getting Cart Items and get Categories Ids and names by
                        loading Products from Items




                         $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                        $cart = $objectManager->get('MagentoCheckoutModelCart');

                        // retrieve quote items collection
                        $itemsCollection = $cart->getQuote()->getItemsCollection();

                        // get array of all items what can be display directly
                        $itemsVisible = $cart->getQuote()->getAllVisibleItems();

                        // retrieve quote items array
                        $items = $cart->getQuote()->getAllItems();

                        foreach($items as $item)
                        $productid = $item->getProductId();
                        $product = $objectManager->create('MagentoCatalogModelProduct')->load($productid);
                        $categoriesIds = $product->getCategoryIds(); /*will return category ids array*/

                        foreach($categoriesIds as $categoryId)
                        $cat = $objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
                        echo $cat->getName();




                        I hope this will help






                        share|improve this answer

























                          0












                          0








                          0








                          Code for Getting Cart Items and get Categories Ids and names by
                          loading Products from Items




                           $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $cart = $objectManager->get('MagentoCheckoutModelCart');

                          // retrieve quote items collection
                          $itemsCollection = $cart->getQuote()->getItemsCollection();

                          // get array of all items what can be display directly
                          $itemsVisible = $cart->getQuote()->getAllVisibleItems();

                          // retrieve quote items array
                          $items = $cart->getQuote()->getAllItems();

                          foreach($items as $item)
                          $productid = $item->getProductId();
                          $product = $objectManager->create('MagentoCatalogModelProduct')->load($productid);
                          $categoriesIds = $product->getCategoryIds(); /*will return category ids array*/

                          foreach($categoriesIds as $categoryId)
                          $cat = $objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
                          echo $cat->getName();




                          I hope this will help






                          share|improve this answer














                          Code for Getting Cart Items and get Categories Ids and names by
                          loading Products from Items




                           $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          $cart = $objectManager->get('MagentoCheckoutModelCart');

                          // retrieve quote items collection
                          $itemsCollection = $cart->getQuote()->getItemsCollection();

                          // get array of all items what can be display directly
                          $itemsVisible = $cart->getQuote()->getAllVisibleItems();

                          // retrieve quote items array
                          $items = $cart->getQuote()->getAllItems();

                          foreach($items as $item)
                          $productid = $item->getProductId();
                          $product = $objectManager->create('MagentoCatalogModelProduct')->load($productid);
                          $categoriesIds = $product->getCategoryIds(); /*will return category ids array*/

                          foreach($categoriesIds as $categoryId)
                          $cat = $objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
                          echo $cat->getName();




                          I hope this will help







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          Muhammad HashamMuhammad Hasham

                          2,6711731




                          2,6711731



























                              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%2f266978%2fhow-to-get-the-product-category-id-in-the-cart-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

                              Sum ergo cogito? 1 nng

                              419 nièngy_Soadمي 19bal1.5o_g

                              Queiggey Chernihivv 9NnOo i Zw X QqKk LpB