-
Notifications
You must be signed in to change notification settings - Fork 19
/
commerce_pos.api.php
138 lines (129 loc) · 4.28 KB
/
commerce_pos.api.php
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
<?php
/**
* @file
* API documentation for commerce_pos.
*/
/**
* Allows modules to define custom POS Transaction Base classes.
*
* The base classes will be attached to each POS transaction object so that
* the base classes' methods can be invoked via the transaction object's
* doAction method.
*
* Modules that define their own base class should extend the
* CommercePosTransactionBase class.
*
* Modules implementing this hook should return an associative array of arrays,
* keyed by a unique machine name for the Base class.
*
* Each Base class array can contain the following key/value pairs:
*
* - class: The PHP class name of the Base class.
* - types: (optional) An array of each type of transaction that the base class
* will be attached to.
*/
function hook_commerce_pos_transaction_base_info() {
return array(
'commerce_pos_transaction_base_actions' => array(
'class' => 'CommercePosTransactionBaseActions',
'types' => array(
CommercePosService::TRANSACTION_TYPE_SALE,
CommercePosService::TRANSACTION_TYPE_RETURN,
CommercePosService::TRANSACTION_TYPE_EXCHANGE,
),
),
);
}
/**
* Allows modules to act upon the main POS sales form AJAX submission.
*
* While this is technically possible already through the use of hook_form_alter,
* this hook allows other modules to set $form_state['transaction_updated'] to
* TRUE to force the form to reload the transaction and recalculate order
* totals.
*
* @param array $form_state
* The Drupal form API form state variable.
* @param array $triggering_element
* The element that triggered the AJAX submission. Available directly in the
* $form_state variable, but provided for ease-of-use.
*/
function hook_commerce_pos_sale_form_ajax_alter(array &$form_state, array $triggering_element) {
}
/**
* Allows modules to specify the default state for a POS transaction's order.
*
* The state is used in price calculation rules to determine applicable taxes.
*
* The administrative_area of the order's billing information will be set to
* whatever $administrative_area is set to.
*
* @param int $administrative_area
* The administrative_area to use on the transaction order.
* @param CommercePosTransaction $transaction
* The POS transaction object containing the order.
*/
function hook_commerce_pos_transaction_state_alter(&$administrative_area, CommercePosTransaction $transaction) {
if (empty($administrative_area)) {
$administrative_area = 90;
}
}
/**
* Allows modules to define payment options available in the Point of Sale.
*
* @return array
* An array of payment options.
* Keys are arbitrary but module short name is suggested. Values are arrays
* with the following key/value pairs:
* - id: An identifier for the payment option.
* - title: A human friendly name for the option.
*/
function hook_commerce_pos_payment_options_info() {
$options['commerce_pos_example'] = array(
'id' => 'commerce_pos_example',
'title' => t('Example'),
);
return $options;
}
/**
* Allows modules to attempt to act on voiding a transaction.
*
* @param CommercePosTransaction $transaction
* A commerce payment transaction.
*
* @return array
* An array with the following keys:
* - success: bool indicating the success of the void attempt.
* - message: Optional string.
*/
function hook_commerce_pos_void_payment_transaction(CommercePosTransaction $transaction) {
$voided = commerce_pos_void_transaction_example($transaction);
return array(
'success' => $voided,
'message' => t('It @result!', array(
'@result' => ($voided) ? t('worked') : t('failed'),
)),
);
}
/**
* Allows modules to change/add to the links output in the POS header.
*
* @param array $links
* An array of links. The key is the path and the value is the title of the
* link.
*/
function hook_commerce_pos_header_links_alter(array &$links) {
$links['admin/commerce/pos/transaction'] = t('Transaction');
}
/**
* Allows modules to alter our stock check for an item.
*
* @param object $product
* The product entity that we are checking the stock for.
*
* @return int
* The number of stock that this product currently has.
*/
function hook_commerce_stock_check_item_stock_alter($product) {
return $product->value()->commerce_stock[LANGUAGE_NONE][0]['value'];
}