1
votes

we are assigning 5 store views for 200 countries using below code.

now I am following as below code where IN, AT, IR, AU are country codes. usa, canada are store views.

like this I need to assign each country code for one store view for all 200+ countries. Is there any way i can use array and use only 5 switch cases & include many country codes in one switch case.

switch ($cnCode) {

                case "IN": {
                    Mage::app()->setCurrentStore('usa');
                    break;
                }


                case "AT": {
                    Mage::app()->setCurrentStore('usa');
                    break;
                 }

                case "IR": {
                    Mage::app()->setCurrentStore('usa');
                    break;
                }


                case "AU": {
                    Mage::app()->setCurrentStore('canada');
                    break;
                }
            }

also i am fine with any other way with less code.

1

1 Answers

4
votes

You can use in_array:

if (in_array($enCode, array('IN', 'AT', 'IR'))) {
    Mage::app()->setCurrentStore('usa');
}
if (in_array($enCode, array('AU'))) {
    Mage::app()->setCurrentStore('canada');
}

Or you could combine you cases:

switch ($enCode) {
    case 'IN':
    case 'AT':
    case 'IR':
        Mage::app()->setCurrentStore('usa');
        break;
    case 'AU':
        Mage::app()->setCurrentStore('canada');
        break;
}