Révision b858700c
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/commerce/modules/tax/commerce_tax.rules.inc | ||
---|---|---|
15 | 15 |
function commerce_tax_rules_action_info() { |
16 | 16 |
$actions = array(); |
17 | 17 |
|
18 |
$actions['commerce_tax_remove_taxes'] = array( |
|
19 |
'label' => t('Remove taxes applied to a line item'), |
|
20 |
'parameter' => array( |
|
21 |
'commerce_line_item' => array( |
|
22 |
'type' => 'commerce_line_item', |
|
23 |
'label' => t('Line item'), |
|
24 |
'wrapped' => TRUE, |
|
25 |
'save' => TRUE, |
|
26 |
'restriction' => 'selector', |
|
27 |
), |
|
28 |
'increase_base_price' => array( |
|
29 |
'type' => 'boolean', |
|
30 |
'label' => t('Increase the base price amount by the amount of display inclusive taxes removed.'), |
|
31 |
'description' => t('If left unchecked, a price of £2.95 including £0.49 VAT will be reduced to £2.46. If checked it will be set to £2.95 with no tax included.'), |
|
32 |
'default value' => FALSE, |
|
33 |
'restriction' => 'input', |
|
34 |
), |
|
35 |
'tax_rates' => array( |
|
36 |
'type' => 'list<text>', |
|
37 |
'label' => t('Limit removal to only a certain set of tax rates'), |
|
38 |
'description' => t('If no tax rates are selected, all tax rates will be removed from the line item. Use ctrl + click (or command + click) to deselect a tax rate.'), |
|
39 |
'options list' => 'commerce_tax_rate_titles', |
|
40 |
'optional' => TRUE, |
|
41 |
'restriction' => 'input', |
|
42 |
), |
|
43 |
), |
|
44 |
'group' => t('Commerce Tax'), |
|
45 |
); |
|
46 |
|
|
18 | 47 |
if (count(commerce_tax_rates()) > 0) { |
19 | 48 |
$actions['commerce_tax_rate_apply'] = array( |
20 | 49 |
'label' => t('Apply a tax rate to a line item'), |
... | ... | |
63 | 92 |
return $actions; |
64 | 93 |
} |
65 | 94 |
|
95 |
/** |
|
96 |
* Rules actions: removes all taxes applied to a line item. |
|
97 |
*/ |
|
98 |
function commerce_tax_remove_taxes($line_item_wrapper, $increase_base_price, $tax_rates) { |
|
99 |
// Load all the tax component types to look for matching price components in |
|
100 |
// the line item's unit price. Filter the list by tax rates that should be |
|
101 |
// removed if only some were specified. |
|
102 |
$component_types = commerce_tax_commerce_price_component_type_info(); |
|
103 |
|
|
104 |
if (!empty($tax_rates)) { |
|
105 |
foreach ($component_types as $name => $component_type) { |
|
106 |
if (!in_array($component_type['tax_rate'], $tax_rates)) { |
|
107 |
unset($component_types[$name]); |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
// Loop over the price components in the line item's unit price. |
|
113 |
$price = $line_item_wrapper->commerce_unit_price->value(); |
|
114 |
$new_components = array(); |
|
115 |
|
|
116 |
foreach ($price['data']['components'] as $key => $component) { |
|
117 |
// Look for components that match one of the defined tax price components. |
|
118 |
if (in_array($component['name'], array_keys($component_types))) { |
|
119 |
// Remove it from the components array. |
|
120 |
unset($price['data']['components'][$key]); |
|
121 |
|
|
122 |
// If the component was marked as "included" in the price amount, update |
|
123 |
// the price amount to reflect the difference. |
|
124 |
if (!empty($component['included'])) { |
|
125 |
$price['amount'] -= $component['price']['amount']; |
|
126 |
|
|
127 |
// If the user opted to increase the base price by the amount of the |
|
128 |
// display inclusive taxes removed, add them back as new price components. |
|
129 |
if (!empty($increase_base_price)) { |
|
130 |
$price['data']['components'][] = array( |
|
131 |
'name' => 'base_price', |
|
132 |
'price' => array( |
|
133 |
'amount' => $component['price']['amount'], |
|
134 |
'currency_code' => $component['price']['currency_code'], |
|
135 |
'data' => array(), |
|
136 |
), |
|
137 |
'included' => TRUE, |
|
138 |
); |
|
139 |
|
|
140 |
$price['amount'] += $component['price']['amount']; |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
$line_item_wrapper->commerce_unit_price = $price; |
|
147 |
} |
|
148 |
|
|
66 | 149 |
/** |
67 | 150 |
* Rules action: loads and applies a tax rate to the given line item. |
68 | 151 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules