|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
|
6
|
|
|
* @package: ecommerce |
|
7
|
|
|
* @sub-package: ecommerce_tax |
|
8
|
|
|
* @description: special tax rules for individual buyables |
|
9
|
|
|
* |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class GSTTaxDecorator extends DataExtension |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* standard SS method |
|
19
|
|
|
* @return Array |
|
20
|
|
|
*/ |
|
21
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
22
|
|
|
"ExcludedFrom" => "GSTTaxModifierOptions", |
|
23
|
|
|
"AdditionalTax" => "GSTTaxModifierOptions" |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* for variations, use product for data |
|
28
|
|
|
* @return DataList |
|
29
|
|
|
*/ |
|
30
|
|
View Code Duplication |
public function BuyableCalculatedExcludedFrom() |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
if ($this->owner instanceof ProductVariation) { |
|
|
|
|
|
|
33
|
|
|
if ($product = $this->owner->Product()) { |
|
34
|
|
|
return $product->ExcludedFrom(); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
return $this->owner->ExcludedFrom(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* for variations, use product for data |
|
42
|
|
|
* @return DataList |
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
public function BuyableCalculatedAdditionalTax() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
if ($this->owner instanceof ProductVariation) { |
|
|
|
|
|
|
47
|
|
|
if ($product = $this->owner->Product()) { |
|
48
|
|
|
return $product->AdditionalTax(); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
return $this->owner->AdditionalTax(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* standard SS method |
|
57
|
|
|
* @param Object - $fields (FieldList) |
|
58
|
|
|
* @return Object - FieldList |
|
|
|
|
|
|
59
|
|
|
*/ |
|
60
|
|
|
public function updateCMSFields(FieldList $fields) |
|
61
|
|
|
{ |
|
62
|
|
|
$additionalWhereForDefault = ""; |
|
63
|
|
|
$fields->removeByName("ExcludedFrom"); |
|
64
|
|
|
$fields->removeByName("AdditionalTax"); |
|
65
|
|
|
$tabName = "Root.Tax"; |
|
66
|
|
|
if ($this->owner instanceof ProductVariation) { |
|
|
|
|
|
|
67
|
|
|
$fields->addFieldToTab( |
|
68
|
|
|
$tabName, |
|
69
|
|
|
new LiteralField( |
|
70
|
|
|
"SeeProductForAdditionalTax", |
|
71
|
|
|
_t("GSTTaxModifier.SEE_PARENT", "See parent Product for Additional Tax") |
|
72
|
|
|
) |
|
73
|
|
|
); |
|
74
|
|
|
} else { |
|
75
|
|
|
//additional taxes |
|
76
|
|
|
$additionalOptions = GSTTaxModifierOptions::get()->filter(array("DoesNotApplyToAllProducts" => 1)); |
|
77
|
|
|
if ($additionalOptions->count()) { |
|
78
|
|
|
$additionalOptionsList = $additionalOptions->map()->toArray(); |
|
79
|
|
|
$fields->addFieldToTab( |
|
80
|
|
|
$tabName, |
|
81
|
|
|
new CheckboxSetField( |
|
82
|
|
|
"AdditionalTax", |
|
83
|
|
|
_t("GSTTaxMofidifier.ADDITIONAL_TAXES", "Additional taxes ..."), |
|
84
|
|
|
$additionalOptionsList |
|
85
|
|
|
) |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
if ($this->owner instanceof ProductVariation) { |
|
|
|
|
|
|
90
|
|
|
$fields->addFieldToTab( |
|
91
|
|
|
$tabName, |
|
92
|
|
|
new LiteralField( |
|
93
|
|
|
"SeeProductForExcludedFrom", |
|
94
|
|
|
_t("GSTTaxModifier.SEE_PARRENT", "See parent product for excluded taxes") |
|
95
|
|
|
) |
|
96
|
|
|
); |
|
97
|
|
|
} else { |
|
98
|
|
|
//excluded options |
|
99
|
|
|
$excludedOptions = GSTTaxModifierOptions::get()->filter(array("DoesNotApplyToAllProducts" => 0)); |
|
100
|
|
|
if ($excludedOptions->count()) { |
|
101
|
|
|
$excludedOptionsList = $excludedOptions->map()->toArray(); |
|
102
|
|
|
$fields->addFieldToTab( |
|
103
|
|
|
$tabName, |
|
104
|
|
|
new CheckboxSetField( |
|
105
|
|
|
"ExcludedFrom", |
|
106
|
|
|
_t("GSTTaxMofidifier.EXCLUDE_TAXES", "Taxes that do not apply ..."), |
|
107
|
|
|
$excludedOptionsList |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
$additionalWhereForDefault = " \"GSTTaxModifierOptions\".\"ID\" NOT IN (".implode(", ", $excludedOptions->map("ID", "ID")->toArray()).")"; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
//default options |
|
114
|
|
|
$defaultOptions = GSTTaxModifierOptions::get() |
|
115
|
|
|
->filter(array("DoesNotApplyToAllProducts" => 0)) |
|
116
|
|
|
->where($additionalWhereForDefault); |
|
117
|
|
|
if ($defaultOptions->count()) { |
|
118
|
|
|
$fields->addFieldToTab( |
|
119
|
|
|
$tabName, |
|
120
|
|
|
new ReadonlyField("AlwaysApplies", "+ ".implode(", ", $defaultOptions->map()->toArray()).".") |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* returns the calculated price for the buyable including tax |
|
127
|
|
|
* @return float |
|
|
|
|
|
|
128
|
|
|
* |
|
129
|
|
|
*/ |
|
130
|
|
|
public function TaxInclusivePrice() |
|
131
|
|
|
{ |
|
132
|
|
|
user_error("to be completed"); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* returns the calculated price for the buyable excluding tax |
|
137
|
|
|
* @return float |
|
|
|
|
|
|
138
|
|
|
* |
|
139
|
|
|
*/ |
|
140
|
|
|
public function TaxExclusivePrice() |
|
141
|
|
|
{ |
|
142
|
|
|
user_error("to be completed"); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.