How to set the category ids to a products from category path?get product category pathEdit products from certain categoryHow do I set new product's category?Filter Category Collection by Enabled, Visible ProductsInclude Category Path in SitemapMagento2: Assign products to category programaticallyMagento2: Remove Category path from product URL is not workingMagento 2 : Backend Products in CategoryHow to edit category in Magento 1 using PHP using path (Not ID)Magento2: Remove Category path from product URL is not working for all productsHow to add category Path when creating product progrmatically in magento 2

Why Shazam when there is already Superman?

Can I say "fingers" when referring to toes?

What is Cash Advance APR?

PTIJ: Haman's bad computer

Recommended PCB layout understanding - ADM2572 datasheet

Is there a RAID 0 Equivalent for RAM?

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

How could a planet have erratic days?

What exactly color does ozone gas have?

How much character growth crosses the line into breaking the character

Why should universal income be universal?

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

Yosemite Fire Rings - What to Expect?

Why is the "ls" command showing permissions of files in a FAT32 partition?

How should I respond when I lied about my education and the company finds out through background check?

Calculating total slots

Is this toilet slogan correct usage of the English language?

How to explain what's wrong with this application of the chain rule?

Bridge building with irregular planks

How can I avoid dust and bubbles when installing window film?

What is going on with 'gets(stdin)' on the site coderbyte?

Using substitution ciphers to generate new alphabets in a novel

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Does Doodling or Improvising on the Piano Have Any Benefits?



How to set the category ids to a products from category path?


get product category pathEdit products from certain categoryHow do I set new product's category?Filter Category Collection by Enabled, Visible ProductsInclude Category Path in SitemapMagento2: Assign products to category programaticallyMagento2: Remove Category path from product URL is not workingMagento 2 : Backend Products in CategoryHow to edit category in Magento 1 using PHP using path (Not ID)Magento2: Remove Category path from product URL is not working for all productsHow to add category Path when creating product progrmatically in magento 2













1















I want to progrmmatically create products from a xml.



Ex : I am getting the product categories as like below.



Default Category/Beer ,
Default Category/Beer /CRAFT,
Default Category/Beer /CRAFT/BOMBER BEER,
Default Category/BEER,
Default Category for Store 2/Beer ,
Default Category for Store 2/Beer /CRAFT,
Default Category for Store 2/Beer /CRAFT/BOMBER BEER,
Default Category for Store 2/BEERe


I am getting the category path from the xml.I want to assign the category to the product.How can i assign the categories to the product?










share|improve this question




























    1















    I want to progrmmatically create products from a xml.



    Ex : I am getting the product categories as like below.



    Default Category/Beer ,
    Default Category/Beer /CRAFT,
    Default Category/Beer /CRAFT/BOMBER BEER,
    Default Category/BEER,
    Default Category for Store 2/Beer ,
    Default Category for Store 2/Beer /CRAFT,
    Default Category for Store 2/Beer /CRAFT/BOMBER BEER,
    Default Category for Store 2/BEERe


    I am getting the category path from the xml.I want to assign the category to the product.How can i assign the categories to the product?










    share|improve this question


























      1












      1








      1








      I want to progrmmatically create products from a xml.



      Ex : I am getting the product categories as like below.



      Default Category/Beer ,
      Default Category/Beer /CRAFT,
      Default Category/Beer /CRAFT/BOMBER BEER,
      Default Category/BEER,
      Default Category for Store 2/Beer ,
      Default Category for Store 2/Beer /CRAFT,
      Default Category for Store 2/Beer /CRAFT/BOMBER BEER,
      Default Category for Store 2/BEERe


      I am getting the category path from the xml.I want to assign the category to the product.How can i assign the categories to the product?










      share|improve this question
















      I want to progrmmatically create products from a xml.



      Ex : I am getting the product categories as like below.



      Default Category/Beer ,
      Default Category/Beer /CRAFT,
      Default Category/Beer /CRAFT/BOMBER BEER,
      Default Category/BEER,
      Default Category for Store 2/Beer ,
      Default Category for Store 2/Beer /CRAFT,
      Default Category for Store 2/Beer /CRAFT/BOMBER BEER,
      Default Category for Store 2/BEERe


      I am getting the category path from the xml.I want to assign the category to the product.How can i assign the categories to the product?







      product magento2.2 custom programmatically






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      Mujahidh

















      asked yesterday









      MujahidhMujahidh

      1,41412036




      1,41412036




















          1 Answer
          1






          active

          oldest

          votes


















          0














          As per given text you cannot find category id.



          You can achieve this function using below code.



          You need to create category id and category name array. by mapping category name you will get category id, after set category id to products.



          protected $_categoryCollectionFactory;

          public function __construct(
          MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory
          )

          $this->_categoryCollectionFactory = $categoryCollectionFactory;


          public function getCategoryIds()
          $collection = $this->_categoryCollectionFactory->create();
          $allCategory = array();
          foreach($collection as $category)
          $allCategory[$category->getName()] = $category->getId() ;


          return $allCategory;






          share|improve this answer























          • thanks, I want to get the category from category path and assign the category to the products

            – Mujahidh
            yesterday











          • Yes you can get last string from path so you will get category name, using this rray you will find category id

            – Prashant Valanda
            yesterday











          • where can i pass the path as an argument here?

            – Mujahidh
            17 hours ago











          • You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

            – Prashant Valanda
            9 hours ago










          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%2f266825%2fhow-to-set-the-category-ids-to-a-products-from-category-path%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














          As per given text you cannot find category id.



          You can achieve this function using below code.



          You need to create category id and category name array. by mapping category name you will get category id, after set category id to products.



          protected $_categoryCollectionFactory;

          public function __construct(
          MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory
          )

          $this->_categoryCollectionFactory = $categoryCollectionFactory;


          public function getCategoryIds()
          $collection = $this->_categoryCollectionFactory->create();
          $allCategory = array();
          foreach($collection as $category)
          $allCategory[$category->getName()] = $category->getId() ;


          return $allCategory;






          share|improve this answer























          • thanks, I want to get the category from category path and assign the category to the products

            – Mujahidh
            yesterday











          • Yes you can get last string from path so you will get category name, using this rray you will find category id

            – Prashant Valanda
            yesterday











          • where can i pass the path as an argument here?

            – Mujahidh
            17 hours ago











          • You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

            – Prashant Valanda
            9 hours ago















          0














          As per given text you cannot find category id.



          You can achieve this function using below code.



          You need to create category id and category name array. by mapping category name you will get category id, after set category id to products.



          protected $_categoryCollectionFactory;

          public function __construct(
          MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory
          )

          $this->_categoryCollectionFactory = $categoryCollectionFactory;


          public function getCategoryIds()
          $collection = $this->_categoryCollectionFactory->create();
          $allCategory = array();
          foreach($collection as $category)
          $allCategory[$category->getName()] = $category->getId() ;


          return $allCategory;






          share|improve this answer























          • thanks, I want to get the category from category path and assign the category to the products

            – Mujahidh
            yesterday











          • Yes you can get last string from path so you will get category name, using this rray you will find category id

            – Prashant Valanda
            yesterday











          • where can i pass the path as an argument here?

            – Mujahidh
            17 hours ago











          • You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

            – Prashant Valanda
            9 hours ago













          0












          0








          0







          As per given text you cannot find category id.



          You can achieve this function using below code.



          You need to create category id and category name array. by mapping category name you will get category id, after set category id to products.



          protected $_categoryCollectionFactory;

          public function __construct(
          MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory
          )

          $this->_categoryCollectionFactory = $categoryCollectionFactory;


          public function getCategoryIds()
          $collection = $this->_categoryCollectionFactory->create();
          $allCategory = array();
          foreach($collection as $category)
          $allCategory[$category->getName()] = $category->getId() ;


          return $allCategory;






          share|improve this answer













          As per given text you cannot find category id.



          You can achieve this function using below code.



          You need to create category id and category name array. by mapping category name you will get category id, after set category id to products.



          protected $_categoryCollectionFactory;

          public function __construct(
          MagentoCatalogModelResourceModelCategoryCollectionFactory $categoryCollectionFactory
          )

          $this->_categoryCollectionFactory = $categoryCollectionFactory;


          public function getCategoryIds()
          $collection = $this->_categoryCollectionFactory->create();
          $allCategory = array();
          foreach($collection as $category)
          $allCategory[$category->getName()] = $category->getId() ;


          return $allCategory;







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Prashant ValandaPrashant Valanda

          9,83412355




          9,83412355












          • thanks, I want to get the category from category path and assign the category to the products

            – Mujahidh
            yesterday











          • Yes you can get last string from path so you will get category name, using this rray you will find category id

            – Prashant Valanda
            yesterday











          • where can i pass the path as an argument here?

            – Mujahidh
            17 hours ago











          • You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

            – Prashant Valanda
            9 hours ago

















          • thanks, I want to get the category from category path and assign the category to the products

            – Mujahidh
            yesterday











          • Yes you can get last string from path so you will get category name, using this rray you will find category id

            – Prashant Valanda
            yesterday











          • where can i pass the path as an argument here?

            – Mujahidh
            17 hours ago











          • You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

            – Prashant Valanda
            9 hours ago
















          thanks, I want to get the category from category path and assign the category to the products

          – Mujahidh
          yesterday





          thanks, I want to get the category from category path and assign the category to the products

          – Mujahidh
          yesterday













          Yes you can get last string from path so you will get category name, using this rray you will find category id

          – Prashant Valanda
          yesterday





          Yes you can get last string from path so you will get category name, using this rray you will find category id

          – Prashant Valanda
          yesterday













          where can i pass the path as an argument here?

          – Mujahidh
          17 hours ago





          where can i pass the path as an argument here?

          – Mujahidh
          17 hours ago













          You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

          – Prashant Valanda
          9 hours ago





          You do not need to pass any argument, first find category name and call $array = $thi->getCategoryIds() funcll give you all category name and category id array. $array['category name here'] using this code you will get category id

          – Prashant Valanda
          9 hours ago

















          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%2f266825%2fhow-to-set-the-category-ids-to-a-products-from-category-path%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

          БиармияSxpst500bh2ntaf! 3h2r