1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Cart module for Yii2 |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/yii2-cart |
7
|
|
|
* @package yii2-cart |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hiqdev\yii2\cart; |
13
|
|
|
|
14
|
|
|
use Yii; |
15
|
|
|
use yii\base\Model; |
16
|
|
|
use yii\grid\GridView; |
17
|
|
|
use yii\helpers\Html; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* CartPositionTrait trait |
21
|
|
|
* It is intended to be used in classes implementing [[CartPositionInterface]]. |
22
|
|
|
* Holds: |
23
|
|
|
* - object (model) and ID. |
24
|
|
|
* - name and description |
25
|
|
|
* Provides: |
26
|
|
|
* - icon with getIcon() to be redefined in childs |
27
|
|
|
*/ |
28
|
|
|
trait CartPositionTrait |
29
|
|
|
{ |
30
|
|
|
use \yz\shoppingcart\CartPositionTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Model object being put in cart |
34
|
|
|
*/ |
35
|
|
|
protected $_model; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string|int ID of object being put in cart |
39
|
|
|
*/ |
40
|
|
|
protected $_id; |
41
|
|
|
|
42
|
|
|
public function rules() |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
[['model_id'], 'integer', 'min' => 1], |
46
|
|
|
[['name', 'description', 'parent_id'], 'string'], |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function attributeLabels() |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
'model_id' => Yii::t('cart', 'ID'), |
54
|
|
|
'name' => Yii::t('cart', 'Name'), |
55
|
|
|
'price' => Yii::t('cart', 'Price'), |
56
|
|
|
'quantity' => Yii::t('cart', 'Quantity'), |
57
|
|
|
'description' => Yii::t('cart', 'Description'), |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function attributes() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'model_id', |
65
|
|
|
'parent_id', |
66
|
|
|
'name', |
67
|
|
|
'quantity', |
68
|
|
|
'description', |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* This closure will be called in [[GridView::rowOptions]]. |
74
|
|
|
* |
75
|
|
|
* @param integer $key the key value associated with the current data model |
76
|
|
|
* @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]] |
77
|
|
|
* @param GridView $grid the GridView object |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function getRowOptions($key, $index, $grid) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
return []; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getIcon() |
86
|
|
|
{ |
87
|
|
|
return '<i class="fa fa-check"></i>'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getName() |
91
|
|
|
{ |
92
|
|
|
return $this->name; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getDescription() |
96
|
|
|
{ |
97
|
|
|
return $this->description; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function renderDescription() |
101
|
|
|
{ |
102
|
|
|
return $this->getIcon() . ' ' . $this->getName() . ' ' . Html::tag('span', $this->getDescription(), ['class' => 'text-muted']); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getAdditionalLinks(): array |
106
|
|
|
{ |
107
|
|
|
return []; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getRelatedPositions(): array |
111
|
|
|
{ |
112
|
|
|
return []; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function hasParent(): bool |
116
|
|
|
{ |
117
|
|
|
return !empty($this->parent_id); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getModel() |
121
|
|
|
{ |
122
|
|
|
return $this->_model; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.