Skip to content

Instantly share code, notes, and snippets.

@diazwatson
Created August 31, 2018 14:19
Show Gist options
  • Save diazwatson/2d1565f0ad975533f729948d7635833b to your computer and use it in GitHub Desktop.
Save diazwatson/2d1565f0ad975533f729948d7635833b to your computer and use it in GitHub Desktop.
Magento2 UK and Ireland Counties for Region Addresses (SetupScript)
<?php
namespace Vendor\ModuleName\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
if (version_compare($context->getVersion(), '1.0.0', '<')) {
$data = [
['GB', 'AB', 'Aberdeenshire'],
['GB', 'AN', 'Anglesey'],
['GB', 'AG', 'Angus'],
['GB', 'AR', 'Argyll'],
['GB', 'AY', 'Ayrshire'],
['GB', 'BN', 'Banffshire'],
['GB', 'BD', 'Bedfordshire'],
['GB', 'BI', 'Berwickshire'],
['GB', 'BR', 'Breconshire'],
['GB', 'BK', 'Buckinghamshire'],
['GB', 'BU', 'Bute'],
['GB', 'CN', 'Caernarvonshire'],
['GB', 'CT', 'Caithness'],
['GB', 'CM', 'Cambridgeshire'],
['GB', 'CG', 'Cardiganshire'],
['GB', 'CR', 'Carmarthenshire'],
['GB', 'CH', 'Cheshire'],
['GB', 'CL', 'Clackmannanshire'],
['GB', 'CN', 'Cornwall and Isles of Scilly'],
['GB', 'ANT', 'County Antrim'],
['GB', 'ARM', 'County Armagh'],
['GB', 'DOW', 'County Down'],
['GB', 'FER', 'County Fermanagh'],
['GB', 'DER', 'County Londonderry'],
['GB', 'TYR', 'County Tyrone'],
['GB', 'CU', 'Cumbria'],
['GB', 'DI', 'Denbighshire'],
['GB', 'DB', 'Derbyshire'],
['GB', 'DV', 'Devon'],
['GB', 'DO', 'Dorset'],
['GB', 'DA', 'Dumbartonshire'],
['GB', 'DU', 'Dumfriesshire'],
['GB', 'DR', 'Durham'],
['GB', 'EL', 'East Lothian'],
['GB', 'ES', 'East Sussex'],
['GB', 'EX', 'Essex'],
['GB', 'FI', 'Fife'],
['GB', 'FL', 'Flintshire'],
['GB', 'GM', 'Glamorgan'],
['GB', 'GL', 'Gloucestershire'],
['GB', 'GR', 'Greater London'],
['GB', 'GM', 'Greater Manchester'],
['GB', 'HM', 'Hampshire'],
['GB', 'HT', 'Hertfordshire'],
['GB', 'IV', 'Inverness'],
['GB', 'KN', 'Kent'],
['GB', 'KE', 'Kincardineshire'],
['GB', 'KP', 'Kinross-shire'],
['GB', 'KC', 'Kirkcudbrightshire'],
['GB', 'LA', 'Lanarkshire'],
['GB', 'LC', 'Lancashire'],
['GB', 'LE', 'Leicestershire'],
['GB', 'LN', 'Lincolnshire'],
['GB', 'LD', 'London'],
['GB', 'ME', 'Merionethshire'],
['GB', 'MR', 'Merseyside'],
['GB', 'MO', 'Midlothian'],
['GB', 'MO', 'Monmouthshire'],
['GB', 'MG', 'Montgomeryshire'],
['GB', 'MY', 'Moray'],
['GB', 'NN', 'Nairnshire'],
['GB', 'NR', 'Norfolk'],
['GB', 'NH', 'Northamptonshire'],
['GB', 'NU', 'Northumberland'],
['GB', 'NY', 'North Yorkshire'],
['GB', 'NO', 'Nottinghamshire'],
['GB', 'OR', 'Orkney'],
['GB', 'OX', 'Oxfordshire'],
['GB', 'PB', 'Peebleshire'],
['GB', 'PM', 'Pembrokeshire'],
['GB', 'PT', 'Perthshire'],
['GB', 'RD', 'Radnorshire'],
['GB', 'RN', 'Renfrewshire'],
['GB', 'RS', 'Ross & Cromarty'],
['GB', 'RX', 'Roxburghshire'],
['GB', 'SL', 'Selkirkshire'],
['GB', 'SE', 'Shetland'],
['GB', 'SH', 'Shropshire'],
['GB', 'SO', 'Somerset'],
['GB', 'SY', 'South Yorkshire'],
['GB', 'ST', 'Staffordshire'],
['GB', 'SN', 'Stirlingshire'],
['GB', 'SU', 'Suffolk'],
['GB', 'SU', 'Surrey'],
['GB', 'SR', 'Sutherland'],
['GB', 'TW', 'Tyne and Wear'],
['GB', 'WR', 'Warwickshire'],
['GB', 'WE', 'West Lothian'],
['GB', 'WM', 'West Midlands'],
['GB', 'WS', 'West Sussex'],
['GB', 'WY', 'West Yorkshire'],
['GB', 'WG', 'Wigtownshire'],
['GB', 'WL', 'Wiltshire'],
['GB', 'WO', 'Worcestershire'],
['IE', 'CAR', 'Carlow'],
['IE', 'CAV', 'Cavan'],
['IE', 'CLA', 'Clare'],
['IE', 'COR', 'Cork'],
['IE', 'DON', 'Donegal'],
['IE', 'DUB', 'Dublin'],
['IE', 'GAL', 'Galway'],
['IE', 'KER', 'Kerry'],
['IE', 'KID', 'Kildare'],
['IE', 'KIK', 'Kilkenny'],
['IE', 'LET', 'Leitrim'],
['IE', 'LEX', 'Leix'],
['IE', 'LIM', 'Limerick'],
['IE', 'LOG', 'Longford'],
['IE', 'LOU', 'Louth'],
['IE', 'MAY', 'Mayo'],
['IE', 'MEA', 'Meath'],
['IE', 'MOG', 'Monaghan'],
['IE', 'OFF', 'Offaly'],
['IE', 'ROS', 'Roscommon'],
['IE', 'SLI', 'Sligo'],
['IE', 'TIP', 'Tipperary'],
['IE', 'WAT', 'Waterford'],
['IE', 'WEM', 'Westmeath'],
['IE', 'WEX', 'Wexford'],
['IE', 'WIC', 'Wicklow'],
];
foreach ($data as $row) {
$bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
$setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);
$regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region'));
$bind = ['locale' => 'en_GB', 'region_id' => $regionId, 'name' => $row[2]];
$setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
}
}
}
}
@tehben
Copy link

tehben commented Feb 23, 2023

            ['GB', 'MO', 'Midlothian'],
            ['GB', 'MO', 'Monmouthshire'],

One is Scotland, the other Wales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment