Magento按默认排序区域

时间:2015-08-20 17:31:18

标签: magento

我需要在一页结帐页面中对区域下拉菜单进行排序。我发现来自'Mage_Directory_Helper_Data'的数据我需要对这些数据进行排序。我尝试添加以下代码:

$collection = Mage::getModel('directory/region')->getResourceCollection()
                    ->addCountryFilter($countryIds)
                        ->addOrder('default_name', 'DESC')
                    ->load();

但它没有用。谁能帮帮我吗。谢谢。

1 个答案:

答案 0 :(得分:1)

尝试

        if (empty($json)) {
            $countryIds = array();
            foreach ($this->getCountryCollection() as $country) {
                $countryIds[] = $country->getCountryId();
            }
            $collection = Mage::getModel('directory/region')->getResourceCollection()
                ->addCountryFilter($countryIds)
                ->setOrder('default_name','DESC')
                ->load();
            $regions = array(
                'config' => array(
                    'show_all_regions' => $this->getShowNonRequiredState(),
                    'regions_required' => $this->getCountriesWithStatesRequired()
                )
            );
            foreach ($collection as $region) {
                if (!$region->getRegionId()) {
                    continue;
                }
                $regions[$region->getCountryId()][$region->getRegionId()] = array(
                    'code' => $region->getCode(),
                    'name' => $this->__($region->getName())
                );
            }
            krsort($regions); // or ksort($regions)
            $json = Mage::helper('core')->jsonEncode($regions);
        }