forked from smmccabe/commerce_shipping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommerce_shipping.module
87 lines (79 loc) · 2.55 KB
/
commerce_shipping.module
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
<?php
/**
* @file
* Contains commerce_shipping.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_help().
*/
function commerce_shipping_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the commerce_shipping module.
case 'help.page.commerce_shipping':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Handles shipping and fulfilment for Drupal Commerce') . '</p>';
return $output;
default:
}
}
/**
* Adds the default shipment items field to the shipment.
*
* Shipment items can't be a base field because the Views integration is broken.
* Instead, it is created as a configurable field for the shipment.
*
*/
function commerce_shipping_add_shipment_item_field() {
$field_storage = FieldStorageConfig::loadByName('commerce_shipment', 'shipment_items');
$field = FieldConfig::loadByName('commerce_shipment', NULL, 'shipment_items');
if (empty($field_storage)) {
$field_storage = FieldStorageConfig::create([
'field_name' => 'shipment_items',
'entity_type' => 'commerce_shipment',
'type' => 'entity_reference',
'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'commerce_shipment_item',
],
'locked' => TRUE,
'translatable' => FALSE,
]);
$field_storage->save();
}
if (empty($field)) {
$field = FieldConfig::create([
'field_storage' => $field_storage,
'label' => 'Shipment items',
'bundle' => 'commerce_shipment',
'required' => TRUE,
'settings' => [
'handler' => 'default',
'handler_settings' => [],
],
'translatable' => FALSE,
]);
$field->save();
//Evan you can probably use this for refernce to some stuff you might need to add for this
/*$view_display = commerce_get_entity_display('commerce_order', $shipment->id(), 'view');
$view_display->setComponent('line_items', [
'type' => 'commerce_line_item_table',
'weight' => 0,
]);
$view_display->save();
$form_display = commerce_get_entity_display('commerce_order', $shipment->id(), 'form');
$form_display->setComponent('line_items', [
'type' => 'inline_entity_form_complex',
'weight' => 0,
'settings' => [
'override_labels' => TRUE,
'label_singular' => 'line item',
'label_plural' => 'line items',
],
]);
$form_display->save();*/
}
}