How to get all categories in configuration (system.xml). magento 2Exclude a specific categoryfunction to display menu from a set levelUnit Test for overwrite collection class in magento2How to add filtering to custom table field column in Customers admin grid in Magento2?main.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 attributeMagento offline custom Payment method with drop down listTwo categories are loading every available product in categoryHow to solve Front controller reached 100 router match iterations in magento2

Why do distances seem to matter in the Foundation world?

How to not starve gigantic beasts

How did Captain America manage to do this?

Contradiction proof for inequality of P and NP?

Why is the underscore command _ useful?

How exactly does Hawking radiation decrease the mass of black holes?

What was Apollo 13's "Little Jolt" after MECO?

How to copy a file or multiple to the directory I previously was?

Don’t seats that recline flat defeat the purpose of having seatbelts?

What is the term for a person whose job is to place products on shelves in stores?

What is the optimal strategy for the Dictionary Game?

Why does Mind Blank stop the Feeblemind spell?

A Paper Record is What I Hamper

Figure is not placed perfectly

Check if a string is entirely made of the same substring

Creating a chemical industry from a medieval tech level without petroleum

diskutil list shows 20 disk partitions, I only know 3, what are the rest?

Is there a grandfather paradox in Endgame?

Is Diceware more secure than a long passphrase?

How to pronounce 'c++' in Spanish

As an international instructor, should I openly talk about my accent?

What makes accurate emulation of old systems a difficult task?

If a planet has 3 moons, is it possible to have triple Full/New Moons at once?

My bank got bought out, am I now going to have to start filing tax returns in a different state?



How to get all categories in configuration (system.xml). magento 2


Exclude a specific categoryfunction to display menu from a set levelUnit Test for overwrite collection class in magento2How to add filtering to custom table field column in Customers admin grid in Magento2?main.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 attributeMagento offline custom Payment method with drop down listTwo categories are loading every available product in categoryHow to solve Front controller reached 100 router match iterations in magento2






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








2















I'm getting all the categories in system.xml using



<?php
namespace VenderModuleModelConfigSource;

use MagentoFrameworkOptionArrayInterface;

class Category implements ArrayInterfaceint $pageSize
* @return MagentoCatalogModelResourceModelCategoryCollection or array
*/


public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)

$collection = $this->_categoryCollectionFactory->create();
$collection->addAttributeToSelect('*');

// select only active categories
if ($isActive)
$collection->addIsActiveFilter();


// select categories of certain level
if ($level)
$collection->addLevelFilter($level);


// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);


// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);


return $collection;




public function toOptionArray()

$arr = $this->_toArray();
$ret = [];
foreach ($arr as $key => $value)
$ret[] = [
'value' => $key,
'label' => $value
];

return $ret;





private function _toArray()

$categories = $this->getCategoryCollection(true, false, false, false);
$catagoryList = array();
foreach ($categories as $category)
$catagoryList[$category->getEntityId()] = __($this->_getParentName($category->getPath()) . $category->getName());

return $catagoryList;




private function _getParentName($path = '')
$parentName = '';
$rootCats = array(1,2);
$catTree = explode("/", $path);
array_pop($catTree);
if($catTree && (count($catTree) > count($rootCats)))
foreach ($catTree as $catId)
if(!in_array($catId, $rootCats))
$category = $this->_categoryFactory->create()->load($catId);
$categoryName = $category->getName();
$parentName .= $categoryName . ' -> ';



return $parentName;




but when I submit my extension to magento QA then they give me the errorenter image description here

now how can I solve this? they are saying that I'm duplicating the class the which core class I can use to get all categories like that
enter image description here










share|improve this question




























    2















    I'm getting all the categories in system.xml using



    <?php
    namespace VenderModuleModelConfigSource;

    use MagentoFrameworkOptionArrayInterface;

    class Category implements ArrayInterfaceint $pageSize
    * @return MagentoCatalogModelResourceModelCategoryCollection or array
    */


    public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)

    $collection = $this->_categoryCollectionFactory->create();
    $collection->addAttributeToSelect('*');

    // select only active categories
    if ($isActive)
    $collection->addIsActiveFilter();


    // select categories of certain level
    if ($level)
    $collection->addLevelFilter($level);


    // sort categories by some value
    if ($sortBy)
    $collection->addOrderField($sortBy);


    // select certain number of categories
    if ($pageSize)
    $collection->setPageSize($pageSize);


    return $collection;




    public function toOptionArray()

    $arr = $this->_toArray();
    $ret = [];
    foreach ($arr as $key => $value)
    $ret[] = [
    'value' => $key,
    'label' => $value
    ];

    return $ret;





    private function _toArray()

    $categories = $this->getCategoryCollection(true, false, false, false);
    $catagoryList = array();
    foreach ($categories as $category)
    $catagoryList[$category->getEntityId()] = __($this->_getParentName($category->getPath()) . $category->getName());

    return $catagoryList;




    private function _getParentName($path = '')
    $parentName = '';
    $rootCats = array(1,2);
    $catTree = explode("/", $path);
    array_pop($catTree);
    if($catTree && (count($catTree) > count($rootCats)))
    foreach ($catTree as $catId)
    if(!in_array($catId, $rootCats))
    $category = $this->_categoryFactory->create()->load($catId);
    $categoryName = $category->getName();
    $parentName .= $categoryName . ' -> ';



    return $parentName;




    but when I submit my extension to magento QA then they give me the errorenter image description here

    now how can I solve this? they are saying that I'm duplicating the class the which core class I can use to get all categories like that
    enter image description here










    share|improve this question
























      2












      2








      2








      I'm getting all the categories in system.xml using



      <?php
      namespace VenderModuleModelConfigSource;

      use MagentoFrameworkOptionArrayInterface;

      class Category implements ArrayInterfaceint $pageSize
      * @return MagentoCatalogModelResourceModelCategoryCollection or array
      */


      public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)

      $collection = $this->_categoryCollectionFactory->create();
      $collection->addAttributeToSelect('*');

      // select only active categories
      if ($isActive)
      $collection->addIsActiveFilter();


      // select categories of certain level
      if ($level)
      $collection->addLevelFilter($level);


      // sort categories by some value
      if ($sortBy)
      $collection->addOrderField($sortBy);


      // select certain number of categories
      if ($pageSize)
      $collection->setPageSize($pageSize);


      return $collection;




      public function toOptionArray()

      $arr = $this->_toArray();
      $ret = [];
      foreach ($arr as $key => $value)
      $ret[] = [
      'value' => $key,
      'label' => $value
      ];

      return $ret;





      private function _toArray()

      $categories = $this->getCategoryCollection(true, false, false, false);
      $catagoryList = array();
      foreach ($categories as $category)
      $catagoryList[$category->getEntityId()] = __($this->_getParentName($category->getPath()) . $category->getName());

      return $catagoryList;




      private function _getParentName($path = '')
      $parentName = '';
      $rootCats = array(1,2);
      $catTree = explode("/", $path);
      array_pop($catTree);
      if($catTree && (count($catTree) > count($rootCats)))
      foreach ($catTree as $catId)
      if(!in_array($catId, $rootCats))
      $category = $this->_categoryFactory->create()->load($catId);
      $categoryName = $category->getName();
      $parentName .= $categoryName . ' -> ';



      return $parentName;




      but when I submit my extension to magento QA then they give me the errorenter image description here

      now how can I solve this? they are saying that I'm duplicating the class the which core class I can use to get all categories like that
      enter image description here










      share|improve this question














      I'm getting all the categories in system.xml using



      <?php
      namespace VenderModuleModelConfigSource;

      use MagentoFrameworkOptionArrayInterface;

      class Category implements ArrayInterfaceint $pageSize
      * @return MagentoCatalogModelResourceModelCategoryCollection or array
      */


      public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)

      $collection = $this->_categoryCollectionFactory->create();
      $collection->addAttributeToSelect('*');

      // select only active categories
      if ($isActive)
      $collection->addIsActiveFilter();


      // select categories of certain level
      if ($level)
      $collection->addLevelFilter($level);


      // sort categories by some value
      if ($sortBy)
      $collection->addOrderField($sortBy);


      // select certain number of categories
      if ($pageSize)
      $collection->setPageSize($pageSize);


      return $collection;




      public function toOptionArray()

      $arr = $this->_toArray();
      $ret = [];
      foreach ($arr as $key => $value)
      $ret[] = [
      'value' => $key,
      'label' => $value
      ];

      return $ret;





      private function _toArray()

      $categories = $this->getCategoryCollection(true, false, false, false);
      $catagoryList = array();
      foreach ($categories as $category)
      $catagoryList[$category->getEntityId()] = __($this->_getParentName($category->getPath()) . $category->getName());

      return $catagoryList;




      private function _getParentName($path = '')
      $parentName = '';
      $rootCats = array(1,2);
      $catTree = explode("/", $path);
      array_pop($catTree);
      if($catTree && (count($catTree) > count($rootCats)))
      foreach ($catTree as $catId)
      if(!in_array($catId, $rootCats))
      $category = $this->_categoryFactory->create()->load($catId);
      $categoryName = $category->getName();
      $parentName .= $categoryName . ' -> ';



      return $parentName;




      but when I submit my extension to magento QA then they give me the errorenter image description here

      now how can I solve this? they are saying that I'm duplicating the class the which core class I can use to get all categories like that
      enter image description here







      magento2 category backend






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Asad KhanAsad Khan

      39510




      39510




















          1 Answer
          1






          active

          oldest

          votes


















          0














          You should try not to use a "core-like" class name. I doubt, it is because you named your class as Category which is already present in the Magento core.



          You can change it to something like Catlist at least it doesn't seem to duplicate any existing core class and instead more like what it seems to, which is Category list.






          share|improve this answer























          • didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

            – Asad Khan
            1 hour ago











          • Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

            – magefms
            1 hour 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%2f272563%2fhow-to-get-all-categories-in-configuration-system-xml-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You should try not to use a "core-like" class name. I doubt, it is because you named your class as Category which is already present in the Magento core.



          You can change it to something like Catlist at least it doesn't seem to duplicate any existing core class and instead more like what it seems to, which is Category list.






          share|improve this answer























          • didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

            – Asad Khan
            1 hour ago











          • Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

            – magefms
            1 hour ago















          0














          You should try not to use a "core-like" class name. I doubt, it is because you named your class as Category which is already present in the Magento core.



          You can change it to something like Catlist at least it doesn't seem to duplicate any existing core class and instead more like what it seems to, which is Category list.






          share|improve this answer























          • didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

            – Asad Khan
            1 hour ago











          • Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

            – magefms
            1 hour ago













          0












          0








          0







          You should try not to use a "core-like" class name. I doubt, it is because you named your class as Category which is already present in the Magento core.



          You can change it to something like Catlist at least it doesn't seem to duplicate any existing core class and instead more like what it seems to, which is Category list.






          share|improve this answer













          You should try not to use a "core-like" class name. I doubt, it is because you named your class as Category which is already present in the Magento core.



          You can change it to something like Catlist at least it doesn't seem to duplicate any existing core class and instead more like what it seems to, which is Category list.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          magefmsmagefms

          2,8502529




          2,8502529












          • didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

            – Asad Khan
            1 hour ago











          • Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

            – magefms
            1 hour ago

















          • didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

            – Asad Khan
            1 hour ago











          • Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

            – magefms
            1 hour ago
















          didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

          – Asad Khan
          1 hour ago





          didn't you think that we use many classes with the same name like Data.php (Helper) and many more.. but they didn't give me any error on that class

          – Asad Khan
          1 hour ago













          Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

          – magefms
          1 hour ago





          Yeah, you are right. I got your point. But having read the review results there's no way you can solve it with a plugin. Just my thought

          – magefms
          1 hour 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%2f272563%2fhow-to-get-all-categories-in-configuration-system-xml-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

          منجزی محتویات تیره‌های طایفه منجزی[ویرایش] مشاهیر طایفه منجزی[ویرایش] محل سکونت[ویرایش] پانویس[ویرایش] منابع[ویرایش] منوی ناوبری«نمودار اجتماعی طوایف بختیاری»«BakhtyārBAḴTĪĀRĪ TRIBE»«اسامی طوایف و شعب ایل بختیاری»ووگسترش آن

          What does the writing on Poe's helmet say? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Favorite questions and answers from first quarter of 2019 Latest Blog Post: Avengers: Endgame PredictionsWhat is the purpose of the blast shield helmet?Why was the Stormtrooper helmet designed this way?What does Kylo Ren place his helmet on?What does the writing on Poe Dameron's flight vest say?Is this Poe Damerons dad? (Kes Dameron)Is Poe Dameron Force-Sensitive?Why is Poe Dameron so shocked in the First Order star destroyer hangar?What does the code breaker's hat say?In “The Last Jedi” was it actually Poe's fault that so much of the resistance died?Did Poe Dameron make custom modifications to his black X-Wing?

          How to implement Time Range Picker in Magento 2 Admin system.xml? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Date field system.xmlMagento 2 - time picker on backend (xml form)How to overwrite System.xml?Magento 2 Pattern Library — Date & Time SelectorsHTTP 500 Error in System ConfigurationMagento 2 - time picker on backend (xml form)Magento 2 Add Datetime picker in system.xmlDate Time picker and time zone woesHow to implement Single Date and Time Picker in Magento 2Custom Module for Custom Column using Plugin Yes/No optionMagento 2 DateTime picker - Limit time selection rangeMagento2 UI Component admin Grid / Listing stuck loading