在任何地方重新安排国家

时间:2014-03-13 13:36:34

标签: php magento countries

我有一个多商店网站,我需要根据商店更改国家/地区的顺序。就像我的以色列商店一样,以色列必须处于领先地位,对于美国商店,美国必须处于领先地位。

有没有办法在magento中这样做?我找到了answer on SO,但国家列表中没有变化。是否有可能以这种方式对国家进行重新排序?

1 个答案:

答案 0 :(得分:0)

我也在寻找相同的内容answer Alex B在我的情况下不起作用。代码

$this->addOrder('country_id="US"','desc')
     ->addOrder('country_id', 'asc');

未在国家/地区列表中进行任何更改。因此,在重写_initSelect()时,我选择toOptionArray()来覆盖。这是我的代码

public function toOptionArray($emptyLabel = '') {
    $options = parent::toOptionArray($emptyLabel);
    foreach ($options as $key => $option) {
        if ($option['value'] == 'IN') {  //check current country code
            unset($options[$key]);
            $options = addCountryToIndex($options, $option, 1);  
        }
    }
    return $options;
}

protected function addCountryToIndex($countries, $country, $index){
    $options = array_slice($countries, 0, $index, true) +
        array($index => $country) +
        array_slice($countries, $index, count($countries) - 1, true);
    return $options;
}