Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateAllowedMethods.php
Go to the documentation of this file.
1 <?php
8 
12 
18 {
22  private $moduleDataSetup;
23 
28  public function __construct(
29  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
30  ) {
31  $this->moduleDataSetup = $moduleDataSetup;
32  }
33 
37  public function apply()
38  {
39  $connection = $this->moduleDataSetup->getConnection();
40  $configDataTable = $this->moduleDataSetup->getTable('core_config_data');
41  $oldToNewMethodCodesMap = [
42  'First-Class' => '0_FCLE',
43  'First-Class Mail International Large Envelope' => 'INT_14',
44  'First-Class Mail International Letter' => 'INT_13',
45  'First-Class Mail International Letters' => 'INT_13',
46  'First-Class Mail International Package' => 'INT_15',
47  'First-Class Mail International Parcel' => 'INT_13',
48  'First-Class Package International Service' => 'INT_15',
49  'First-Class Mail' => '0_FCLE',
50  'First-Class Mail Flat' => '0_FCLE',
51  'First-Class Mail Large Envelope' => '0_FCLE',
52  'First-Class Mail International' => 'INT_14',
53  'First-Class Mail Letter' => '0_FCL',
54  'First-Class Mail Parcel' => '0_FCP',
55  'First-Class Mail Package' => '0_FCP',
56  'First-Class Package Service - Retail' => '0_FCP',
57  'Parcel Post' => '4',
58  'Retail Ground' => '4',
59  'Media Mail' => '6',
60  'Library Mail' => '7',
61  'Express Mail' => '3',
62  'Express Mail PO to PO' => '3',
63  'Express Mail Flat Rate Envelope' => '13',
64  'Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee' => '25',
65  'Express Mail Sunday/Holiday Guarantee' => '23',
66  'Express Mail Flat Rate Envelope Hold For Pickup' => '27',
67  'Express Mail Hold For Pickup' => '2',
68  'Global Express Guaranteed (GXG)' => 'INT_4',
69  'Global Express Guaranteed Non-Document Rectangular' => 'INT_6',
70  'Global Express Guaranteed Non-Document Non-Rectangular' => 'INT_7',
71  'USPS GXG Envelopes' => 'INT_12',
72  'Express Mail International' => 'INT_1',
73  'Express Mail International Flat Rate Envelope' => 'INT_10',
74  'Priority Mail' => '1',
75  'Priority Mail Small Flat Rate Box' => '28',
76  'Priority Mail Medium Flat Rate Box' => '17',
77  'Priority Mail Large Flat Rate Box' => '22',
78  'Priority Mail Flat Rate Envelope' => '16',
79  'Priority Mail International' => 'INT_2',
80  'Priority Mail International Flat Rate Envelope' => 'INT_8',
81  'Priority Mail International Small Flat Rate Box' => 'INT_16',
82  'Priority Mail International Medium Flat Rate Box' => 'INT_9',
83  'Priority Mail International Large Flat Rate Box' => 'INT_11',
84  ];
85 
86  $select = $connection->select()
87  ->from($configDataTable)
88  ->where(
89  'path IN (?)',
90  ['carriers/usps/free_method', 'carriers/usps/allowed_methods']
91  );
92  $oldConfigValues = $connection->fetchAll($select);
93 
94  foreach ($oldConfigValues as $oldValue) {
95  if (stripos($oldValue['path'], 'free_method') !== false
96  && isset($oldToNewMethodCodesMap[$oldValue['value']])
97  ) {
98  $newValue = $oldToNewMethodCodesMap[$oldValue['value']];
99  } elseif (stripos($oldValue['path'], 'allowed_methods') !== false) {
100  $newValuesList = [];
101  foreach (explode(',', $oldValue['value']) as $shippingMethod) {
102  if (isset($oldToNewMethodCodesMap[$shippingMethod])) {
103  $newValuesList[] = $oldToNewMethodCodesMap[$shippingMethod];
104  }
105  }
106  $newValue = implode(',', $newValuesList);
107  } else {
108  continue;
109  }
110 
111  if ($newValue && $newValue != $oldValue['value']) {
112  $whereConfigId = $connection->quoteInto('config_id = ?', $oldValue['config_id']);
113  $connection->update($configDataTable, ['value' => $newValue], $whereConfigId);
114  }
115  }
116  }
117 
121  public static function getDependencies()
122  {
123  return [];
124  }
125 
129  public static function getVersion()
130  {
131  return '2.0.1';
132  }
133 
137  public function getAliases()
138  {
139  return [];
140  }
141 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$shippingMethod
Definition: popup.phtml:12
$connection
Definition: bulk.php:13
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)