|
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 DiscountCouponCountriesModifierExtension extends DataExtension |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* returns TRUE if the country |
|
14
|
|
|
* is not in the included list or if it is in the excluded list |
|
15
|
|
|
* in all other cases it returns null to basically ignore the country specific |
|
16
|
|
|
* rules |
|
17
|
|
|
* |
|
18
|
|
|
* @param DiscountCouponOption $coupon |
|
19
|
|
|
* |
|
20
|
|
|
* @return bool | null |
|
|
|
|
|
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
public function checkForExclusions($coupon) |
|
24
|
|
|
{ |
|
25
|
|
|
$countryCode = CountryPrice_EcommerceCountry::get_real_country(); |
|
26
|
|
|
if ($countryCode) { |
|
27
|
|
|
$countryCode = $countryCode->Code; |
|
28
|
|
|
$includedCountries = $coupon->IncludedCountries(); |
|
29
|
|
|
$excludedCountries = $coupon->ExcludedCountries(); |
|
30
|
|
|
|
|
31
|
|
|
//first situation: no country information => ALLOW => return NULL to ignore this. |
|
32
|
|
|
if ($includedCountries->count() == 0 && $excludedCountries->count() == 0) { |
|
33
|
|
|
$this->owner->DebugString .= '--- no country rules apply ---'; |
|
34
|
|
|
return null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
//second situation: includes and excludes |
|
38
|
|
|
if ($includedCountries->count() > 0 && $excludedCountries->count() > 0) { |
|
39
|
|
|
$this->owner->DebugString .= '--- inclusions and exclusions apply - checking for '.$countryCode.' ---'; |
|
40
|
|
|
$returnFlag = true; |
|
41
|
|
|
|
|
42
|
|
|
$includeArray = $includedCountries->column('Code'); |
|
43
|
|
|
if (in_array($countryCode, $includeArray)) { |
|
44
|
|
|
$returnFlag = null; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$excludeArray = $excludedCountries->column('Code'); |
|
48
|
|
|
if (in_array($countryCode, $excludeArray)) { |
|
49
|
|
|
$returnFlag = true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $returnFlag; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
//third situation: is it included? |
|
56
|
|
View Code Duplication |
if ($includedCountries->count() > 0) { |
|
|
|
|
|
|
57
|
|
|
$this->owner->DebugString .= '--- inclusions apply - checking for '.$countryCode.' ---'; |
|
58
|
|
|
$includeArray = $includedCountries->column('Code'); |
|
59
|
|
|
if (in_array($countryCode, $includeArray)) { |
|
60
|
|
|
return null; |
|
61
|
|
|
} else { |
|
62
|
|
|
return true; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
//fourth situation: is it excluded? |
|
67
|
|
View Code Duplication |
if ($excludedCountries->count() > 0) { |
|
|
|
|
|
|
68
|
|
|
$this->owner->DebugString .= '--- exclusions apply - checking for '.$countryCode.' ---'; |
|
69
|
|
|
$excludeArray = $excludedCountries->column('Code'); |
|
70
|
|
|
if (in_array($countryCode, $excludeArray)) { |
|
71
|
|
|
return true; |
|
72
|
|
|
} else { |
|
|
|
|
|
|
73
|
|
|
//return true; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} else { |
|
77
|
|
|
$this->owner->DebugString .= '--- no country code could be found ---'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return null; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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.