-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommerce_amazon_sp_api.install
More file actions
207 lines (187 loc) · 6.15 KB
/
commerce_amazon_sp_api.install
File metadata and controls
207 lines (187 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* @file
* The install file.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\commerce_amazon_sp_api\Entity\AmazonAppInterface;
/**
* Implements hook_schema().
*/
function commerce_amazon_sp_api_schema(): array {
$schema['commerce_amazon_inventory'] = [
'description' => 'Table used for tracking Amazon inventory',
'fields' => [
'id' => [
'description' => 'Primary Key: id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'sku' => [
'description' => 'The seller SKU of the item.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
],
'fulfillableQuantity' => [
'description' => 'The item quantity that can be picked, packed, and shipped.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'marketplace' => [
'description' => 'The marketplace',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'timestamp' => [
'description' => 'The date and time that any quantity was last updated.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['id'],
'indexes' => [
'sku' => ['sku'],
],
];
return $schema;
}
/**
* Add marketplace column.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10001(&$sandbox): void {
$spec = commerce_amazon_sp_api_schema();
$schema = Database::getConnection()->schema();
$marketplace = $spec['commerce_amazon_inventory']['fields']['marketplace'];
// Add the new column.
$schema->addField('commerce_amazon_inventory', 'marketplace', $marketplace);
}
/**
* Add region field.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10002(&$sandbox): void {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$storage_definition = BaseFieldDefinition::create('list_string')
->setLabel(t('AWS region'))
->setSetting('allowed_values', AmazonAppInterface::AMAZON_REGIONS)
->setDisplayOptions('form', [
'type' => 'options_buttons',
'weight' => 4,
])
->setDisplayConfigurable('form', TRUE);
$entity_definition_update->installFieldStorageDefinition('region', 'commerce_amazon_app', 'commerce_amazon_sp_api', $storage_definition);
}
/**
* Add integration field.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10003(&$sandbox): void {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$storage_definition = BaseFieldDefinition::create('map')
->setLabel(t('Integration'))
->setDescription(t('A serialized array of integration mapping for Commerce core'));
$entity_definition_update->installFieldStorageDefinition('mapping', 'commerce_amazon_marketplace', 'commerce_amazon_sp_api', $storage_definition);
}
/**
* Add logging field.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10005(&$sandbox): void {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Log requests'))
->setDefaultValue(FALSE)
->setDescription(t('Log all requests'))
->setSetting('on_label', 'Enabled')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$entity_definition_update->installFieldStorageDefinition('logging', 'commerce_amazon_app', 'commerce_amazon_sp_api', $storage_definition);
}
/**
* Reorganize table.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10006(&$sandbox): void {
$spec = commerce_amazon_sp_api_schema();
$schema = Database::getConnection()->schema();
$schema->dropTable('commerce_amazon_inventory');
$schema->createTable('commerce_amazon_inventory', $spec['commerce_amazon_inventory']);
}
/**
* Add preview fulfillment field.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10007(&$sandbox): void {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Preview fulfillment'))
->setDescription(t('Returns a list of fulfillment order previews based on shipping criteria that you specify.'))
->setDefaultValue(FALSE)
->setRequired(TRUE)
->setSettings([
'on_label' => t('Yes'),
'off_label' => t('No'),
])
->setSetting('on_label', 'Yes')
->setDisplayOptions('form', [
'type' => 'options_buttons',
])
->setDisplayConfigurable('form', TRUE);
$entity_definition_update->installFieldStorageDefinition('preview_fulfillment', 'commerce_amazon_marketplace', 'commerce_amazon_sp_api', $storage_definition);
}
/**
* Add partial sync inventory.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10008(&$sandbox): void {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Incremental sync'))
->setDescription(t('Sync partially via startDateTime which is set by each cron run.'))
->setDefaultValue(FALSE)
->setRequired(TRUE)
->setSettings([
'on_label' => t('Yes'),
'off_label' => t('No'),
])
->setSetting('on_label', 'Yes')
->setDisplayOptions('form', [
'type' => 'options_buttons',
])
->setDisplayConfigurable('form', TRUE);
$entity_definition_update->installFieldStorageDefinition('incremental_sync', 'commerce_amazon_marketplace', 'commerce_amazon_sp_api', $storage_definition);
}
/**
* Add partial sync inventory.
*
* Implements hook_update_N().
*/
function commerce_amazon_sp_api_update_10009(&$sandbox): void {
$schema = Database::getConnection()->schema();
if ($schema->tableExists('commerce_amazon_inventory')) {
$new = [
'description' => 'The seller SKU of the item.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
];
$schema->changeField('commerce_amazon_inventory', 'sku', 'sku', $new);
}
}