1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Alexey Tatarinov <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2015 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
*/
|
8
|
|
|
class RetailCrmProductList extends ProductList
|
9
|
|
|
{
|
10
|
|
|
protected $assignments;
|
11
|
|
|
|
12
|
|
|
protected $parameters;
|
13
|
|
|
|
14
|
|
|
protected $images;
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/* protected function afterFetchData($event)
|
18
|
|
|
{
|
19
|
|
|
$keys = $this->dataProvider->getKeys(true);
|
20
|
|
|
|
21
|
|
|
$this->setAssignmentsRetailCrm($keys);
|
22
|
|
|
$this->setParametersRetailCrm($keys);
|
23
|
|
|
$this->setImagesRetailCrm($keys);
|
24
|
|
|
$this->setParentsRetailCrm();
|
25
|
|
|
}*/
|
26
|
|
|
|
27
|
|
|
public function getAssignmentsRetailCrm()
|
28
|
|
|
{
|
29
|
|
|
return $this->assignments;
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
public function getParametersRetailCrm()
|
33
|
|
|
{
|
34
|
|
|
return $this->parameters;
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
public function getImages()
|
38
|
|
|
{
|
39
|
|
|
return $this->images;
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/* protected function initCriteria(CDbCriteria $criteria)
|
43
|
|
|
{
|
44
|
|
|
$assignment = ProductAssignment::model()->tableName();
|
45
|
|
|
$assignmentCriteria = new CDbCriteria();
|
46
|
|
|
$assignmentCriteria->select = 'product_id';
|
47
|
|
|
$assignmentCriteria->compare('visible', 1);
|
48
|
|
|
$assignmentCriteria->distinct = true;
|
49
|
|
|
|
50
|
|
|
$command = Yii::app()->db->commandBuilder->createFindCommand($assignment, $assignmentCriteria);
|
51
|
|
|
$criteria->addInCondition('t.id', $command->queryColumn());
|
52
|
|
|
$criteria->compare('t.visible', 1);
|
53
|
|
|
|
54
|
|
|
$this->criteria = $criteria;
|
55
|
|
|
}*/
|
56
|
|
|
|
57
|
|
|
protected function setParentsRetailCrm()
|
58
|
|
|
{
|
59
|
|
|
$criteria = new CDbCriteria();
|
60
|
|
|
$criteria->addInCondition('t.id', $this->getParentIds());
|
61
|
|
|
$criteria->index = 'id';
|
62
|
|
|
$parents = Product::model()->findAll($criteria);
|
63
|
|
|
|
64
|
|
|
/**
|
65
|
|
|
* @var Product $product
|
66
|
|
|
*/
|
67
|
|
|
foreach($this->dataProvider->getData() as $product)
|
68
|
|
|
{
|
69
|
|
|
if( !empty($product->parent) )
|
70
|
|
|
{
|
71
|
|
|
$product->addRelatedRecord('parentProduct', Arr::get($parents, $product->parent), false);
|
72
|
|
|
}
|
73
|
|
|
}
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
protected function setImagesRetailCrm($keys)
|
77
|
|
|
{
|
78
|
|
|
$criteria = new CDbCriteria();
|
79
|
|
|
$criteria->compare('type', 'main');
|
80
|
|
|
$criteria->addInCondition('parent', CMap::mergeArray($keys, $this->getParentIds()));
|
81
|
|
|
|
82
|
|
|
$command = Yii::app()->db->commandBuilder->createFindCommand(ProductImage::model()->tableName(), $criteria);
|
83
|
|
|
|
84
|
|
|
foreach($command->queryAll() as $image)
|
85
|
|
|
$this->images[$image['parent']] = Yii::app()->request->getHostInfo().'/f/product/'.$image['name'];
|
86
|
|
|
|
87
|
|
|
return $this->images;
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
protected function setAssignmentsRetailCrm($keys)
|
91
|
|
|
{
|
92
|
|
|
$criteria = new CDbCriteria(array('select' => 'a.product_id, a.id'));
|
93
|
|
|
$criteria->addInCondition('a.product_id', $keys);
|
94
|
|
|
$assignmentModel = new ProductAssignment();
|
95
|
|
|
$assignments = $assignmentModel->getAssignments($criteria);
|
96
|
|
|
|
97
|
|
|
$this->assignments = array();
|
98
|
|
|
foreach($assignments as $assignment)
|
99
|
|
|
{
|
100
|
|
|
$this->assignments[$assignment['product_id']][$assignment['id']] = $assignment;
|
101
|
|
|
}
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
protected function setParametersRetailCrm($keys)
|
105
|
|
|
{
|
106
|
|
|
$criteria = new CDbCriteria();
|
107
|
|
|
$criteria->select = 't.*, pn.name as pn_name, pv.name as pv_name';
|
108
|
|
|
$criteria->join .= ' JOIN {{product_param_name}} as pn on(pn.id = t.param_id)';
|
109
|
|
|
$criteria->join .= ' JOIN {{product_param_variant}} as pv on(pv.id = t.variant_id)';
|
110
|
|
|
$criteria->compare('pn.product', 1);
|
111
|
|
|
$criteria->order = 'pn.name';
|
112
|
|
|
$criteria->addInCondition('t.product_id', $keys);
|
113
|
|
|
|
114
|
|
|
$builder = new CDbCommandBuilder(Yii::app()->db->getSchema());
|
115
|
|
|
$command = $builder->createFindCommand(ProductParameter::model()->tableName(), $criteria, 't');
|
116
|
|
|
$parameters = $command->queryAll();
|
117
|
|
|
|
118
|
|
|
$this->parameters = array();
|
119
|
|
|
foreach($parameters as $parameter)
|
120
|
|
|
{
|
121
|
|
|
if( !empty($parameter['pv_name']) || !empty($parameter['value']) )
|
122
|
|
|
{
|
123
|
|
|
$this->parameters[$parameter['product_id']][$parameter['param_id']]['id'] = $parameter['param_id'];
|
124
|
|
|
$this->parameters[$parameter['product_id']][$parameter['param_id']]['name'] = $parameter['pn_name'];
|
125
|
|
|
$this->parameters[$parameter['product_id']][$parameter['param_id']]['variants'][] = !empty($parameter['pv_name']) ? $parameter['pv_name'] : $parameter['value'];
|
126
|
|
|
}
|
127
|
|
|
}
|
128
|
|
|
}
|
129
|
|
|
} |