@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | class EcommerceCountriesTest extends SapphireTest { |
3 | 3 | |
4 | - protected $usesDatabase = false; |
|
4 | + protected $usesDatabase = false; |
|
5 | 5 | |
6 | - protected $requiredExtensions = array(); |
|
6 | + protected $requiredExtensions = array(); |
|
7 | 7 | |
8 | - public function testMyMethod() { |
|
9 | - $this->assertEquals(1, 1); |
|
10 | - } |
|
8 | + public function testMyMethod() { |
|
9 | + $this->assertEquals(1, 1); |
|
10 | + } |
|
11 | 11 | |
12 | 12 | } |
13 | 13 |
@@ -157,7 +157,7 @@ |
||
157 | 157 | |
158 | 158 | /** |
159 | 159 | * |
160 | - * @return DataList |
|
160 | + * @return string |
|
161 | 161 | */ |
162 | 162 | public function AlternativeHrefLangLinksCachingKey() |
163 | 163 | { |
@@ -99,8 +99,7 @@ |
||
99 | 99 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($oldURL); |
100 | 100 | if($hasCountrySegment){ |
101 | 101 | $newURL = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($countryCode, $oldURL); |
102 | - } |
|
103 | - else { |
|
102 | + } else { |
|
104 | 103 | $newURL = CountryPrice_Translation::get_country_url_provider()->addCountryCodeToUrl($countryCode, $oldURL); |
105 | 104 | } |
106 | 105 |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $oldURL = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
98 | 98 | |
99 | 99 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($oldURL); |
100 | - if($hasCountrySegment){ |
|
100 | + if ($hasCountrySegment) { |
|
101 | 101 | $newURL = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($countryCode, $oldURL); |
102 | 102 | } |
103 | 103 | else { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function UpdateCanonicalLink(&$link) |
163 | 163 | { |
164 | 164 | $obj = $this->owner->dataRecord->CanonicalObject(); |
165 | - if($obj) { |
|
165 | + if ($obj) { |
|
166 | 166 | $link = $obj->Link(); |
167 | 167 | } else { |
168 | 168 | $link = $this->owner->dataRecord->AbsoluteLink(); |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | $currencyCode = isset($currencyPerCountry[$countryCode]) ? $currencyPerCountry[$countryCode] : EcommerceCurrency::default_currency_code(); |
45 | 45 | $currencyDO = EcommerceCurrency::get_one_from_code($currencyCode); |
46 | 46 | } |
47 | - if (! $currencyDO) { |
|
47 | + if (!$currencyDO) { |
|
48 | 48 | $currencyDO = EcommerceCurrency::create_new($currencyCode); |
49 | 49 | } |
50 | - if (! $currencyDO) { |
|
50 | + if (!$currencyDO) { |
|
51 | 51 | $currencyDO = EcommerceCurrency::get_default(); |
52 | 52 | } |
53 | 53 | return $currencyDO; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $cachekey = "EcommerceCurrencyCountryMatrix"; |
69 | 69 | $cache = SS_Cache::factory('CountryPrice_EcommerceCurrency'); |
70 | - if (! ($serializedArray = $cache->load($cachekey))) { |
|
70 | + if (!($serializedArray = $cache->load($cachekey))) { |
|
71 | 71 | $countries = CountryPrice_EcommerceCountry::get_real_countries_list(); |
72 | 72 | $unserializedArray = array(); |
73 | 73 | $defaultCurrencyCode = EcommerceCurrency::default_currency_code(); |
@@ -123,6 +123,7 @@ |
||
123 | 123 | /** |
124 | 124 | * @var int $countryID |
125 | 125 | * |
126 | + * @param integer $countryID |
|
126 | 127 | * @return CountryPrice_Translation | null |
127 | 128 | */ |
128 | 129 | public function getEcommerceTranslation($countryID) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function loadTranslatedValues($countryID = 0, $variableOrMethod = '') |
57 | 57 | { |
58 | 58 | $translation = null; |
59 | - if (! $countryID) { |
|
59 | + if (!$countryID) { |
|
60 | 60 | $countryObject = CountryPrice_EcommerceCountry::get_real_country(); |
61 | 61 | if ($countryObject) { |
62 | 62 | $countryID = $countryObject->ID; |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | $fieldsToReplace = $translation->FieldsToReplace(); |
76 | 76 | foreach ($fieldsToReplace as $replaceFields) { |
77 | 77 | $pageField = $replaceFields->PageField; |
78 | - $pageFieldTranslated = $pageField . 'Translated'; |
|
78 | + $pageFieldTranslated = $pageField.'Translated'; |
|
79 | 79 | $translationField = $replaceFields->TranslationField; |
80 | - if (! $variableOrMethod || $variableOrMethod === $pageField) { |
|
80 | + if (!$variableOrMethod || $variableOrMethod === $pageField) { |
|
81 | 81 | if ($translation->hasMethod($translationField)) { |
82 | 82 | $this->owner->$pageField = $translation->$translationField(); |
83 | 83 | $this->owner->$pageFieldTranslated = $translation->$translationField(); |
@@ -3,14 +3,17 @@ |
||
3 | 3 | interface CountryURLProviderInterface |
4 | 4 | { |
5 | 5 | /** |
6 | + * @return boolean |
|
6 | 7 | */ |
7 | 8 | public function hasCountrySegment($url = ''); |
8 | 9 | |
9 | 10 | /** |
11 | + * @return string |
|
10 | 12 | */ |
11 | 13 | public function replaceCountryCodeInUrl($countryCode, $url = ''); |
12 | 14 | |
13 | 15 | /** |
16 | + * @return string |
|
14 | 17 | */ |
15 | 18 | public function addCountryCodeToUrl($countryCode, $url = ''); |
16 | 19 |
@@ -225,8 +225,7 @@ |
||
225 | 225 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($link); |
226 | 226 | if($hasCountrySegment){ |
227 | 227 | $link = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($this->EcommerceCountry()->Code, $link); |
228 | - } |
|
229 | - else { |
|
228 | + } else { |
|
230 | 229 | $link = CountryPrice_Translation::get_country_url_provider()->addCountryCodeToUrl($this->EcommerceCountry()->Code, $link); |
231 | 230 | } |
232 | 231 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | $countryDropdownField = DropdownField::create( |
100 | 100 | 'EcommerceCountryID', |
101 | 101 | $fields->dataFieldByName('EcommerceCountryID')->Title(), |
102 | - array('' => '-- make sure to select a country --')+$countries |
|
102 | + array('' => '-- make sure to select a country --') + $countries |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | // //$fields->removeFieldFromTab("Root.Main", 'ParentID'); |
106 | - if($this->WithoutTranslation) { |
|
106 | + if ($this->WithoutTranslation) { |
|
107 | 107 | return FieldList::create( |
108 | 108 | array( |
109 | 109 | $countryDropdownField, |
@@ -123,19 +123,19 @@ discard block |
||
123 | 123 | ); |
124 | 124 | } |
125 | 125 | $dbFields = $this->inheritedDatabaseFields(); |
126 | - foreach($dbFields as $dbField => $fieldType) { |
|
126 | + foreach ($dbFields as $dbField => $fieldType) { |
|
127 | 127 | $useField = 'UseOriginal'.$dbField; |
128 | - if(!empty($this->$useField)) { |
|
128 | + if (!empty($this->$useField)) { |
|
129 | 129 | $fields->replaceField( |
130 | 130 | $dbField, |
131 | 131 | $fields->dataFieldByName($dbField)->performReadonlyTransformation() |
132 | 132 | ); |
133 | 133 | } |
134 | - if($fields->dataFieldByName($useField)){ |
|
135 | - $fields->dataFieldByName($useField)->setDescription(_t('CountryPrice_Translation.IGNORE', 'Use untranslated value for ') . $dbField); |
|
134 | + if ($fields->dataFieldByName($useField)) { |
|
135 | + $fields->dataFieldByName($useField)->setDescription(_t('CountryPrice_Translation.IGNORE', 'Use untranslated value for ').$dbField); |
|
136 | 136 | } |
137 | 137 | } |
138 | - if($this->exists() && $this->ParentID) { |
|
138 | + if ($this->exists() && $this->ParentID) { |
|
139 | 139 | $fields->addFieldToTab( |
140 | 140 | 'Root.ParentPage', |
141 | 141 | CMSEditLinkField::create( |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | ) |
211 | 211 | ); |
212 | 212 | $this->extend('updateFieldsToReplace', $al); |
213 | - foreach($al as $fieldToReplace) { |
|
214 | - $ignoreField = 'UseOriginal' . $fieldToReplace->PageField; |
|
215 | - if(!empty($this->owner->$ignoreField)) { |
|
213 | + foreach ($al as $fieldToReplace) { |
|
214 | + $ignoreField = 'UseOriginal'.$fieldToReplace->PageField; |
|
215 | + if (!empty($this->owner->$ignoreField)) { |
|
216 | 216 | $al->remove($fieldToReplace); |
217 | 217 | } |
218 | 218 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $link = $this->Parent()->Link(); |
236 | 236 | if ($this->EcommerceCountryID) { |
237 | 237 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($link); |
238 | - if($hasCountrySegment){ |
|
238 | + if ($hasCountrySegment) { |
|
239 | 239 | $link = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($this->EcommerceCountry()->Code, $link); |
240 | 240 | } |
241 | 241 | else { |
@@ -250,20 +250,20 @@ discard block |
||
250 | 250 | parent::requireDefaultRecords(); |
251 | 251 | //get rid of rogue entries: |
252 | 252 | DB::query('DELETE FROM CountryPrice_Translation WHERE EcommerceCountryID = 0 OR ParentID = 0'); |
253 | - if(Config::inst()->get('CountryPrice_Translation', 'automatically_create_dummy_translations_for_products_and_productgroups')) { |
|
253 | + if (Config::inst()->get('CountryPrice_Translation', 'automatically_create_dummy_translations_for_products_and_productgroups')) { |
|
254 | 254 | $prices = CountryPrice::get(); |
255 | 255 | $ecommerceCountries = array(); |
256 | - foreach($prices as $price) { |
|
257 | - if($countryObject = $price->CountryObject()) { |
|
258 | - if($buyable = $price->Buyable()) { |
|
259 | - if($buyable instanceof Product) { |
|
260 | - if($buyable->ID && $countryObject->ID) { |
|
256 | + foreach ($prices as $price) { |
|
257 | + if ($countryObject = $price->CountryObject()) { |
|
258 | + if ($buyable = $price->Buyable()) { |
|
259 | + if ($buyable instanceof Product) { |
|
260 | + if ($buyable->ID && $countryObject->ID) { |
|
261 | 261 | $filter = array( |
262 | 262 | 'EcommerceCountryID' => $countryObject->ID, |
263 | 263 | 'ParentID' => $buyable->ID |
264 | 264 | ); |
265 | 265 | $ecommerceCountries[$countryObject->ID] = $countryObject; |
266 | - if(! CountryPrice_Translation::get()->filter($filter)->first()) { |
|
266 | + if (!CountryPrice_Translation::get()->filter($filter)->first()) { |
|
267 | 267 | DB::alteration_message( |
268 | 268 | 'Creating fake translation for '.$buyable->Title.' for country '.$countryObject->Code, |
269 | 269 | 'created' |
@@ -277,14 +277,14 @@ discard block |
||
277 | 277 | } |
278 | 278 | } |
279 | 279 | } |
280 | - if(count($ecommerceCountries)) { |
|
281 | - foreach(ProductGroup::get() as $productGroup) { |
|
282 | - foreach($ecommerceCountries as $countryID => $countryObject) { |
|
280 | + if (count($ecommerceCountries)) { |
|
281 | + foreach (ProductGroup::get() as $productGroup) { |
|
282 | + foreach ($ecommerceCountries as $countryID => $countryObject) { |
|
283 | 283 | $filter = array( |
284 | 284 | 'EcommerceCountryID' => $countryObject->ID, |
285 | 285 | 'ParentID' => $productGroup->ID |
286 | 286 | ); |
287 | - if(! CountryPrice_Translation::get()->filter($filter)->first()) { |
|
287 | + if (!CountryPrice_Translation::get()->filter($filter)->first()) { |
|
288 | 288 | DB::alteration_message( |
289 | 289 | 'Creating fake translation for '.$productGroup->Title.' for country '.$countryObject->Code, |
290 | 290 | 'created' |
@@ -114,10 +114,10 @@ |
||
114 | 114 | |
115 | 115 | $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; |
116 | 116 | |
117 | - $query = !empty($query) ? '?'. http_build_query($query) : ''; |
|
117 | + $query = !empty($query) ? '?'.http_build_query($query) : ''; |
|
118 | 118 | |
119 | 119 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($url); |
120 | - if($hasCountrySegment){ |
|
120 | + if ($hasCountrySegment) { |
|
121 | 121 | $url = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($newCountryCode, $url); |
122 | 122 | } |
123 | 123 | else { |
@@ -119,8 +119,7 @@ |
||
119 | 119 | $hasCountrySegment = CountryPrice_Translation::get_country_url_provider()->hasCountrySegment($url); |
120 | 120 | if($hasCountrySegment){ |
121 | 121 | $url = CountryPrice_Translation::get_country_url_provider()->replaceCountryCodeInUrl($newCountryCode, $url); |
122 | - } |
|
123 | - else { |
|
122 | + } else { |
|
124 | 123 | $url = CountryPrice_Translation::get_country_url_provider()->addCountryCodeToUrl($newCountryCode, $url); |
125 | 124 | } |
126 | 125 | return $url; |
@@ -10,62 +10,62 @@ |
||
10 | 10 | |
11 | 11 | class CountryURLProvider extends Object implements CountryURLProviderInterface |
12 | 12 | { |
13 | - private static $country_segments = array('nz', 'au', 'gb', 'eu', 'jp', 'us', 'zz'); |
|
13 | + private static $country_segments = array('nz', 'au', 'gb', 'eu', 'jp', 'us', 'zz'); |
|
14 | 14 | |
15 | - public function hasCountrySegment($url = ''){ |
|
15 | + public function hasCountrySegment($url = '') { |
|
16 | 16 | $url = $this->getDefaultURL($url); |
17 | 17 | $parsedUrl = parse_url($url); |
18 | 18 | $pathSegments = explode("/", $parsedUrl['path']); |
19 | 19 | $firstSegment = ''; |
20 | - $countries = Config::inst()->get('CountryURLProvider', 'country_segments'); |
|
21 | - foreach ($pathSegments as $position => $segment){ |
|
22 | - if($segment){ |
|
20 | + $countries = Config::inst()->get('CountryURLProvider', 'country_segments'); |
|
21 | + foreach ($pathSegments as $position => $segment) { |
|
22 | + if ($segment) { |
|
23 | 23 | $firstSegment = $segment; |
24 | 24 | break; |
25 | 25 | } |
26 | 26 | } |
27 | - if(in_array($firstSegment, $countries)){ |
|
27 | + if (in_array($firstSegment, $countries)) { |
|
28 | 28 | return true; |
29 | 29 | } |
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | |
33 | - public function replaceCountryCodeInUrl($countryCode, $url = ''){ |
|
33 | + public function replaceCountryCodeInUrl($countryCode, $url = '') { |
|
34 | 34 | $url = $this->getDefaultURL($url); |
35 | 35 | $parsedUrl = parse_url($url); |
36 | 36 | $pathParts = explode('/', $parsedUrl['path']); |
37 | - $countries = Config::inst()->get('CountryURLProvider', 'country_segments'); |
|
38 | - foreach($pathParts as $pathPartsKey => $pathPart) { |
|
37 | + $countries = Config::inst()->get('CountryURLProvider', 'country_segments'); |
|
38 | + foreach ($pathParts as $pathPartsKey => $pathPart) { |
|
39 | 39 | //check for first match |
40 | - if(in_array($pathPart, $countries)) { |
|
40 | + if (in_array($pathPart, $countries)) { |
|
41 | 41 | $pathParts[$pathPartsKey] = strtolower($countryCode); |
42 | 42 | break; |
43 | 43 | } |
44 | 44 | } |
45 | 45 | $parsedUrl['path'] = implode('/', $pathParts); |
46 | - $url = $parsedUrl['scheme']. '://'. $parsedUrl['host']. $parsedUrl['path']; |
|
47 | - if(isset($parsedUrl['query'])){ |
|
48 | - $url = $url . $parsedUrl['query']; |
|
46 | + $url = $parsedUrl['scheme'].'://'.$parsedUrl['host'].$parsedUrl['path']; |
|
47 | + if (isset($parsedUrl['query'])) { |
|
48 | + $url = $url.$parsedUrl['query']; |
|
49 | 49 | } |
50 | 50 | return $url; |
51 | 51 | } |
52 | 52 | |
53 | - public function addCountryCodeToUrl($countryCode, $url = ''){ |
|
53 | + public function addCountryCodeToUrl($countryCode, $url = '') { |
|
54 | 54 | $url = $this->getDefaultURL($url); |
55 | 55 | $parsedUrl = parse_url($url); |
56 | - $url = $parsedUrl['scheme']. '://'. $parsedUrl['host']. '/'. strtolower($countryCode) . $parsedUrl['path']; |
|
57 | - if(isset($parsedUrl['query'])){ |
|
58 | - $url = $url . $parsedUrl['query']; |
|
56 | + $url = $parsedUrl['scheme'].'://'.$parsedUrl['host'].'/'.strtolower($countryCode).$parsedUrl['path']; |
|
57 | + if (isset($parsedUrl['query'])) { |
|
58 | + $url = $url.$parsedUrl['query']; |
|
59 | 59 | } |
60 | 60 | return $url; |
61 | 61 | } |
62 | 62 | |
63 | 63 | private function getDefaultURL($url = '') |
64 | 64 | { |
65 | - if($url) { |
|
65 | + if ($url) { |
|
66 | 66 | return Director::absoluteURL($url); |
67 | 67 | } |
68 | - return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|
68 | + return (isset($_SERVER['HTTPS']) ? "https" : "http")."://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |