1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class CountryPrice_Translation extends DataObject |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
private static $db = array( |
|
|
|
|
8
|
|
|
'Title' => 'Varchar(200)', |
9
|
|
|
'Content' => 'HTMLText', |
10
|
|
|
'WithoutTranslation' => 'Boolean' |
11
|
|
|
); |
12
|
|
|
|
13
|
|
|
private static $field_labels = array( |
|
|
|
|
14
|
|
|
'Title' => 'Page Title', |
15
|
|
|
'Content' => 'Page Content', |
16
|
|
|
'EcommerceCountryID' => 'Country', |
17
|
|
|
'WithoutTranslation' => 'Without Translation' |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
private static $has_one = array( |
|
|
|
|
21
|
|
|
'EcommerceCountry' => 'EcommerceCountry', |
22
|
|
|
'Parent' => 'SiteTree' |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
private static $summary_fields = array( |
|
|
|
|
26
|
|
|
'EcommerceCountry.Name' => 'Country', |
27
|
|
|
'Title' => 'Title', |
28
|
|
|
'WithoutTranslation.Nice' => 'Price Difference Only' |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
private static $casting = array( |
|
|
|
|
32
|
|
|
'Link' => 'Varchar' |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private static $locale_get_parameter = 'ecomlocale'; |
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Standard SS variable. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private static $singular_name = 'Translation'; |
|
|
|
|
46
|
|
|
public function i18n_singular_name() |
47
|
|
|
{ |
48
|
|
|
return self::$singular_name; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Standard SS variable. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private static $plural_name = 'Translations'; |
|
|
|
|
57
|
|
|
public function i18n_plural_name() |
58
|
|
|
{ |
59
|
|
|
return self::$plural_name; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* CMS Fields |
64
|
|
|
* @return FieldList |
65
|
|
|
*/ |
66
|
|
|
public function getCMSFields() |
67
|
|
|
{ |
68
|
|
|
$fields = parent::getCMSFields(); |
69
|
|
|
$countries = CountryPrice_EcommerceCountry::get_real_countries_list()->map()->toArray(); |
70
|
|
|
$fields->addFieldToTab( |
71
|
|
|
'Root.Main', |
72
|
|
|
DropdownField::create( |
73
|
|
|
'EcommerceCountryID', |
74
|
|
|
$fields->dataFieldByName('EcommerceCountryID')->Title(), |
75
|
|
|
array('' => '-- make sure to select a country --')+$countries |
76
|
|
|
), |
77
|
|
|
'Title' |
78
|
|
|
); |
79
|
|
|
$withoutTranslationField = $fields->dataFieldByName('WithoutTranslation'); |
80
|
|
|
$fields->addFieldToTab( |
81
|
|
|
'Root.Main', |
82
|
|
|
CheckboxField::create( |
83
|
|
|
'WithoutTranslation', |
84
|
|
|
$withoutTranslationField->Title() |
85
|
|
|
)->setRightTitle('The page is <em>translated</em> for search engines because it has prices for this country. '), |
86
|
|
|
'Title' |
87
|
|
|
); |
88
|
|
|
$fields->removeFieldFromTab("Root.Main", 'ParentID'); |
89
|
|
|
return $fields; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function canCreate($member = null) |
93
|
|
|
{ |
94
|
|
|
if (CountryPrice_EcommerceCountry::get_real_countries_list()->count()) { |
95
|
|
|
return parent::canCreate($member); |
96
|
|
|
} |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
protected function validate() |
104
|
|
|
{ |
105
|
|
|
$validation = parent::validate(); |
106
|
|
|
if ($validation->valid()) { |
107
|
|
|
if ($this->exists()) { |
108
|
|
|
$existing = CountryPrice_Translation::get() |
109
|
|
|
->exclude(array("ID" => $this->ID)) |
110
|
|
|
->filter( |
111
|
|
|
array( |
112
|
|
|
"EcommerceCountryID" => $this->EcommerceCountryID, |
|
|
|
|
113
|
|
|
"ParentID" => $this->ParentID |
|
|
|
|
114
|
|
|
) |
115
|
|
|
); |
116
|
|
|
if ($existing->count() > 0) { |
117
|
|
|
$validation->error( |
118
|
|
|
'There is already an entry for this country and page' |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
return $validation; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* 'PageField' => 'Title' |
128
|
|
|
* 'TranslationField' => 'Title' |
129
|
|
|
* |
130
|
|
|
* @return ArrayList |
131
|
|
|
*/ |
132
|
|
|
public function FieldsToReplace() |
133
|
|
|
{ |
134
|
|
|
$al = ArrayList::create(); |
135
|
|
|
$al->push( |
136
|
|
|
ArrayData::create( |
137
|
|
|
array( |
138
|
|
|
'PageField' => 'Title', |
139
|
|
|
'TranslationField' => 'Title' |
140
|
|
|
) |
141
|
|
|
) |
142
|
|
|
); |
143
|
|
|
$al->push( |
144
|
|
|
ArrayData::create( |
145
|
|
|
array( |
146
|
|
|
'PageField' => 'Content', |
147
|
|
|
'TranslationField' => 'Content' |
148
|
|
|
) |
149
|
|
|
) |
150
|
|
|
); |
151
|
|
|
$this->extend('updateFieldsToReplace', $al); |
152
|
|
|
return $al; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
function Link() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return $this->getLink(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
function getLink() |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
$link = $this->Parent()->Link(); |
|
|
|
|
169
|
|
|
if($this->EcommerceCountryID) { |
|
|
|
|
170
|
|
|
$link .= '?'.$this->Config()->get('locale_get_parameter').'='.$this->EcommerceCountry()->Code; |
|
|
|
|
171
|
|
|
} |
172
|
|
|
return Director::absoluteURL($link); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
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.