Test Failed
Push — master ( 23cc6e...476483 )
by Alexey
05:28
created

Delivery::relations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 0
dl 0
loc 26
rs 8.8571
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
    ];
57
    public static $labels = [
58
        'name' => 'Название',
59
        'price_type' => 'Тип расчета стоимости',
60
        'price' => 'Стоимость',
61
        'price_text' => 'Текстовое описание стоимости (отображается вместо цены)',
62
        'max_cart_price' => 'Басплатно при',
63
        'icon_file_id' => 'Иконка',
64
        'currency_id' => 'Валюта',
65
        'info' => 'Дополнительная информация',
66
        'priceChanger' => 'Градация стоимости',
67
        'field' => 'Поля',
68
        'disabled' => 'Отключено',
69
        'default' => 'По умолчанию',
70
    ];
71
    public static $dataManagers = [
72
        'manager' => [
73
            'name' => 'Варианты доставки',
74
            'cols' => [
75
                'name',
76
                'delivery_provider_id',
77
                'price',
78
                'currency_id',
79
                'max_cart_price',
80
                'disabled',
81
                'default',
82
                'field',
83
                'priceChanger',
84
            ],
85
            'sortMode' => true
86
        ],
87
    ];
88
    public static $forms = [
89
        'manager' => [
90
            'map' => [
91
                ['name', 'delivery_provider_id'],
92
                ['default', 'disabled'],
93
                ['price', 'currency_id'],
94
                ['max_cart_price', 'icon_file_id'],
95
                ['price_text'],
96
                ['info'],
97
                ['priceChanger'],
98
                ['field']
99
            ]
100
        ]
101
    ];
102
103
    public static function relations() {
104
        return [
105
            'icon' => [
106
                'model' => 'Files\File',
107
                'col' => 'icon_file_id'
108
            ],
109
            'currency' => [
110
                'model' => 'Money\Currency',
111
                'col' => 'currency_id'
112
            ],
113
            'fields' => [
114
                'type' => 'relModel',
115
                'model' => 'Ecommerce\Delivery\Field',
116
                'relModel' => 'Ecommerce\Delivery\DeliveryFieldLink'
117
            ],
118
            'prices' => [
119
                'type' => 'many',
120
                'model' => 'Ecommerce\Delivery\Price',
121
                'col' => 'delivery_id'
122
            ],
123
            'provider' => [
124
                'model' => 'Ecommerce\Delivery\Provider',
125
                'col' => 'delivery_provider_id'
126
            ]
127
        ];
128
    }
129
130
    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...
131
        if ($this->default) {
132
            Delivery::update(['default' => 0]);
133
        }
134
    }
135
}
136