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

namespace Vender\Module\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Category implements ArrayInterface{

    protected $_categoryFactory;
    protected $_categoryCollectionFactory;

    public function __construct(
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
        \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
        $this->_categoryCollectionFactory = $categoryCollectionFactory;
        $this->_categoryFactory = $categoryFactory;

    * Get category collection
    * @param bool $isActive
    * @param bool|int $level
    * @param bool|string $sortBy
    * @param bool|int $pageSize
    * @return \Magento\Catalog\Model\ResourceModel\Category\Collection or array

    public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)
        $collection = $this->_categoryCollectionFactory->create();

        // select only active categories
        if ($isActive) {

        // select categories of certain level
        if ($level) {

        // sort categories by some value
        if ($sortBy) {

        // select certain number of categories
        if ($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);
        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

1 Answer 1


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.

  • 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
    Apr 26, 2019 at 10:37
  • 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
    – fmsthird
    Apr 26, 2019 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.