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
But when I submit my module to Magento QA they send me the Error
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.