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

SalesAdminExtras::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 SalesAdminExtras 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-advanced';
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 Details';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
27
28
    /**
29
     * standard SS variable.
30
     *
31
     * @var int
32
     */
33
    private static $menu_priority = 3.11;
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
    }
54
55
56
    /**
57
     * @return array Map of class name to an array of 'title' (see {@link $managed_models})
58
     *               we make sure that the Order Admin is FIRST
59
     */
60
    public function getManagedModels()
61
    {
62
        $models = parent::getManagedModels();
63
        $orderModelManagement = isset($models['Order']) ? $models['Order'] : null;
64
        if ($orderModelManagement) {
65
            unset($models['Order']);
66
67
            return array('Order' => $orderModelManagement) + $models;
68
        }
69
70
        return $models;
71
    }
72
73
    /**
74
     * @return DataList
75
     */
76
    public function getList()
77
    {
78
        $list = parent::getList();
79
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
80
            $submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order');
81
            $list = $list
82
                ->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"')
83
                ->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"')
84
                ->where('"OrderStatusLog"."ClassName" = \''.$submittedOrderStatusLogClassName.'\'');
85
        }
86
        $newLists = $this->extend('updateGetList', $list);
87
        if (is_array($newLists) && count($newLists)) {
88
            foreach ($newLists as $newList) {
89
                if ($newList instanceof DataList) {
90
                    $list = $newList;
91
                }
92
            }
93
        }
94
95
        return $list;
96
    }
97
98
99
    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...
100
    {
101
        $form = parent::getEditForm($id, $fields);
102
        if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') {
103
            if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
104
                if ($gridField instanceof GridField) {
105
                    $config = $gridField->getConfig();
106
                    $exportButton = new GridFieldExportSalesButton('buttons-before-left');
107
                    $exportButton->setExportColumns($this->getExportFields());
108
                    $config->addComponent($exportButton);
109
                    $printAllInvoices = new GridFieldPrintAllInvoicesButton('buttons-before-left');
110
                    $config->addComponent($printAllInvoices);
111
                    $printAllPackingSlips = new GridFieldPrintAllPackingSlipsButton('buttons-before-left');
112
                    $config->addComponent($printAllPackingSlips);
113
                    //per row ...
114
                    $config->addComponent(new GridFieldPrintInvoiceButton());
115
                    // $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...
116
                }
117
            }
118
        }
119
        return $form;
120
    }
121
}
122