EcommerceAssignOrdersExtension::updateCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
class EcommerceAssignOrdersExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
        'AssignedAdmin' => 'Member'
7
    );
8
9
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
        'AssignedAdminNice' => 'Varchar'
11
    );
12
13
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
        'AssignedAdminNice' => 'Admin'
15
    );
16
17
    private static $searchable_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $searchable_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
        "AssignedAdminID" => array(
19
            'field' => 'TextField',
20
            'filter' => 'ExactMatchFilter',
21
            'title' => 'Assigned Admin'
22
        )
23
    );
24
25
    private static $notify_by_email = true;
0 ignored issues
show
Unused Code introduced by
The property $notify_by_email is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
27
    public function getAssignedAdminNice()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
28
    {
29
        if ($this->owner->AssignedAdminID) {
0 ignored issues
show
Bug introduced by
The property AssignedAdminID 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.

Loading history...
30
            if ($admin = $this->owner->AssignedAdmin()) {
31
                if ($admin->exists()) {
32
                    return $admin->getTitle();
33
                }
34
            }
35
        }
36
        return 'n/a';
37
    }
38
39
    /**
40
     * Update Fields
41
     * @return FieldList
0 ignored issues
show
Documentation introduced by
Should the return type not be FieldList|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
42
     */
43
    public function updateCMSFields(FieldList $fields)
44
    {
45
        $fields->addFieldToTab(
46
            'Root.Next',
47
            $this->getAssignedAdminDropdown(),
48
            'OrderSummary'
49
        );
50
    }
51
52
    public function scaffoldSearchFields($fieldList, $_params)
0 ignored issues
show
Unused Code introduced by
The parameter $_params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        $fieldList->push($this->getAssignedAdminDropdown());
55
    }
56
57
    protected function getAssignedAdminDropdown()
58
    {
59
        $shopAdminAndCurrentCustomerArray = EcommerceRole::list_of_admins(true);
60
        $titleArray = Config::inst()->get('EcommerceAssignOrdersExtension', 'searchable_fields');
61
        $title = isset($titleArray['AssignedAdminID']['title']) ? $titleArray['AssignedAdminID']['title'] : 'Admin';
62
        return DropdownField::create(
63
            'AssignedAdminID',
64
            $title,
65
            $shopAdminAndCurrentCustomerArray
66
        );
67
    }
68
69
    public function onAfterWrite()
70
    {
71
        if (Config::inst()->get('EcommerceAssignOrdersExtension', 'notify_by_email')) {
72
            if ($this->owner->AssignedAdminID) {
73
                if ($this->owner->isChanged('AssignedAdminID')) {
74
                    //$member = $this->owner->AssignedAdmin();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
                    $member = Member::get()->byID($this->owner->AssignedAdminID);
0 ignored issues
show
Bug introduced by
The property AssignedAdminID 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.

Loading history...
76
                    if ($member && $member->exists() && $member->Email) {
77
                        $this->owner->sendEmail(
78
                            $emailClassName = 'Order_InvoiceEmail',
79
                            $subject = 'An order has been assigned to you on '.Director::absoluteURL('/'),
80
                            $message = '<p>An order has been assigned to you:</p> <h1><a href="'.$this->owner->CMSEditLink().'">Open Order</a></h1>',
81
                            $resend = true,
82
                            $adminOnlyOrToEmail = $member->Email
83
                        );
84
                    }
85
                }
86
            }
87
        }
88
    }
89
}
90