I have the parent category "XXX" and having around 115 subcategories under the same.
I am trying to sort the subcategories listed under of specific parent category at the backend...
I have the parent category "XXX" and having around 115 subcategories under the same.
I am trying to sort the subcategories listed under of specific parent category at the backend...
Use like below.
protected $_categoryCollection;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollection,
array $data = []
)
{
$this->_categoryCollection = $categoryCollection;
parent::__construct($context, $data);
}
public function getCategoryCollection()
{
$categoryId = "your parent categoryId";
$collection = $this->_categoryCollection->create()->load($categoryId)
->addAttributeToSelect('*')
->addAttributeToSort('position', 'asc');
return $collection;
}