|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Directory\Setup\Patch\Data; |
| 9 | + |
| 10 | +use Magento\Directory\Setup\DataInstaller; |
| 11 | +use Magento\Directory\Setup\DataInstallerFactory; |
| 12 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 13 | +use Magento\Framework\Setup\Patch\DataPatchInterface; |
| 14 | +use Magento\Framework\Setup\Patch\PatchVersionInterface; |
| 15 | + |
| 16 | +/** |
| 17 | + * Add Regions/States for India. |
| 18 | + */ |
| 19 | +class AddRegionsForIndia implements DataPatchInterface |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var ModuleDataSetupInterface |
| 23 | + */ |
| 24 | + private ModuleDataSetupInterface $moduleDataSetup; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var DataInstallerFactory |
| 28 | + */ |
| 29 | + private DataInstallerFactory $dataInstallerFactory; |
| 30 | + |
| 31 | + /** |
| 32 | + * AddRegionsForIndia constructor. |
| 33 | + * |
| 34 | + * @param ModuleDataSetupInterface $moduleDataSetup |
| 35 | + * @param DataInstallerFactory $dataInstallerFactory |
| 36 | + */ |
| 37 | + public function __construct( |
| 38 | + ModuleDataSetupInterface $moduleDataSetup, |
| 39 | + DataInstallerFactory $dataInstallerFactory |
| 40 | + ) { |
| 41 | + $this->moduleDataSetup = $moduleDataSetup; |
| 42 | + $this->dataInstallerFactory = $dataInstallerFactory; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @inheritdoc |
| 47 | + */ |
| 48 | + public function apply() |
| 49 | + { |
| 50 | + /** @var DataInstaller $dataInstaller */ |
| 51 | + $dataInstaller = $this->dataInstallerFactory->create(); |
| 52 | + $dataInstaller->addCountryRegions( |
| 53 | + $this->moduleDataSetup->getConnection(), |
| 54 | + $this->getDataForIndia() |
| 55 | + ); |
| 56 | + |
| 57 | + return $this; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Indian states data. |
| 62 | + * |
| 63 | + * @return array |
| 64 | + */ |
| 65 | + private function getDataForIndia(): array |
| 66 | + { |
| 67 | + return [ |
| 68 | + ['IN', 'LA', 'Ladakh'] |
| 69 | + ]; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @inheritdoc |
| 74 | + */ |
| 75 | + public static function getDependencies(): array |
| 76 | + { |
| 77 | + return [ |
| 78 | + InitializeDirectoryData::class, |
| 79 | + ]; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @inheritdoc |
| 84 | + */ |
| 85 | + public function getAliases(): array |
| 86 | + { |
| 87 | + return []; |
| 88 | + } |
| 89 | +} |
0 commit comments