This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @description EcommerceRole provides specific customisations to the {@link Member} |
||
4 | * class for the ecommerce module. |
||
5 | * |
||
6 | * |
||
7 | * |
||
8 | * @authors: Nicolaas [at] Sunny Side Up .co.nz |
||
9 | * @package: ecommerce |
||
10 | * @sub-package: extensions |
||
11 | * @inspiration: Silverstripe Ltd, Jeremy |
||
12 | **/ |
||
13 | class EcommerceRole extends DataExtension implements PermissionProvider |
||
14 | { |
||
15 | private static $max_count_of_members_in_array = 1500; |
||
16 | |||
17 | private static $api_access = array( |
||
18 | 'view' => array( |
||
19 | 'ID', |
||
20 | 'Orders', |
||
21 | 'PreferredCurrency', |
||
22 | ), |
||
23 | ); |
||
24 | |||
25 | /** |
||
26 | * standard SS method. |
||
27 | */ |
||
28 | private static $db = array( |
||
29 | 'Notes' => 'Text', |
||
30 | ); |
||
31 | |||
32 | private static $has_one = array( |
||
33 | 'PreferredCurrency' => 'EcommerceCurrency', |
||
34 | ); |
||
35 | |||
36 | private static $has_many = array( |
||
37 | 'Orders' => 'Order', |
||
38 | 'CancelledOrders' => 'Order', |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | *@return Group | NULL |
||
43 | **/ |
||
44 | public static function get_customer_group() |
||
45 | { |
||
46 | $customerCode = EcommerceConfig::get('EcommerceRole', 'customer_group_code'); |
||
47 | |||
48 | return DataObject::get_one( |
||
49 | 'Group', |
||
50 | array('Code' => $customerCode) |
||
51 | ); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * returns an aray of customers |
||
56 | * The unselect option shows an extra line, basically allowing you to deselect the |
||
57 | * current option. |
||
58 | * |
||
59 | * @param bool $showUnselectedOption |
||
60 | * |
||
61 | * @return array ( ID => Email (member.title) ) |
||
62 | */ |
||
63 | public static function list_of_customers($showUnselectedOption = false) |
||
64 | { |
||
65 | //start array |
||
66 | $array = array(); |
||
67 | if ($showUnselectedOption) { |
||
68 | $array[0] = _t('Member.SELECTCUSTOMER', ' --- SELECT CUSTOMER ---'); |
||
69 | } |
||
70 | //get customer group |
||
71 | $customerCode = EcommerceConfig::get('EcommerceRole', 'customer_group_code'); |
||
0 ignored issues
–
show
|
|||
72 | $group = self::get_customer_group(); |
||
73 | //fill array |
||
74 | if ($group) { |
||
75 | $members = $group->Members(); |
||
76 | $membersCount = $members->count(); |
||
77 | if ($membersCount > 0 && $membersCount < Config::inst()->get('EcommerceRole', 'max_count_of_members_in_array')) { |
||
78 | foreach ($members as $member) { |
||
79 | if ($member->Email) { |
||
80 | $array[$member->ID] = $member->Email.' ('.$member->getTitle().')'; |
||
81 | } |
||
82 | } |
||
83 | } else { |
||
84 | return $array; |
||
85 | } |
||
86 | } |
||
87 | //sort in a natural order |
||
88 | natcasesort($array); |
||
89 | |||
90 | return $array; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * returns an aray of customers |
||
95 | * The unselect option shows an extra line, basically allowing you to deselect the |
||
96 | * current option. |
||
97 | * |
||
98 | * @param bool $showUnselectedOption |
||
99 | * |
||
100 | * @return array ( ID => Email (member.title) ) |
||
101 | */ |
||
102 | public static function list_of_admins($showUnselectedOption = false) |
||
103 | { |
||
104 | //start array |
||
105 | $array = array(); |
||
106 | if ($showUnselectedOption) { |
||
107 | $array[0] = _t('Member.SELECT_ECOMMERCE_ADMIN', ' --- SELECT ADMIN ---'); |
||
108 | } |
||
109 | //get customer group |
||
110 | $customerCode = EcommerceConfig::get('EcommerceRole', 'customer_group_code'); |
||
0 ignored issues
–
show
$customerCode is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
111 | $group = self::get_admin_group(); |
||
112 | //fill array |
||
113 | if ($group) { |
||
114 | $members = $group->Members(); |
||
115 | $membersCount = $members->count(); |
||
116 | if ($membersCount > 0) { |
||
117 | foreach ($members as $member) { |
||
118 | if ($member->Email) { |
||
119 | $array[$member->ID] = $member->Email.' ('.$member->getTitle().')'; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | $group = DataObject::get_one( |
||
125 | 'Group', |
||
126 | array('Code' => 'administrators') |
||
127 | ); |
||
128 | //fill array |
||
129 | if ($group) { |
||
130 | $members = $group->Members(); |
||
131 | $membersCount = $members->count(); |
||
132 | if ($membersCount > 0) { |
||
133 | foreach ($members as $member) { |
||
134 | if ($member->Email) { |
||
135 | $array[$member->ID] = $member->Email.' ('.$member->getTitle().')'; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | //sort in a natural order |
||
141 | natcasesort($array); |
||
142 | |||
143 | return $array; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * tells us if the current member is in the Shop Administrators Group. |
||
148 | * |
||
149 | * @param Member | Null $member |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | public static function current_member_is_shop_admin($member = null) |
||
154 | { |
||
155 | if (!$member) { |
||
156 | $member = Member::currentUser(); |
||
157 | } |
||
158 | if ($member) { |
||
159 | return $member->IsShopAdmin(); |
||
160 | } |
||
161 | |||
162 | return false; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * tells us if the current member is in the Shop Administrators Group. |
||
167 | * |
||
168 | * @param Member | Null $member |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | public static function current_member_is_shop_assistant($member = null) |
||
173 | { |
||
174 | if (!$member) { |
||
175 | $member = Member::currentUser(); |
||
176 | } |
||
177 | if ($member) { |
||
178 | return $member->IsShopAssistant(); |
||
179 | } |
||
180 | |||
181 | return false; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * tells us if the current member can process the orders |
||
186 | * |
||
187 | * @param Member | Null $member |
||
188 | * |
||
189 | * @return bool |
||
190 | */ |
||
191 | public static function current_member_can_process_orders($member = null) |
||
192 | { |
||
193 | if (!$member) { |
||
194 | $member = Member::currentUser(); |
||
195 | } |
||
196 | if ($member) { |
||
197 | return $member->CanProcessOrders(); |
||
198 | } |
||
199 | |||
200 | return false; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return DataObject (Group) | NULL |
||
205 | **/ |
||
206 | public static function get_admin_group() |
||
207 | { |
||
208 | $adminCode = EcommerceConfig::get('EcommerceRole', 'admin_group_code'); |
||
209 | |||
210 | return DataObject::get_one( |
||
211 | 'Group', |
||
212 | array('Code' => $adminCode) |
||
213 | ); |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return DataObject (Group) | NULL |
||
218 | **/ |
||
219 | public static function get_assistant_group() |
||
220 | { |
||
221 | $assistantCode = EcommerceConfig::get('EcommerceRole', 'assistant_group_code'); |
||
222 | |||
223 | return DataObject::get_one( |
||
224 | 'Group', |
||
225 | array('Code' => $assistantCode) |
||
226 | ); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @return DataObject (Member) | NULL |
||
231 | **/ |
||
232 | public static function get_default_shop_admin_user() |
||
233 | { |
||
234 | $group = self::get_admin_group(); |
||
235 | if ($group) { |
||
236 | return $group->Members()->First(); |
||
237 | } |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * @return DataObject (Member) | NULL |
||
242 | **/ |
||
243 | public static function get_default_shop_assistant_user() |
||
244 | { |
||
245 | $group = self::get_assistant_group(); |
||
246 | if ($group) { |
||
247 | return $group->Members()->First(); |
||
248 | } |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * you can't delete a Member with one or more orders. |
||
253 | */ |
||
254 | public function canDelete($member = null) |
||
255 | { |
||
256 | if ($this->getOrders()->count()) { |
||
257 | return false; |
||
258 | } |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * we need this function because $this->Orders does not return anything |
||
263 | * that is probably because Order links the member twice (placed by and cancelled by). |
||
264 | * |
||
265 | * @return DataList |
||
266 | */ |
||
267 | public function Orders() |
||
268 | { |
||
269 | return $this->getOrders(); |
||
270 | } |
||
271 | |||
272 | public function getOrders() |
||
273 | { |
||
274 | return Order::get()->filter(array('MemberID' => $this->owner->ID)); |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
275 | } |
||
276 | |||
277 | public function CancelledOrders() |
||
278 | { |
||
279 | return $this->getCancelledOrders(); |
||
280 | } |
||
281 | |||
282 | public function getCancelledOrders() |
||
283 | { |
||
284 | return Order::get()->filter(array('CancelledByID' => $this->owner->ID)); |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
285 | } |
||
286 | |||
287 | /** |
||
288 | * creates two permission roles. |
||
289 | * standard SS Method. |
||
290 | * |
||
291 | * @return array |
||
292 | */ |
||
293 | public function providePermissions() |
||
294 | { |
||
295 | $category = EcommerceConfig::get('EcommerceRole', 'permission_category'); |
||
296 | $perms[EcommerceConfig::get('EcommerceRole', 'customer_permission_code')] = array( |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$perms was never initialized. Although not strictly required by PHP, it is generally a good practice to add $perms = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
297 | 'name' => _t( |
||
298 | 'EcommerceRole.CUSTOMER_PERMISSION_ANME', |
||
299 | 'Customers' |
||
300 | ), |
||
301 | 'category' => $category, |
||
302 | 'help' => _t( |
||
303 | 'EcommerceRole.CUSTOMERS_HELP', |
||
304 | 'Customer Permissions (usually very little)' |
||
305 | ), |
||
306 | 'sort' => 98, |
||
307 | ); |
||
308 | $perms[EcommerceConfig::get('EcommerceRole', 'admin_permission_code')] = array( |
||
309 | 'name' => EcommerceConfig::get('EcommerceRole', 'admin_role_title'), |
||
310 | 'category' => $category, |
||
311 | 'help' => _t( |
||
312 | 'EcommerceRole.ADMINISTRATORS_HELP', |
||
313 | 'Store Manager - can edit everything to do with the e-commerce application.' |
||
314 | ), |
||
315 | 'sort' => 99, |
||
316 | ); |
||
317 | $perms[EcommerceConfig::get('EcommerceRole', 'assistant_permission_code')] = array( |
||
318 | 'name' => EcommerceConfig::get('EcommerceRole', 'assistant_role_title'), |
||
319 | 'category' => $category, |
||
320 | 'help' => _t( |
||
321 | 'EcommerceRole.STORE_ASSISTANTS_HELP', |
||
322 | 'Store Assistant - can only view sales details and makes notes about orders' |
||
323 | ), |
||
324 | 'sort' => 100, |
||
325 | ); |
||
326 | $perms[EcommerceConfig::get('EcommerceRole', 'process_orders_permission_code')] = array( |
||
327 | 'name' => _t( |
||
328 | 'EcommerceRole.PROCESS_ORDERS_PERMISSION_NAME', |
||
329 | 'Can process orders' |
||
330 | ), |
||
331 | 'category' => $category, |
||
332 | 'help' => _t( |
||
333 | 'EcommerceRole.PROCESS_ORDERS_PERMISSION_HELP', |
||
334 | 'Can the user progress orders through the order steps (e.g. dispatch orders)' |
||
335 | ), |
||
336 | 'sort' => 101 |
||
337 | ); |
||
338 | return $perms; |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * Update the CMS Fields |
||
343 | * for /admin/security. |
||
344 | * |
||
345 | * @param FieldList $fields |
||
346 | * |
||
347 | * @return FieldList |
||
348 | */ |
||
349 | public function updateCMSFields(FieldList $fields) |
||
350 | { |
||
351 | $orderField = $fields->dataFieldByName('Orders'); |
||
352 | if ($orderField) { |
||
353 | $config = GridFieldConfig_RecordEditor::create(); |
||
354 | $config->removeComponentsByType('GridFieldDeleteAction'); |
||
355 | $config->removeComponentsByType('GridFieldAddNewButton'); |
||
356 | if ($orderField instanceof GridField) { |
||
357 | $orderField->setConfig($config); |
||
358 | $orderField->setList($this->getOrders()); |
||
359 | } |
||
360 | } else { |
||
361 | $orderField = new HiddenField('Orders', 'Orders'); |
||
362 | } |
||
363 | $preferredCurrencyField = $fields->dataFieldByName('PreferredCurrencyID'); |
||
364 | $notesFields = $fields->dataFieldByName('Notes'); |
||
365 | $loginAsField = new LiteralField( |
||
366 | 'LoginAsThisCustomer', |
||
367 | "<p class=\"actionInCMS\"><a href=\"".$this->owner->LoginAsLink()."\" target=\"_blank\">Login as this customer</a></p>" |
||
368 | ); |
||
369 | $link = Controller::join_links( |
||
370 | Director::baseURL(), |
||
371 | Config::inst()->get('ShoppingCart_Controller', 'url_segment').'/placeorderformember/'.$this->owner->ID.'/' |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
372 | ); |
||
373 | $orderForLink = new LiteralField('OrderForCustomerLink', "<p class=\"actionInCMS\"><a href=\"$link\" target=\"_blank\">Place order for customer</a></p>"); |
||
374 | $fields->addFieldsToTab( |
||
375 | 'Root.Orders', |
||
376 | array( |
||
377 | $orderField, |
||
378 | $preferredCurrencyField, |
||
379 | $notesFields, |
||
380 | $loginAsField, |
||
381 | $orderForLink, |
||
382 | ) |
||
383 | ); |
||
384 | |||
385 | return $fields; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Save a preferred currency for a member. |
||
390 | * |
||
391 | * @param EcommerceCurrency $currency - object for the currency |
||
392 | */ |
||
393 | public function SetPreferredCurrency(EcommerceCurrency $currency) |
||
394 | { |
||
395 | if ($this->owner->exists()) { |
||
396 | if ($currency && $currency->exists()) { |
||
397 | $this->owner->PreferredCurrencyID = $currency->ID; |
||
0 ignored issues
–
show
The property
PreferredCurrencyID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
398 | $this->owner->write(); |
||
399 | } |
||
400 | } |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * get CMS fields describing the member in the CMS when viewing the order. |
||
405 | * |
||
406 | * @return CompositeField |
||
407 | **/ |
||
408 | public function getEcommerceFieldsForCMS() |
||
409 | { |
||
410 | $fields = new CompositeField(); |
||
411 | $memberTitle = new ReadonlyField('MemberTitle', _t('Member.TITLE', 'Name'), '<p>'._t('Member.TITLE', 'Name').': '.$this->owner->getTitle().'</p>'); |
||
412 | $memberTitle->dontEscape = true; |
||
413 | $fields->push($memberTitle); |
||
414 | $memberEmail = new ReadonlyField('MemberEmail', _t('Member.EMAIL', 'Email'), '<p>'._t('Member.EMAIL', 'Email').': <a href="mailto:'.$this->owner->Email.'">'.$this->owner->Email.'</a></p>'); |
||
0 ignored issues
–
show
The property
Email does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
415 | $memberEmail->dontEscape = true; |
||
416 | $fields->push($memberEmail); |
||
417 | $lastLogin = new ReadonlyField('MemberLastLogin', _t('Member.LASTLOGIN', 'Last Login'), '<p>'._t('Member.LASTLOGIN', 'Last Login').': '.$this->owner->dbObject('LastVisited')->Nice().'</p>'); |
||
418 | $lastLogin->dontEscape = true; |
||
419 | $fields->push($lastLogin); |
||
420 | $group = self::get_customer_group(); |
||
421 | if (!$group) { |
||
422 | $group = new Group(); |
||
423 | } |
||
424 | $headerField = HeaderField::create('MemberLinkFieldHeader', _t('Member.EDIT_CUSTOMER', 'Edit Customer')); |
||
425 | $linkField1 = EcommerceCMSButtonField::create( |
||
426 | 'MemberLinkFieldEditThisCustomer', |
||
427 | $this->owner->CMSEditLink(), |
||
428 | _t('Member.EDIT', 'Edit').' <i>'.$this->owner->getTitle().'d</i>' |
||
429 | ); |
||
430 | $fields->push($headerField); |
||
431 | $fields->push($linkField1); |
||
432 | |||
433 | if (EcommerceRole::current_member_can_process_orders(Member::currentUser())) { |
||
434 | $linkField2 = EcommerceCMSButtonField::create( |
||
435 | 'MemberLinkFieldEditAllCustomers', |
||
436 | CMSEditLinkAPI::find_edit_link_for_object($group), |
||
437 | _t('Member.EDIT_ALL_CUSTOMERS', 'Edit All '.$group->Title) |
||
438 | ); |
||
439 | $fields->push($linkField2); |
||
440 | } |
||
441 | return $fields; |
||
442 | } |
||
443 | |||
444 | /** |
||
445 | * @param bool $additionalFields: add extra fields. |
||
0 ignored issues
–
show
There is no parameter named
$additionalFields: . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
446 | * |
||
447 | * @return FieldList |
||
448 | */ |
||
449 | public function getEcommerceFields($mustCreateAccount = false) |
||
450 | { |
||
451 | if (! EcommerceConfig::get('EcommerceRole', 'allow_customers_to_setup_accounts')) { |
||
452 | //if no accounts are made then we simply return the basics.... |
||
453 | $fields = new FieldList( |
||
454 | new TextField('FirstName', _t('EcommerceRole.FIRSTNAME', 'First Name')), |
||
455 | new TextField('Surname', _t('EcommerceRole.SURNAME', 'Surname')), |
||
456 | new EmailField('Email', _t('EcommerceRole.EMAIL', 'Email')) |
||
457 | ); |
||
458 | } else { |
||
459 | Requirements::javascript('ecommerce/javascript/EcomPasswordField.js'); |
||
460 | |||
461 | if ($this->owner->exists()) { |
||
462 | if ($this->owner->Password) { |
||
0 ignored issues
–
show
The property
Password does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
463 | $passwordField = new PasswordField('PasswordCheck1', _t('Account.NEW_PASSWORD', 'New Password')); |
||
464 | $passwordDoubleCheckField = new PasswordField('PasswordCheck2', _t('Account.CONFIRM_NEW_PASSWORD', 'Confirm New Password')); |
||
465 | $updatePasswordLinkField = new LiteralField('UpdatePasswordLink', '<a href="#Password" datano="'.Convert::raw2att(_t('Account.DO_NOT_UPDATE_PASSWORD', 'Do not update password')).'" class="updatePasswordLink passwordToggleLink secondary-button" rel="Password">'._t('Account.UPDATE_PASSWORD', 'Update Password').'</a>'); |
||
466 | } else { |
||
467 | //if they dont have a password then we now force them to create one. |
||
468 | //the fields of which are added further down the line... |
||
469 | } |
||
470 | //we simply hide these fields, as they add little extra .... |
||
471 | $loginDetailsHeader = new HiddenField('LoginDetails', _t('Account.LOGINDETAILS', 'Login Details'), 5); |
||
472 | $loginDetailsDescription = new HiddenField( |
||
473 | 'AccountInfo', |
||
474 | '<p>'. |
||
475 | _t('OrderForm.PLEASE_REVIEW', 'Please review your log in details below.') |
||
476 | .'</p>' |
||
477 | ); |
||
478 | } else { |
||
479 | //login invite right on the top |
||
480 | if (EcommerceConfig::get('EcommerceRole', 'must_have_account_to_purchase') || $mustCreateAccount) { |
||
481 | $loginDetailsHeader = new HeaderField('CreateAnAccount', _t('OrderForm.SETUPYOURACCOUNT', 'Create an account'), 3); |
||
482 | //dont allow people to purchase without creating a password |
||
483 | $loginDetailsDescription = new LiteralField( |
||
484 | 'AccountInfo', |
||
485 | '<p class"password-info">'. |
||
486 | _t('OrderForm.MUSTCREATEPASSWORD', 'Please choose a password to create your account.') |
||
487 | .'</p>' |
||
488 | ); |
||
489 | } else { |
||
490 | $loginDetailsHeader = new HeaderField('CreateAnAccount', _t('OrderForm.CREATEANACCONTOPTIONAL', 'Create an account (optional)'), 3); |
||
491 | //allow people to purchase without creating a password |
||
492 | $updatePasswordLinkField = new LiteralField('UpdatePasswordLink', '<a href="#Password" datano="'.Convert::raw2att(_t('Account.DO_NOT_CREATE_ACCOUNT', 'do not create account')).'" class="choosePassword passwordToggleLink">choose a password</a>'); |
||
493 | $loginDetailsDescription = new LiteralField( |
||
494 | 'AccountInfo', |
||
495 | '<p class="password-info">'. |
||
496 | _t('OrderForm.SELECTPASSWORD', 'Please enter a password; this will allow you to check your order history in the future.') |
||
497 | .'</p>' |
||
498 | ); |
||
499 | //close by default |
||
500 | } |
||
501 | } |
||
502 | |||
503 | if (empty($passwordField)) { |
||
504 | $passwordField = new PasswordField('PasswordCheck1', _t('Account.CREATE_PASSWORD', 'Password')); |
||
505 | $passwordDoubleCheckField = new PasswordField('PasswordCheck2', _t('Account.CONFIRM_PASSWORD', 'Confirm Password')); |
||
506 | } |
||
507 | if (empty($updatePasswordLinkField)) { |
||
508 | $updatePasswordLinkField = new LiteralField('UpdatePasswordLink', ''); |
||
509 | } |
||
510 | $fields = new FieldList( |
||
511 | new TextField('FirstName', _t('EcommerceRole.FIRSTNAME', 'First Name')), |
||
512 | new TextField('Surname', _t('EcommerceRole.SURNAME', 'Surname')), |
||
513 | new EmailField('Email', _t('EcommerceRole.EMAIL', 'Email')), |
||
514 | $loginDetailsHeader, |
||
515 | $loginDetailsDescription, |
||
516 | $updatePasswordLinkField, |
||
517 | $passwordField, |
||
518 | $passwordDoubleCheckField |
||
0 ignored issues
–
show
The variable
$passwordDoubleCheckField does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
519 | ); |
||
520 | } |
||
521 | $this->owner->extend('augmentEcommerceFields', $fields); |
||
522 | |||
523 | return $fields; |
||
524 | } |
||
525 | |||
526 | /** |
||
527 | * Return which member fields should be required on {@link OrderForm} |
||
528 | * and {@link ShopAccountForm}. |
||
529 | * |
||
530 | * @return array |
||
531 | */ |
||
532 | public function getEcommerceRequiredFields() |
||
533 | { |
||
534 | $fields = array( |
||
535 | 'FirstName', |
||
536 | 'Surname', |
||
537 | 'Email', |
||
538 | ); |
||
539 | if (EcommerceConfig::get('EcommerceRole', 'must_have_account_to_purchase')) { |
||
540 | $passwordFieldIsRequired = true; |
||
541 | if ($this->owner->exists()) { |
||
542 | if ($this->owner->Password) { |
||
0 ignored issues
–
show
The property
Password does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
543 | $passwordFieldIsRequired = false; |
||
544 | } |
||
545 | } |
||
546 | } else { |
||
547 | $passwordFieldIsRequired = false; |
||
548 | } |
||
549 | if ($passwordFieldIsRequired) { |
||
550 | $fields[] = 'PasswordCheck1'; |
||
551 | $fields[] = 'PasswordCheck2'; |
||
552 | } |
||
553 | $this->owner->extend('augmentEcommerceRequiredFields', $fields); |
||
554 | |||
555 | return $fields; |
||
556 | } |
||
557 | |||
558 | /** |
||
559 | * Is the member a member of the ShopAdmin Group. |
||
560 | * |
||
561 | * @return bool |
||
0 ignored issues
–
show
|
|||
562 | **/ |
||
563 | public function IsShopAdmin() |
||
564 | { |
||
565 | if (Permission::checkMember($this->owner, 'ADMIN')) { |
||
566 | return true; |
||
567 | } else { |
||
568 | return Permission::checkMember($this->owner, EcommerceConfig::get('EcommerceRole', 'admin_permission_code')); |
||
569 | } |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * Is the member a member of the SHOPASSISTANTS Group. |
||
574 | * |
||
575 | * @return bool |
||
0 ignored issues
–
show
|
|||
576 | **/ |
||
577 | public function IsShopAssistant() |
||
578 | { |
||
579 | if ($this->owner->IsShopAdmin()) { |
||
580 | return true; |
||
581 | } |
||
582 | |||
583 | return Permission::checkMember($this->owner, EcommerceConfig::get('EcommerceRole', 'assistant_permission_code')); |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * Is the member a member of the SHOPASSISTANTS Group. |
||
588 | * |
||
589 | * @return bool |
||
0 ignored issues
–
show
|
|||
590 | **/ |
||
591 | public function CanProcessOrders() |
||
592 | { |
||
593 | if ($this->owner->IsShopAdmin()) { |
||
594 | return true; |
||
595 | } |
||
596 | |||
597 | return Permission::checkMember($this->owner, EcommerceConfig::get('EcommerceRole', 'process_orders_permission_code')); |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * returns the last (submitted) order by the member. |
||
602 | * |
||
603 | * @param bool $includeUnsubmittedOrders - set to TRUE to include unsubmitted orders |
||
604 | */ |
||
605 | public function LastOrder($includeUnsubmittedOrders = false) |
||
606 | { |
||
607 | //limit to 10 |
||
608 | if ($includeUnsubmittedOrders) { |
||
609 | $orders = Order::get_datalist_of_orders_with_submit_record(false); |
||
610 | } else { |
||
611 | $orders = Order::get_datalist_of_orders_with_submit_record(true); |
||
612 | } |
||
613 | $lastOrder = $orders |
||
614 | ->Filter(array('MemberID' => $this->owner->ID)) |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
615 | ->First(); |
||
616 | |||
617 | return $lastOrder; |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * standard SS method |
||
622 | * Make sure the member is added as a customer. |
||
623 | */ |
||
624 | public function onAfterWrite() |
||
625 | { |
||
626 | $customerGroup = self::get_customer_group(); |
||
627 | if ($customerGroup) { |
||
628 | $existingMembers = $customerGroup->Members(); |
||
629 | if ($existingMembers) { |
||
630 | $existingMembers->add($this->owner); |
||
0 ignored issues
–
show
$this->owner is of type object<SS_Object> , but the function expects a object<DataObject>|integer .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
631 | } |
||
632 | } |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * Finds previous addresses from the member of the current address. |
||
637 | * |
||
638 | * @param string $type |
||
639 | * @param int $excludeID - the ID of the record to exlcude (if any) |
||
640 | * @param bool $onlyLastRecord - only select one |
||
641 | * @param bool $keepDoubles - keep addresses that are the same (if set to false, only unique addresses are returned) |
||
642 | * |
||
643 | * @return ArrayList (BillingAddresses | ShippingAddresses) |
||
644 | **/ |
||
645 | public function previousOrderAddresses($type = 'BillingAddress', $excludeID = 0, $onlyLastRecord = false, $keepDoubles = false) |
||
646 | { |
||
647 | $returnArrayList = new ArrayList(); |
||
648 | if ($this->owner->exists()) { |
||
649 | $fieldName = $type.'ID'; |
||
650 | $limit = 999; |
||
0 ignored issues
–
show
$limit is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
651 | if ($onlyLastRecord) { |
||
652 | $limit = 1; |
||
0 ignored issues
–
show
$limit is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
653 | } |
||
654 | $addresses = $type::get() |
||
655 | ->where( |
||
656 | '"Obsolete" = 0 AND "Order"."MemberID" = '.$this->owner->ID |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
657 | ) |
||
658 | ->sort('LastEdited', 'DESC') |
||
659 | ->exclude(array('ID' => $excludeID)) |
||
660 | //->limit($limit) |
||
661 | ->innerJoin('Order', '"Order"."'.$fieldName.'" = "OrderAddress"."ID"'); |
||
662 | if ($addresses->count()) { |
||
663 | if ($keepDoubles) { |
||
664 | foreach ($addresses as $address) { |
||
665 | $returnArrayList->push($address); |
||
666 | } |
||
667 | } else { |
||
668 | $addressCompare = array(); |
||
669 | foreach ($addresses as $address) { |
||
670 | $comparisonString = $address->comparisonString(); |
||
671 | if (in_array($comparisonString, $addressCompare)) { |
||
672 | //do nothing |
||
673 | } else { |
||
674 | $addressCompare[$address->ID] = $comparisonString; |
||
675 | $returnArrayList->push($address); |
||
676 | } |
||
677 | } |
||
678 | } |
||
679 | } |
||
680 | } |
||
681 | |||
682 | return $returnArrayList; |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * Finds the last address used by this member. |
||
687 | * |
||
688 | * @param string $type |
||
689 | * @param int $excludeID - the ID of the record to exlcude (if any) |
||
690 | **/ |
||
691 | public function previousOrderAddress($type = 'BillingAddress', $excludeID = 0) |
||
692 | { |
||
693 | $addresses = $this->previousOrderAddresses($type, $excludeID, true, false); |
||
694 | if ($addresses->count()) { |
||
695 | return $addresses->First(); |
||
696 | } |
||
697 | } |
||
698 | |||
699 | public function LoginAsLink() |
||
700 | { |
||
701 | return Controller::join_links( |
||
702 | Director::baseURL(), |
||
703 | Config::inst()->get('ShoppingCart_Controller', 'url_segment'). |
||
704 | '/loginas/'.$this->owner->ID.'/' |
||
0 ignored issues
–
show
The property
ID does not seem to exist in SS_Object .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
705 | ); |
||
706 | } |
||
707 | |||
708 | /** |
||
709 | * link to edit the record. |
||
710 | * |
||
711 | * @param string | Null $action - e.g. edit |
||
712 | * |
||
713 | * @return string |
||
0 ignored issues
–
show
|
|||
714 | */ |
||
715 | public function CMSEditLink($action = null) |
||
0 ignored issues
–
show
|
|||
716 | { |
||
717 | return CMSEditLinkAPI::find_edit_link_for_object($this->owner); |
||
718 | } |
||
719 | } |
||
720 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.