How to sort the subcategories of specific parent category in magento 2.3 programatically
-
02-03-2021 - |
Solução
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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange