forked from mglaman/commerce_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_demo.install
61 lines (53 loc) · 1.98 KB
/
commerce_demo.install
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
<?php
use Drupal\commerce_order\Entity\OrderType;
use Drupal\commerce_shipping\Entity\ShippingMethod;
function commerce_demo_install() {
$currency_importer = \Drupal::service('commerce_price.currency_importer');
$store_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_store');
$currency_importer->import('USD');
$store_values = [
'type' => 'online',
'uid' => 1,
'name' => 'Demo store',
'mail' => '[email protected]',
'address' => [
'country_code' => 'US',
'postal_code' => '29616',
'locality' => 'Greenville',
'address_line1' => 'PO Box 26851',
'administrative_area' => 'SC',
],
'billing_countries' => [
'US',
],
'shipping_countries' => [
'US',
],
'default_currency' => 'USD',
];
/** @var \Drupal\commerce_store\Entity\StoreInterface $store */
$store = $store_storage->create($store_values);
$store->save();
$store_storage->markAsDefault($store);
// Enable shipping on the default order type.
$default_order_type = OrderType::load('default');
$default_order_type->setThirdPartySetting('commerce_checkout', 'checkout_flow', 'shipping');
/** @var \Drupal\commerce\ConfigurableFieldManagerInterface $configurable_field_manager */
$configurable_field_manager = \Drupal::service('commerce.configurable_field_manager');
$field_definition = commerce_shipping_build_shipment_field_definition($default_order_type->id());
$configurable_field_manager->createField($field_definition);
$default_order_type->setThirdPartySetting('commerce_shipping', 'shipment_type', 'default');
$default_order_type->save();
// Create demo shipping method.
$shipping_method = ShippingMethod::create([
'stores' => [$store->id()],
'name' => 'Table rate',
'status' => 1,
'plugin' => [
'target_plugin_id' => 'demo_table_rate',
'target_plugin_configuration' => [],
],
]);
$shipping_method->save();
\Drupal::getContainer()->get('commerce_demo.migration_runner')->run();
}