|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class DiscountCouponOptionCountriesExtension extends DataExtension |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
private static $casting = array( |
|
|
|
|
|
|
12
|
|
|
"CountryDescription" => "Varchar" |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
16
|
|
|
"CountryDescription" => "CountryDescription" |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
21
|
|
|
"CountryDescription" => "Where" |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
26
|
|
|
"IncludedCountries" => "EcommerceCountry", |
|
27
|
|
|
"ExcludedCountries" => "EcommerceCountry" |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
// private static $belongs_many_many = array( |
|
|
|
|
|
|
31
|
|
|
// |
|
32
|
|
|
// ); |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function getCountryDescription() |
|
37
|
|
|
{ |
|
38
|
|
|
$returnString = ''; |
|
|
|
|
|
|
39
|
|
|
$includedCountries = $this->owner->IncludedCountries(); |
|
40
|
|
|
$excludedCountries = $this->owner->ExcludedCountries(); |
|
41
|
|
|
//first situation: no country information => ALLOW => return NULL to ignore this. |
|
42
|
|
|
if ($includedCountries->count() == 0 && $excludedCountries->count() == 0) { |
|
43
|
|
|
return _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN_ALL_COUNTRIES', 'Available in all countries'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
//second situation: includes and excludes |
|
47
|
|
|
if ($includedCountries->count() > 0 && $excludedCountries->count() > 0) { |
|
48
|
|
|
$includeArray = $includedCountries->column('Code'); |
|
49
|
|
|
$excludeArray = $excludedCountries->column('Code'); |
|
50
|
|
|
foreach ($includeArray as $key => $countryCode) { |
|
51
|
|
|
if (in_array($countryCode, $excludeArray)) { |
|
52
|
|
|
unset($includeArray[$key]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
return _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN', 'Available in: ').implode(', ', $includeArray). |
|
56
|
|
|
_t('DiscountCouponOptionCountriesExtension.SPECIFICALLY_EXCLUDED', ' || Specifically excluded: ').implode(', ', $excludeArray); |
|
57
|
|
|
//... |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
//third situation: is it included? |
|
61
|
|
|
if ($includedCountries->count() > 0) { |
|
62
|
|
|
$includeArray = $includedCountries->column('Code'); |
|
63
|
|
|
return _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN', 'Available in: ').implode(', ', $includeArray); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
//fourth situation: is it excluded? |
|
67
|
|
|
if ($excludedCountries->count() > 0) { |
|
68
|
|
|
$excludeArray = $excludedCountries->column('Code'); |
|
69
|
|
|
return _t('DiscountCouponOptionCountriesExtension.NOT_AVAILABLE_IN', 'Not available in: ').implode(', ', $excludeArray); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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.