我有父类别"XXX",并且在同一个类别下有大约115个子类别。
我正在尝试对后端特定父类别下列出的子类别进行排序...
使用如下.
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; }
使用如下.