Skip to content

Magento admin scope choosers show wrong website order after DB import (order ignores store_website.sort_order)

Environment
– Magento (Open Source / Adobe Commerce) 2.4.6
– PHP 8.2; MySQL 8.1
– Same codebase on both instances: Original and Test (no code differences).
– Full DB export from Original → import into a clean schema on Test.


Problem

After importing the DB into Test, all admin scope choosers
(Website/Store/Store View pickers on CMS Pages, Products, Categories, etc.) list websites in a
different order than on Original — even though store_website.sort_order is correct and identical.

On Original (expected order):

Admin → Website A → Website B → Website C → …

On Test (actual order):

Admin → Website B → Website A → Website C → …

What I expect

  • Websites sorted by store_website.sort_order (ascending).
  • Store views sorted by store.sort_order within each Store Group.

What I verified

  1. store_website.sort_order is correct:

    SELECT code, sort_order 
    FROM store_website 
    ORDER BY sort_order, code;
    

    Example result:

    admin       0
    website_a  10
    website_b  20
    website_c  30
    
  2. Store views are consistently ordered per group:

    SELECT store_id, group_id, code, name, sort_order
    FROM store
    ORDER BY group_id, sort_order, store_id;
    
  3. Store Group names are clean (no leading/trailing spaces or special unicode):

    SELECT group_id, CONCAT('[',name,']') AS bracketed, HEX(name) AS hex
    FROM store_group
    ORDER BY name ASC;
    
  4. Default website is set correctly on both envs:

    SELECT website_id, code, is_default, default_group_id
    FROM store_website
    ORDER BY website_id;
    
  5. Changing sort_order on Test (e.g., temporarily set one website to 90)
    does not change the order in the problematic choosers. So those choosers appear to
    ignore store_website.sort_order.

  6. Cleared everything on Test and tried multiple browsers/incognito (no change):

    bin/magento cache:flush
    rm -rf var/cache var/page_cache var/di var/generation var/view_preprocessed
    bin/magento setup:di:compile
    
  7. If I emulate a typical core ordering (websites by store_website.sort_order, groups by name/id,
    stores by store.sort_order), SQL returns the expected order (Website A before Website B):

    SELECT w.sort_order AS website_so, w.name AS website,
           g.name AS group_name, s.sort_order AS storeview_so, s.name AS storeview
    FROM store_website w
    JOIN store_group g ON g.website_id = w.website_id
    JOIN store s ON s.group_id = g.group_id
    ORDER BY w.sort_order, g.name, s.sort_order, s.store_id;
    

Where it happens

The “wrong” order shows up wherever the admin requires Website/Store/Store View scope selection
(CMS Page, Product, Category, etc.). On Original the order is consistent with sort_order.
On Test (after import) it isn’t.


Questions

  1. Which class/provider defines the data & sorting for these scope choosers
    (e.g., CMS Page/Product/Category forms) in Magento 2.x?
    Is it MagentoStoreModelSystemStore::getStoreValuesForForm(), and do those choosers rely
    on collection defaults instead of sort_order?
  2. Is there any known post-import condition (cache/config/flag table or generated metadata)
    that can make these choosers ignore store_website.sort_order on one instance
    but not the other, even with identical DB data?
  3. If those choosers don’t consistently respect store_website.sort_order, what is the
    recommended core-compatible approach to enforce it globally?

Repro steps

  1. Export DB from Original.
  2. Import into a clean schema on Test.
  3. Flush caches, clear var/*, recompile.
  4. Open any admin form with Website/Store/Store View selector.
  5. Observe that the order on Test ≠ Original, even with identical DB data.