8

I'm getting all the categories in System.xml using the class

Vender\Module\Model\Config\Source\Category

<?php
namespace Vender\Module\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;

class Category implements OptionSourceInterface{

    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 getAllCategoryCollection($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->_toCheckArray();
        $ret = [];
        foreach ($arr as $key => $value){
            $ret[] = [
                'value' => $key,
                'label' => $value
            ];
        }    
        return $ret;
    } 

    private function _toCheckArray(){

        $categories = $this->getAllCategoryCollection(true, false, false, false);
        $catagoryList = array();
        foreach ($categories as $category){
           $catagoryList[$category->getEntityId()] = __($this->_getCategoryParentName($category->getPath()) . $category->getName());
        }
        return $catagoryList;
    }



    private function _getCategoryParentName($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;
    }
}

I get this class form Magento 2 - Category list for custom magento system configuration section
Now its works perfectly for me and its output is like enter image description here But when I submit my module to Magento QA they send me the Error enter image description here
Now how can I solve this problem?unable to identify the problem

Note: I have submitted this Extension before by changing the Name of Class I thought that it will be the problem because of the Class name or Methods name I changed all the methods name and class name but again they send me the same problem.

4
  • Your extension is rejected due to duplicate code or you use a public function instead of private function. see this module will help you to remove duplicate code github.com/mconnectmedia/… Commented May 17, 2019 at 5:55
  • @ChiragPatel its not working... In response it gives me "No code duplication found in your code"
    – Asad Khan
    Commented May 17, 2019 at 6:23
  • If you are not getting any error or not clear about your rejection then you can email to magento market place. i have mentioned email in may answer Commented May 17, 2019 at 6:54
  • Yeah I already send them an Email but they are not giving me any response
    – Asad Khan
    Commented May 17, 2019 at 7:25

2 Answers 2

3
+25

To solve out your issue do the follow below step :

  1. Technical Review Guidelines
  2. You can email to [email protected] with any Marketplace submission problems. They'll be able to help you out.
  3. marketplacesupport.magento.com From here you can create a support ticket to ask your question and you will also find more Info regarding Magento Marketplace.
  4. This are the few things I found which can help to reduce rejection and pass EQP process.

Follow the above step it might be solved out your problem.

I hope it helps!Thanks.

0

I think that is happening because there is code that already does that. Check: vendor/magento/module-catalog/Ui/Component/Product/Form/Categories/Options.php

1
  • 1
    yeah I get all the categories in this class but when I tried to show all categories in configuration (system.xml) then it only shows me default category. How can I show all categories in system.xml using this class
    – Asad Khan
    Commented May 16, 2019 at 8:54

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.