|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* create standard country and regions. |
|
5
|
|
|
* |
|
6
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
7
|
|
|
* @package: ecommerce |
|
8
|
|
|
* @sub-package: tasks |
|
9
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
10
|
|
|
**/ |
|
11
|
|
|
class EcommerceTaskCountryAndRegion extends BuildTask |
|
12
|
|
|
{ |
|
13
|
|
|
protected $title = 'Create standard countries and regions'; |
|
14
|
|
|
|
|
15
|
|
|
protected $description = 'Adds all countries to the EcommerceCountry list'; |
|
16
|
|
|
|
|
17
|
|
|
public function run($request) |
|
18
|
|
|
{ |
|
19
|
|
|
$count = 0; |
|
20
|
|
|
$array = EcommerceCountry::get_country_dropdown(); |
|
21
|
|
|
$allowedArray = EcommerceConfig::get('EcommerceCountry', 'allowed_country_codes'); |
|
22
|
|
|
foreach ($array as $code => $name) { |
|
23
|
|
|
$ecommerceCountry = DataObject::get_one( |
|
24
|
|
|
'EcommerceCountry', |
|
25
|
|
|
array('Code' => Convert::raw2sql($code)), |
|
26
|
|
|
$cacheDataObjectGetOne = false |
|
27
|
|
|
); |
|
28
|
|
|
if ($ecommerceCountry) { |
|
29
|
|
|
//do nothing |
|
30
|
|
|
++$count; |
|
31
|
|
|
} else { |
|
32
|
|
|
DB::alteration_message("adding $code to Ecommerce Country", 'created'); |
|
33
|
|
|
$ecommerceCountry = EcommerceCountry::create(); |
|
34
|
|
|
$ecommerceCountry->Code = $code; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
if ($allowedArray && count($allowedArray)) { |
|
37
|
|
|
if (in_array($code, $allowedArray)) { |
|
38
|
|
|
//do nothing |
|
39
|
|
|
$ecommerceCountry->DoNotAllowSales = 0; |
|
40
|
|
|
} else { |
|
41
|
|
|
$ecommerceCountry->DoNotAllowSales = 1; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
$ecommerceCountry->Name = $name; |
|
45
|
|
|
$ecommerceCountry->write(); |
|
46
|
|
|
} |
|
47
|
|
|
DB::alteration_message("Created / Checked $count Ecommerce Countries", 'edited'); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* update EcommerceCountry.DoNotAllowSales to 1 so that you can not sell to any country. |
|
53
|
|
|
* |
|
54
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
55
|
|
|
* @package: ecommerce |
|
56
|
|
|
* @sub-package: tasks |
|
57
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
58
|
|
|
**/ |
|
59
|
|
|
class EcommerceTaskCountryAndRegion_DisallowAllCountries extends BuildTask |
|
60
|
|
|
{ |
|
61
|
|
|
protected $title = 'Disallows sale to all countries'; |
|
62
|
|
|
|
|
63
|
|
|
protected $description = 'We add this task to reset all countries from Allow Sales to Disallow Sales - as a good starting point when selling to just a few countries'; |
|
64
|
|
|
|
|
65
|
|
|
public function run($request) |
|
66
|
|
|
{ |
|
67
|
|
|
$count = 0; |
|
|
|
|
|
|
68
|
|
|
$array = EcommerceCountry::get_country_dropdown(); |
|
|
|
|
|
|
69
|
|
|
$allowedArray = EcommerceCountry::get() |
|
70
|
|
|
->filter(array('DoNotAllowSales' => 0)); |
|
71
|
|
|
if ($allowedArray->count()) { |
|
72
|
|
|
foreach ($allowedArray as $obj) { |
|
73
|
|
|
$obj->DoNotAllowSales = 1; |
|
74
|
|
|
$obj->write(); |
|
75
|
|
|
DB::alteration_message('Disallowing sales to '.$obj->Name); |
|
76
|
|
|
} |
|
77
|
|
|
} else { |
|
78
|
|
|
DB::alteration_message('Could not find any countries that are allowed', 'created'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
/** |
|
83
|
|
|
* update EcommerceCountry.DoNotAllowSales to 0 so that you can sell to all countries. |
|
84
|
|
|
* |
|
85
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
86
|
|
|
* @package: ecommerce |
|
87
|
|
|
* @sub-package: tasks |
|
88
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
89
|
|
|
**/ |
|
90
|
|
|
class EcommerceTaskCountryAndRegion_AllowAllCountries extends BuildTask |
|
91
|
|
|
{ |
|
92
|
|
|
protected $title = 'Allows sale to all countries'; |
|
93
|
|
|
|
|
94
|
|
|
protected $description = 'We add this task to reset all countries from Allow Sales to Disallow Sales - as a good starting point when selling to just a few countries'; |
|
95
|
|
|
|
|
96
|
|
|
public function run($request) |
|
97
|
|
|
{ |
|
98
|
|
|
$count = 0; |
|
|
|
|
|
|
99
|
|
|
$array = EcommerceCountry::get_country_dropdown(); |
|
|
|
|
|
|
100
|
|
|
$allowedArray = EcommerceCountry::get() |
|
101
|
|
|
->filter(array('DoNotAllowSales' => 1)); |
|
102
|
|
|
if ($allowedArray->count()) { |
|
103
|
|
|
foreach ($allowedArray as $obj) { |
|
104
|
|
|
$obj->DoNotAllowSales = 0; |
|
105
|
|
|
$obj->write(); |
|
106
|
|
|
DB::alteration_message('Disallowing sales to '.$obj->Name); |
|
107
|
|
|
} |
|
108
|
|
|
} else { |
|
109
|
|
|
DB::alteration_message('Could not find any countries that are not allowed', 'created'); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.