1

I want to get store list sort by sort order. How to get it?

I just use this code. Which code i need to add ?

$stores = $this->storeManager->getStores();
2
$stores = $this->storeManager->getStores();
uasort(
    $stores,
    function (\Magento\Store\Model\Store $storeA, \Magento\Store\Model\Store $storeB) {
        return $storeA->getSortOrder() <=> $storeB->getSortOrder();
    }    
);

Now the variable $stores should contain all your stores sorted by sort_order.

  • Is it possible in Magento way? – Emipro Technologies Pvt. Ltd. Apr 11 at 5:58
  • 1
    what do you mean by "magento way"? – Marius Apr 11 at 6:17
  • I'm just asking about is there any other way instead of uasort(); – Emipro Technologies Pvt. Ltd. Apr 11 at 7:02
  • Because, $stores; inside uasort() returns error in sublime text editor for something like syntax error so. – Emipro Technologies Pvt. Ltd. Apr 11 at 7:04
  • Oups. Sorry. I got the order of the parameters wrong. I've updated the answer – Marius Apr 11 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.