Completed
Push — master ( 747acb...c6269f )
by Nicolaas
03:40
created

SalesAdmin::getManagedModels()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
/**
5
 * @description: CMS management for everything you have sold and all related data (e.g. logs, payments)
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: cms
10
 * @inspiration: Silverstripe Ltd, Jeremy
11
 **/
12
class SalesAdmin extends ModelAdminEcommerceBaseClass
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...
13
{
14
    /**
15
     * standard SS variable.
16
     *
17
     * @var string
18
     */
19
    private static $url_segment = 'sales';
0 ignored issues
show
Unused Code introduced by
The property $url_segment 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
20
21
    /**
22
     * standard SS variable.
23
     *
24
     * @var string
25
     */
26
    private static $menu_title = 'Sales to Action';
0 ignored issues
show
Unused Code introduced by
The property $menu_title 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
28
    /**
29
     * standard SS variable.
30
     *
31
     * @var int
32
     */
33
    private static $menu_priority = 3.1;
0 ignored issues
show
Unused Code introduced by
The property $menu_priority 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
34
35
    /**
36
     * Change this variable if you don't want the Import from CSV form to appear.
37
     * This variable can be a boolean or an array.
38
     * If array, you can list className you want the form to appear on. i.e. array('myClassOne','myClasstwo').
39
     */
40
    public $showImportForm = false;
41
42
    /**
43
     * standard SS variable.
44
     *
45
     * @var string
46
     */
47
    private static $menu_icon = 'ecommerce/images/icons/money-file.gif';
0 ignored issues
show
Unused Code introduced by
The property $menu_icon 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
48
49
    public function init()
50
    {
51
        parent::init();
52
        Requirements::javascript('ecommerce/javascript/EcomBuyableSelectField.js');
53
        //Requirements::themedCSS("OrderReport", 'ecommerce'); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
54
        //Requirements::themedCSS("Order_Invoice", 'ecommerce', "print"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
55
        //Requirements::themedCSS("Order_PackingSlip", 'ecommerce', "print"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
56
        //Requirements::themedCSS("OrderStepField",'ecommerce'); // LEAVE HERE
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
57
        //Requirements::javascript("ecommerce/javascript/EcomModelAdminExtensions.js"); // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
58
    }
59
60
    public function urlSegmenter()
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...
61
    {
62
        return $this->config()->get('url_segment');
63
    }
64
65
    /**
66
     * @return array Map of class name to an array of 'title' (see {@link $managed_models})
67
     *               we make sure that the Order Admin is FIRST
68
     */
69
    public function getManagedModels()
70
    {
71
        $models = parent::getManagedModels();
72
        $orderModelManagement = isset($models['Order']) ? $models['Order'] : null;
73
        if ($orderModelManagement) {
74
            unset($models['Order']);
75
76
            return array('Order' => $orderModelManagement) + $models;
77
        }
78
79
        return $models;
80
    }
81
82
83
    /**
84
     * @return DataList
85
     */
86
    public function getList()
87
    {
88
        $list = parent::getList();
89
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
90
            $queueObjectSingleton = Injector::inst()->get('OrderProcessQueue');
91
            $ordersinQueue = $queueObjectSingleton->OrdersInQueueThatAreNotReady();
92
            $list = $list
93
                ->filter(
94
                    array(
95
                        "CancelledByID" => 0,
96
                        "StatusID:greaterThan" => 0
97
                    )
98
                )
99
                ->exclude(
100
                    array(
101
                        'ID' => $ordersinQueue->column('ID'),
102
                    )
103
                );
104
            //you can only do one exclude at the same time.
105
            $list = $list
106
                ->exclude(
107
                    array(
108
                        'StatusID' => OrderStep::non_admin_manageable_steps()->column('ID')
109
                    )
110
                );
111
        }
112
113
        $newLists = $this->extend('updateGetList', $list);
114
        if (is_array($newLists) && count($newLists)) {
115
            foreach ($newLists as $newList) {
116
                if ($newList instanceof DataList) {
117
                    $list = $newList;
118
                }
119
            }
120
        }
121
        return $list;
122
    }
123
124
125
    public function getEditForm($id = null, $fields = null)
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...
126
    {
127
        $form = parent::getEditForm($id, $fields);
128
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
129
            if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
130
                if ($gridField instanceof GridField) {
131
                    $config = $gridField->getConfig();
132
                    $exportButton = new GridFieldExportSalesButton('buttons-before-left');
133
                    $exportButton->setExportColumns($this->getExportFields());
134
                    $config->addComponent($exportButton);
135
                    $printAllInvoices = new GridFieldPrintAllInvoicesButton('buttons-before-left');
136
                    $config->addComponent($printAllInvoices);
137
                    $printAllPackingSlips = new GridFieldPrintAllPackingSlipsButton('buttons-before-left');
138
                    $config->addComponent($printAllPackingSlips);
139
                    //per row ...
140
                    $config->addComponent(new GridFieldPrintInvoiceButton());
141
                    // $config->addComponent(new GridFieldPrintPackingSlipButton());
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
142
                }
143
            }
144
        }
145
        return $form;
146
    }
147
}
148