Test Failed
Push — master ( b74686...9a59de )
by Alexey
05:52
created

Delivery::providerHelper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Delivery
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ecommerce;
13
/**
14
 * Class Delivery
15
 *
16
 * @property int $id
17
 * @property int $delivery_provider_id
18
 * @property string $name
19
 * @property string $price_type
20
 * @property number $price
21
 * @property int $currency_id
22
 * @property string $price_text
23
 * @property number $max_cart_price
24
 * @property int $icon_file_id
25
 * @property string $info
26
 * @property bool $disabled
27
 * @property bool $default
28
 * @property number $weight
29
 * @property string $date_create
30
 * @property \Files\File $icon
31
 * @property \Money\Currency $currency
32
 * @property \Ecommerce\Delivery\Field[] $fields
33
 * @property \Ecommerce\Delivery\Price[] $prices
34
 */
35
class Delivery extends \Model {
36
37
    public static $objectName = 'Доставка';
38
    public static $cols = [
39
        //Основные параметры
40
        'name' => ['type' => 'text'],
41
        'delivery_provider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'provider'],
42
        'price' => ['type' => 'decimal'],
43
        'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'],
44
        'price_text' => ['type' => 'textarea'],
45
        'max_cart_price' => ['type' => 'decimal'],
46
        'icon_file_id' => ['type' => 'image'],
47
        'info' => ['type' => 'html'],
48
        'disabled' => ['type' => 'bool'],
49
        'default' => ['type' => 'bool'],
50
        //Системные
51
        'weight' => ['type' => 'number'],
52
        'date_create' => ['type' => 'dateTime'],
53
        //Менеджеры
54
        'field' => ['type' => 'dataManager', 'relation' => 'fields'],
55
        'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'],
56
        'disabledPayTypesMgr' => ['type' => 'dataManager', 'relation' => 'disabledPayTypes'],
57
    ];
58
    public static $labels = [
59
        'name' => 'Название',
60
        'price_type' => 'Тип расчета стоимости',
61
        'price' => 'Стоимость',
62
        'price_text' => 'Текстовое описание стоимости (отображается вместо цены)',
63
        'max_cart_price' => 'Басплатно при',
64
        'icon_file_id' => 'Иконка',
65
        'currency_id' => 'Валюта',
66
        'info' => 'Дополнительная информация',
67
        'priceChanger' => 'Градация стоимости',
68
        'field' => 'Поля',
69
        'disabled' => 'Отключено',
70
        'default' => 'По умолчанию',
71
        'disabledPayTypesMgr' => 'Недоступные способы оплаты',
72
    ];
73
    public static $dataManagers = [
74
        'manager' => [
75
            'name' => 'Варианты доставки',
76
            'cols' => [
77
                'name',
78
                'delivery_provider_id',
79
                'price',
80
                'currency_id',
81
                'max_cart_price',
82
                'disabled',
83
                'default',
84
                'field',
85
                'priceChanger',
86
                'disabledPayTypesMgr'
87
            ],
88
            'sortMode' => true
89
        ],
90
    ];
91
    public static $forms = [
92
        'manager' => [
93
            'map' => [
94
                ['name', 'delivery_provider_id'],
95
                ['default', 'disabled'],
96
                ['price', 'currency_id'],
97
                ['max_cart_price', 'icon_file_id'],
98
                ['price_text'],
99
                ['info'],
100
                ['priceChanger'],
101
                ['field'],
102
                ['disabledPayTypesMgr']
103
            ]
104
        ]
105
    ];
106
107
    public static function relations() {
108
        return [
109
            'icon' => [
110
                'model' => 'Files\File',
111
                'col' => 'icon_file_id'
112
            ],
113
            'currency' => [
114
                'model' => 'Money\Currency',
115
                'col' => 'currency_id'
116
            ],
117
            'fields' => [
118
                'type' => 'relModel',
119
                'model' => 'Ecommerce\Delivery\Field',
120
                'relModel' => 'Ecommerce\Delivery\DeliveryFieldLink'
121
            ],
122
            'prices' => [
123
                'type' => 'many',
124
                'model' => 'Ecommerce\Delivery\Price',
125
                'col' => 'delivery_id'
126
            ],
127
            'provider' => [
128
                'model' => 'Ecommerce\Delivery\Provider',
129
                'col' => 'delivery_provider_id'
130
            ],
131
            'disabledPayTypes' => [
132
                'type' => 'many',
133
                'model' => 'Ecommerce\Delivery\DisablePayType',
134
                'col' => 'delivery_id'
135
            ],
136
        ];
137
    }
138
139
    public function providerHelper() {
140
        if ($this->provider) {
0 ignored issues
show
Bug introduced by
The property provider does not seem to exist. Did you mean delivery_provider_id?

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...
141
            return 'Ecommerce\DeliveryProvider\\' . $this->provider->object;
0 ignored issues
show
Bug introduced by
The property provider does not seem to exist. Did you mean delivery_provider_id?

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...
142
        }
143
        return false;
144
    }
145
146
    function beforeSave() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
147
        if ($this->default) {
148
            Delivery::update(['default' => 0]);
149
        }
150
    }
151
}
152