-
Notifications
You must be signed in to change notification settings - Fork 2
/
commerce_rma.install
137 lines (122 loc) · 5.08 KB
/
commerce_rma.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
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
<?php
/**
* @file
* Contains install and update functions for RMA.
*/
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_install().
*/
function commerce_rma_install() {
// Allow authenticated users to manage own payment methods.
user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['add commerce return entities']);
user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['use commerce_return default cancel transition']);
user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['return order']);
}
/**
* Recreate Total returned price (Confirmed) field.
*/
function commerce_rma_update_8714() {
$field_storage_definition = BaseFieldDefinition::create('commerce_price')
->setLabel(t('Total confirmed returned price'))
->setDescription(t('The returned total price (Value which should be returned to user). Manager can modify this value if manual return is in use.'))
->setReadOnly(TRUE)
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('confirmed_total_price', 'commerce_return', 'commerce_rma', $field_storage_definition);
}
/**
* Recreate Expected resolution field.
*/
function commerce_rma_update_8716() {
$field_storage_definition = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Expected resolution'))
->setDescription(t('The expected resolution of item return.'))
->setRequired(TRUE)
->setSetting('target_type', 'commerce_return_reason')
->setSetting('handler', 'default')
->setCardinality(1)
->setReadOnly(TRUE)
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => -1,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('expected_resolution', 'commerce_return_item', 'commerce_rma', $field_storage_definition);
}
/**
* Recreate Total return price field.
*/
function commerce_rma_update_8717() {
$field_storage_definition = BaseFieldDefinition::create('commerce_price')
->setLabel(t('Total return price'))
->setDescription(t('The return total price (Value which should be returned to user). Manager can modify this value if manual return is in use.'))
->setReadOnly(TRUE)
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'commerce_unit_price',
'weight' => -4,
]);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('total_price', 'commerce_return', 'commerce_rma', $field_storage_definition);
}
/**
* set correct Label for confirmed total price field.
*/
function commerce_rma_update_8718() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('confirmed_total_price', 'commerce_return');
$field_storage_definition->setLabel(t('Total confirmed returned price'));
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}
/**
* Set confirmed_price field readonly.
*/
function commerce_rma_update_8719() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('confirmed_price', 'commerce_return_item');
$field_storage_definition->setReadOnly(TRUE);
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}
/**
* Recreate Shipping info field.
*/
function commerce_rma_update_8720() {
$field_storage_definition = BaseFieldDefinition::create('entity_reference_revisions')
->setLabel(t('Shipping information'))
->setDescription(t('Shipping profile'))
->setSetting('target_type', 'profile')
->setSetting('handler', 'default')
->setSetting('handler_settings', ['target_bundles' => ['customer']])
->setTranslatable(TRUE)
->setDisplayOptions('form', [
'type' => 'rma_commerce_billing_profile',
'weight' => 0,
'settings' => [],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('shipping_profile', 'commerce_return', 'commerce_rma', $field_storage_definition);
}
/**
* Set billing profile field readonly.
*/
function commerce_rma_update_8721() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('billing_profile', 'commerce_return');
$field_storage_definition->setReadOnly(TRUE);
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}