|
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'], '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
|
|
|
'name', |
|
66
|
|
|
'quantity', |
|
67
|
|
|
'description', |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* This closure will be called in [[GridView::rowOptions]]. |
|
73
|
|
|
* |
|
74
|
|
|
* @param integer $key the key value associated with the current data model |
|
75
|
|
|
* @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]] |
|
76
|
|
|
* @param GridView $grid the GridView object |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getRowOptions($key, $index, $grid) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
return []; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getIcon() |
|
85
|
|
|
{ |
|
86
|
|
|
return '<i class="fa fa-check"></i>'; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getName() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->name; |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getDescription() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->description; |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function renderDescription() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->getIcon() . ' ' . $this->getName() . ' ' . Html::tag('span', $this->getDescription(), ['class' => 'text-muted']); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function renderBuyMoreLink(): array |
|
105
|
|
|
{ |
|
106
|
|
|
return []; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getModel() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->_model; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.