|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class CountryPrice_TestController extends ContentController |
|
5
|
|
|
{ |
|
6
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
7
|
|
|
"whoami" => true, |
|
8
|
|
|
"addproducts" => true, |
|
9
|
|
|
"setmycountry" => true, |
|
10
|
|
|
"resetmycountry" => true, |
|
11
|
|
|
"currencypercountry" => true, |
|
12
|
|
|
"countrieswithoutdistributor" => true, |
|
13
|
|
|
"stockistcountrieswithoutcountry" => true |
|
14
|
|
|
); |
|
15
|
|
|
|
|
16
|
|
|
public function init() |
|
17
|
|
|
{ |
|
18
|
|
|
parent::init(); |
|
19
|
|
|
if (! Permission::check('ADMIN')) { |
|
20
|
|
|
return Security::permissionFailure($this, 'This page is secured and you need administrator rights to access it. You can also save the page in the CMS to get 15 minutes access without being logged in.'); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function index() |
|
25
|
|
|
{ |
|
26
|
|
|
echo "<hr />"; |
|
27
|
|
|
echo "<hr />"; |
|
28
|
|
|
echo "<hr />"; |
|
29
|
|
|
|
|
30
|
|
|
foreach (self::$allowed_actions as $action => $notNeeded) { |
|
31
|
|
|
if (!in_array($action, array("setmycountry"))) { |
|
32
|
|
|
DB::alteration_message("<a href=\"".$this->Link($action)."\">$action</a>"); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
DB::alteration_message("<a href=\"/dev/ecommerce/\">All E-commerce Tools</a>"); |
|
36
|
|
|
echo "<hr />"; |
|
37
|
|
|
$countries = CountryPrice_EcommerceCountry::get_real_countries_list(); |
|
38
|
|
|
$countryLinks = array(); |
|
39
|
|
View Code Duplication |
foreach ($countries as $country) { |
|
|
|
|
|
|
40
|
|
|
$code = $country->Code; |
|
41
|
|
|
$name = $country->Name; |
|
42
|
|
|
$countryLinks[] = "<a href=\"".$this->Link("setmycountry/$code/?countryfortestingonly=$code")."\">$name</a>"; |
|
43
|
|
|
} |
|
44
|
|
|
DB::alteration_message("Available Countries: ".implode(", ", $countryLinks)); |
|
45
|
|
|
$countries = EcommerceCountry::get()->exclude(array('Code' => $countries->column('Code'))); |
|
46
|
|
|
$countryLinks = array(); |
|
47
|
|
View Code Duplication |
foreach ($countries as $country) { |
|
|
|
|
|
|
48
|
|
|
$code = $country->Code; |
|
49
|
|
|
$name = $country->Name; |
|
50
|
|
|
$countryLinks[] = "<a href=\"".$this->Link("setmycountry/$code/?countryfortestingonly=$code")."\">$name</a>"; |
|
51
|
|
|
} |
|
52
|
|
|
DB::alteration_message("Other Countries: ".implode(", ", $countryLinks)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function Link($action = null) |
|
57
|
|
|
{ |
|
58
|
|
|
return "/distributors-test/".$action; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function addproducts() |
|
62
|
|
|
{ |
|
63
|
|
|
$sc = ShoppingCart::singleton(); |
|
64
|
|
|
$count = 1; |
|
65
|
|
|
$products = Product::get()->filter("AllowPurchase", 1)->limit(20)->Sort("Rand()"); |
|
66
|
|
|
foreach ($products as $product) { |
|
67
|
|
|
if ($product->canPurchase() && $count < 3) { |
|
68
|
|
|
$count++; |
|
69
|
|
|
$sc->addBuyable($product, rand(1, 5)); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
$count = 1; |
|
73
|
|
|
if (class_exists('ProductVariation')) { |
|
74
|
|
|
$productVariations = ProductVariation::get()->filter("AllowPurchase", 1)->limit(20)->Sort("Rand()"); |
|
75
|
|
|
foreach ($productVariations as $productVariation) { |
|
76
|
|
|
if ($productVariation->canPurchase() && $count < 3) { |
|
77
|
|
|
$count++; |
|
78
|
|
|
$sc->addBuyable($productVariation, rand(1, 5)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
return $this->redirect($sc->Link()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
public function resetmycountry($request) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$this->resetSessionVars(); |
|
89
|
|
|
$o = ShoppingCart::current_order(); |
|
90
|
|
|
if ($o) { |
|
91
|
|
|
$o->delete(); |
|
92
|
|
|
} |
|
93
|
|
|
DB::alteration_message("Cleared countries"); |
|
94
|
|
|
return $this->redirect("/dev/ecommerce/ecommercetaskcartmanipulation_current"); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
public function setmycountry($request) |
|
99
|
|
|
{ |
|
100
|
|
|
$value = strtoupper(Convert::raw2sql($request->param("ID"))); |
|
101
|
|
|
if ($o = ShoppingCart::current_order()) { |
|
102
|
|
|
$this->resetSessionVars(); |
|
103
|
|
|
$o->SetCountryFields($value); |
|
104
|
|
|
$o->CurrencyCountry = $value; |
|
105
|
|
|
$o->OriginatingCountryCode = $value; |
|
106
|
|
|
$o->write(); |
|
107
|
|
|
$o->SetCountryFields($value); |
|
108
|
|
|
$o->CurrencyCountry = $value; |
|
109
|
|
|
$o->OriginatingCountryCode = $value; |
|
110
|
|
|
$o->write(); |
|
111
|
|
|
CountryPrice_OrderDOD::localise_order(); |
|
112
|
|
|
CountryPrice_OrderDOD::localise_order(); |
|
113
|
|
|
CountryPrice_OrderDOD::localise_order(); |
|
114
|
|
|
return $this->redirectBack('/dev/ecommerce/ecommercetaskcartmanipulation_current/'); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
user_error("There is no cart available."); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
private function resetSessionVars() |
|
120
|
|
|
{ |
|
121
|
|
|
Session::clear("countryfortestingonly"); |
|
122
|
|
|
Session::clear("MyCloudFlareCountry"); |
|
123
|
|
|
Session::clear("ipfortestingonly"); |
|
124
|
|
|
Session::save(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function currencypercountry($request) |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
$currencies = CountryPrice_EcommerceCurrency::get_currency_per_country(); |
|
130
|
|
|
$usedCurrencies = CountryPrice_EcommerceCurrency::get_currency_per_country_used_ones(); |
|
131
|
|
|
$useArray = array(); |
|
132
|
|
|
$nonUseArray = array(); |
|
133
|
|
|
foreach ($currencies as $country => $currency) { |
|
134
|
|
|
$countryName = EcommerceCountry::find_title($country); |
|
135
|
|
|
$currencyObject = EcommerceCurrency::create_new($currency); |
|
136
|
|
|
if (isset($usedCurrencies[$country])) { |
|
137
|
|
|
$useArray[] = "$country: $currency ($countryName, ".$currencyObject->getTitle().")"; |
|
138
|
|
|
} else { |
|
139
|
|
|
$nonUseArray[] = "$country: $currency ($countryName, ".$currencyObject->getTitle().")"; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
echo "<h2>Countries ready for sale with their currency:</h2>"; |
|
143
|
|
|
foreach ($useArray as $line) { |
|
144
|
|
|
DB::alteration_message($line); |
|
145
|
|
|
} |
|
146
|
|
|
echo "<h2>Countries NOT ready for sale with their currency:</h2>"; |
|
147
|
|
|
foreach ($nonUseArray as $line) { |
|
148
|
|
|
DB::alteration_message($line); |
|
149
|
|
|
} |
|
150
|
|
|
return $this->index(); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function countrieswithoutdistributor($request) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
$list = EcommerceCountry::get()->filter(array("DistributorID" => 0)); |
|
156
|
|
|
if (!$list->count()) { |
|
157
|
|
|
DB::alteration_message('All countries have distributors', 'created'); |
|
158
|
|
|
} else { |
|
159
|
|
|
foreach ($list as $country) { |
|
160
|
|
|
DB::alteration_message("<a href=\"".$country->CMSEditLink()."\">".$country->Code." ".$country->Name."</a>"); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
return $this->index(); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function stockistcountrieswithoutcountry($request) |
|
|
|
|
|
|
167
|
|
|
{ |
|
168
|
|
|
$mainPage = StockistSearchPage::get()->first(); |
|
169
|
|
|
$list = StockistCountryPage::get()->where("Country = '' OR Country IS NULL")->exclude(array("ParentID" => $mainPage->ID)); |
|
170
|
|
|
foreach ($list as $stockistCountry) { |
|
171
|
|
|
DB::alteration_message("<a href=\"".$stockistCountry->CMSEditLink()."\">".$stockistCountry->Title."</a>"); |
|
172
|
|
|
} |
|
173
|
|
|
return $this->index(); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
public function whoami() |
|
178
|
|
|
{ |
|
179
|
|
|
$descriptionArray = array( |
|
180
|
|
|
"MyCountryCode" => "This is the key function", |
|
181
|
|
|
"MyCountryTitle" => "", |
|
182
|
|
|
"MyCurrency" => "Based on the currency set in the order.", |
|
183
|
|
|
"MyDistributor" => "You have to set the ". _t('Distributor.SINGULAR_NAME', 'Distributor') . "'s countries in order to work out someone's ". _t('Distributor.SINGULAR_NAME', 'Distributor') . ".", |
|
184
|
|
|
"MyDistributorCountry" => "This is the country that is being used for the sale. For dodgy countries, we use the backup country.", |
|
185
|
|
|
"MyDeliveryCostNote" => "Set in country, ". _t('Distributor.SINGULAR_NAME', 'Distributor') . " and default country.", |
|
186
|
|
|
"MyShippingDeliveryInfo" => "Set in country, ". _t('Distributor.SINGULAR_NAME', 'Distributor') . " and default country.", |
|
187
|
|
|
"MyShippingReturnInfo" => "Set in country, ". _t('Distributor.SINGULAR_NAME', 'Distributor') . " and default country.", |
|
188
|
|
|
"MyProductNotAvailableNote" => "Set in country, ". _t('Distributor.SINGULAR_NAME', 'Distributor') . ", default country, AND the Ecommerce Config.", |
|
189
|
|
|
"MyStockistSearchPage" => "", |
|
190
|
|
|
"MyStockistCountryPage" => "The stockist page that is related to the visitor's country", |
|
191
|
|
|
"MyCountryFAQPage" => "", |
|
192
|
|
|
"MyBackupCountryCode" => "This country is used if the information for the selected country is not available.", |
|
193
|
|
|
"MyDefaultDistributor" => "You can set one default ". _t('Distributor.SINGULAR_NAME', 'Distributor') . " (head office) with a tickbox for any ". _t('Distributor.SINGULAR_NAME', 'Distributor') , |
|
194
|
|
|
|
|
195
|
|
|
); |
|
196
|
|
|
$array = array( |
|
197
|
|
|
"MyCountryCode" => "String", |
|
198
|
|
|
"MyCountryTitle" => "String", |
|
199
|
|
|
"MyCurrency" => "Object", |
|
200
|
|
|
"MyDistributor" => "Object", |
|
201
|
|
|
"MyDistributorCountry" => "Object", |
|
202
|
|
|
"MyDeliveryCostNote" => "String", |
|
203
|
|
|
"MyShippingDeliveryInfo" => "String", |
|
204
|
|
|
"MyShippingReturnInfo" => "String", |
|
205
|
|
|
"MyProductNotAvailableNote" => "String", |
|
206
|
|
|
"MyStockistSearchPage" => "Object", |
|
207
|
|
|
"MyStockistCountryPage" => "Object", |
|
208
|
|
|
"MyCountryFAQPage" => "Object", |
|
209
|
|
|
"MyBackupCountryCode" => "String", |
|
210
|
|
|
"MyDefaultDistributor" => "Object", |
|
211
|
|
|
); |
|
212
|
|
|
echo "<h1>Current Settings</h1>"; |
|
213
|
|
|
echo "<p>Most of these settings can be adjusted in the country, ". _t('Distributor.SINGULAR_NAME', 'Distributor') . " and generic e-commerce settings.</p>"; |
|
214
|
|
|
foreach ($array as $name => $type) { |
|
215
|
|
|
$style = "created"; |
|
216
|
|
|
$notSet = false; |
|
|
|
|
|
|
217
|
|
|
$string = ""; |
|
|
|
|
|
|
218
|
|
|
if ($type == "String") { |
|
219
|
|
|
$string = $this->$name(); |
|
220
|
|
|
if (is_object($string)) { |
|
221
|
|
|
$string = $string->raw(); |
|
222
|
|
|
} |
|
223
|
|
|
} else { |
|
224
|
|
|
$obj = $this->$name(); |
|
225
|
|
|
if (!$obj) { |
|
226
|
|
|
$string = "Object Not Found"; |
|
227
|
|
|
$notSet = true; |
|
|
|
|
|
|
228
|
|
|
$style = "deleted"; |
|
229
|
|
|
} else { |
|
230
|
|
|
switch ($name) { |
|
231
|
|
|
case "MyDistributorCountry": |
|
232
|
|
|
case "MyCountryFAQPage": |
|
233
|
|
|
case "MyDefaultDistributor": |
|
234
|
|
|
case "MyDistributor": |
|
235
|
|
|
$string = $obj->Name; |
|
236
|
|
|
break; |
|
237
|
|
|
|
|
238
|
|
|
case "MyStockistSearchPage": |
|
239
|
|
|
case "MyStockistCountryPage": |
|
240
|
|
|
$string = $obj->Title; |
|
241
|
|
|
break; |
|
242
|
|
|
default: |
|
243
|
|
|
$string = print_r($obj, 1); |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
if (! $string) { |
|
248
|
|
|
$string = "NOT SET"; |
|
249
|
|
|
$style = "deleted"; |
|
250
|
|
|
} |
|
251
|
|
|
DB::alteration_message("<i>$name</i>: <u><strong>".$string."</strong></u> ... <br /><sup>".$descriptionArray[$name]."</sup><hr />", $style); |
|
252
|
|
|
} |
|
253
|
|
|
echo "<h1>Change Settings</h1>"; |
|
254
|
|
|
$links = array( |
|
255
|
|
|
"resetmycountry/" => "Go back to the standard country", |
|
256
|
|
|
); |
|
257
|
|
|
$links["/dev/tasks/TEST_GEOIP_COUNTRY_CODE_BY_NAME"] = "test GEOIP function"; |
|
258
|
|
|
foreach ($links as $link => $desc) { |
|
259
|
|
|
DB::alteration_message("<a href=\"".$this->Link($link)."\">".$desc."</a>"); |
|
260
|
|
|
} |
|
261
|
|
|
return $this->index(); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* |
|
267
|
|
|
* @return String |
|
268
|
|
|
*/ |
|
269
|
|
|
public function MyCurrency() |
|
270
|
|
|
{ |
|
271
|
|
|
return ShoppingCart::current_order()->CurrencyUsed()->Name; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* |
|
276
|
|
|
* @return String |
|
277
|
|
|
*/ |
|
278
|
|
|
public function MyCountryCode() |
|
279
|
|
|
{ |
|
280
|
|
|
return EcommerceCountry::get_country(); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* |
|
285
|
|
|
* @return String |
|
286
|
|
|
*/ |
|
287
|
|
|
public function MyBackupCountryCode() |
|
288
|
|
|
{ |
|
289
|
|
|
return CountryPrice_EcommerceCountry::get_backup_country()->Code; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @return String |
|
294
|
|
|
*/ |
|
295
|
|
|
public function MyCountryTitle() |
|
296
|
|
|
{ |
|
297
|
|
|
$code = EcommerceCountry::get_country(); |
|
298
|
|
|
return EcommerceCountry::find_title($code); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
public function MyDefaultDistributor() |
|
302
|
|
|
{ |
|
303
|
|
|
return Distributor::get_default_distributor(); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* returns note about Delivery Cost |
|
310
|
|
|
* Needs to be in model so we can access from the order in the template. |
|
311
|
|
|
* @return Varchar Field |
|
312
|
|
|
*/ |
|
313
|
|
View Code Duplication |
public function MyDeliveryCostNote() |
|
|
|
|
|
|
314
|
|
|
{ |
|
315
|
|
|
$note = EcommerceCountry::get_country_object()->DeliveryCostNote; |
|
316
|
|
|
if (!$note) { |
|
317
|
|
|
if ($distributor = $this->MyDistributor()) { |
|
318
|
|
|
$note = $distributor->DeliveryCostNote; |
|
|
|
|
|
|
319
|
|
|
} |
|
320
|
|
|
if (!$note) { |
|
321
|
|
|
$note = CountryPrice_EcommerceCountry::get_backup_country()->DeliveryCostNote; |
|
322
|
|
|
} |
|
323
|
|
|
} |
|
324
|
|
|
return DBField::create_field("Varchar", $note); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* returns note about Shipping Estimation Time |
|
329
|
|
|
* Needs to be in model so we can access from the order in the template. |
|
330
|
|
|
* @return Varchar Field |
|
331
|
|
|
*/ |
|
332
|
|
View Code Duplication |
public function MyShippingDeliveryInfo() |
|
|
|
|
|
|
333
|
|
|
{ |
|
334
|
|
|
$info = EcommerceCountry::get_country_object()->ShippingEstimation; |
|
335
|
|
|
if (!$info) { |
|
336
|
|
|
if ($distributor = $this->MyDistributor()) { |
|
337
|
|
|
$info = $distributor->ShippingEstimation; |
|
|
|
|
|
|
338
|
|
|
} |
|
339
|
|
|
if (!$info) { |
|
340
|
|
|
$info = CountryPrice_EcommerceCountry::get_backup_country()->ShippingEstimation; |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
return DBField::create_field("Varchar", $info); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* returns the Distributor for the user |
|
348
|
|
|
* Needs to be in model so we can access from the order in the template. |
|
349
|
|
|
* @return Varchar Field |
|
|
|
|
|
|
350
|
|
|
*/ |
|
351
|
|
|
public function MyDistributor() |
|
352
|
|
|
{ |
|
353
|
|
|
$code = EcommerceCountry::get_country(); |
|
354
|
|
|
$distributor = Distributor::get_one_for_country($code); |
|
355
|
|
|
return $distributor; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* returns note about shipping return information |
|
360
|
|
|
* Needs to be in model so we can access from the order in the template. |
|
361
|
|
|
* @return Varchar Field |
|
362
|
|
|
*/ |
|
363
|
|
View Code Duplication |
public function MyShippingReturnInfo() |
|
|
|
|
|
|
364
|
|
|
{ |
|
365
|
|
|
$info = EcommerceCountry::get_country_object()->ReturnInformation; |
|
366
|
|
|
if (!$info) { |
|
367
|
|
|
if ($distributor = $this->MyDistributor()) { |
|
368
|
|
|
$info = $distributor->ReturnInformation; |
|
|
|
|
|
|
369
|
|
|
} |
|
370
|
|
|
if (!$info) { |
|
371
|
|
|
$info = CountryPrice_EcommerceCountry::get_backup_country()->ReturnInformation; |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
return DBField::create_field("Varchar", $info); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* returns note to show when product / variation is not available in the specific country |
|
380
|
|
|
* Needs to be in model so we can access from the order in the template. |
|
381
|
|
|
* @return Varchar Field |
|
382
|
|
|
*/ |
|
383
|
|
|
public function MyProductNotAvailableNote() |
|
384
|
|
|
{ |
|
385
|
|
|
$note = EcommerceCountry::get_country_object()->ProductNotAvailableNote; |
|
386
|
|
|
if (!$note) { |
|
387
|
|
|
if ($distributor = $this->MyDistributor()) { |
|
388
|
|
|
$note = $distributor->ProductNotAvailableNote; |
|
|
|
|
|
|
389
|
|
|
} |
|
390
|
|
|
if (!$note) { |
|
391
|
|
|
$note = CountryPrice_EcommerceCountry::get_backup_country()->ProductNotAvailableNote; |
|
392
|
|
|
} |
|
393
|
|
|
if (!$note) { |
|
394
|
|
|
$note = $this->EcomConfig()->NotForSaleMessage; |
|
|
|
|
|
|
395
|
|
|
} |
|
396
|
|
|
} |
|
397
|
|
|
return DBField::create_field("HTMLText", $note); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* provides information on where to buy a product |
|
403
|
|
|
* if it can not be bought online... |
|
404
|
|
|
* @return StockistCountryPage | Null |
|
405
|
|
|
*/ |
|
406
|
|
|
public function MyStockistCountryPage($attempts = 0) |
|
407
|
|
|
{ |
|
408
|
|
|
$exit = false; |
|
409
|
|
|
switch ($attempts) { |
|
410
|
|
|
case 0: |
|
411
|
|
|
$countryCode = EcommerceCountry::get_country(); |
|
412
|
|
|
break; |
|
413
|
|
|
case 1: |
|
414
|
|
|
$countryCode = CountryPrice_EcommerceCountry::get_distributor_country(); |
|
415
|
|
|
break; |
|
416
|
|
|
case 2: |
|
417
|
|
|
$countryCode = EcommerceConfig::get('EcommerceCountry', 'default_country_code'); |
|
418
|
|
|
break; |
|
419
|
|
|
break; |
|
|
|
|
|
|
420
|
|
|
default: |
|
421
|
|
|
$countryCode = "NZ"; |
|
422
|
|
|
$exit = true; |
|
423
|
|
|
} |
|
424
|
|
|
if ($countryCode) { |
|
425
|
|
|
$countryStockistPage = StockistCountryPage::get()->filter(array("Country" => $countryCode))->first(); |
|
426
|
|
|
if (!$countryStockistPage) { |
|
427
|
|
|
if ($countryObject = DataObject::get_one("EcommerceCountry", "Code = '$countryCode'")) { |
|
428
|
|
|
$rows = DB::query( |
|
429
|
|
|
" |
|
430
|
|
|
SELECT \"StockistCountryPageID\" |
|
431
|
|
|
FROM \"StockistCountryPage_AdditionalCountries\" |
|
432
|
|
|
WHERE \"EcommerceCountryID\" = ".$countryObject->ID |
|
433
|
|
|
); |
|
434
|
|
|
if ($rows) { |
|
435
|
|
|
foreach ($rows as $row) { |
|
436
|
|
|
$countryStockistPage = StockistCountryPage::get()->byID($rows["StockistCountryPageID"]); |
|
437
|
|
|
if ($countryStockistPage) { |
|
438
|
|
|
break; |
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
} |
|
442
|
|
|
} |
|
443
|
|
|
} |
|
444
|
|
|
if ($countryStockistPage || $exit) { |
|
445
|
|
|
return $countryStockistPage; |
|
446
|
|
|
} |
|
447
|
|
|
} |
|
448
|
|
|
$attempts++; |
|
449
|
|
|
return $this->MyStockistCountryPage($attempts); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* |
|
454
|
|
|
* @return EcommerceCountry |
|
455
|
|
|
*/ |
|
456
|
|
|
public function MyDistributorCountry() |
|
457
|
|
|
{ |
|
458
|
|
|
return CountryPrice_EcommerceCountry::get_distributor_country(); |
|
459
|
|
|
return $countryObject; |
|
|
|
|
|
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* |
|
464
|
|
|
* @return StockistSearchPage |
|
465
|
|
|
*/ |
|
466
|
|
|
public function StockistSearchPage() |
|
467
|
|
|
{ |
|
468
|
|
|
return StockistSearchPage::get()->filter(array("ClassName" => "StockistSearchPage"))->first(); |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
|
|
472
|
|
|
public function MyStockistSearchPage() |
|
|
|
|
|
|
473
|
|
|
{ |
|
474
|
|
|
$country = EcommerceCountry::get_country(); |
|
475
|
|
|
$countryPage = StockistCountryPage::get()->filter(array("Country" => $country))->First(); |
|
476
|
|
|
$sql = " |
|
477
|
|
|
SELECT StockistCountryPageID |
|
478
|
|
|
FROM StockistCountryPage_AdditionalCountries |
|
479
|
|
|
WHERE EcommerceCountryID = '".EcommerceCountry::get_country_id($country)."'"; |
|
480
|
|
|
$idForPage = DB::query($sql)->value(); |
|
481
|
|
|
if ($idForPage) { |
|
482
|
|
|
StockistCountryPage::get()->byID($idForPage); |
|
483
|
|
|
} |
|
484
|
|
|
if (!$countryPage) { |
|
485
|
|
|
if (!$countryPage) { |
|
486
|
|
|
$countryPage = $this->StockistSearchPage(); |
|
487
|
|
|
} |
|
488
|
|
|
} |
|
489
|
|
|
return $countryPage; |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* |
|
494
|
|
|
* returns the DistributorFAQPage ONLY if Specific Content has been entered |
|
495
|
|
|
* for the country. |
|
496
|
|
|
* @return DistributorFAQPage |
|
497
|
|
|
*/ |
|
498
|
|
|
public function MyCountryFAQPage() |
|
499
|
|
|
{ |
|
500
|
|
|
$country = $this->MyDistributorCountry(); |
|
501
|
|
|
if ($country && $country->FAQContent) { |
|
502
|
|
|
return DistributorFAQPage::get()->First(); |
|
503
|
|
|
} |
|
504
|
|
|
} |
|
505
|
|
|
} |
|
506
|
|
|
|