|
1
|
|
|
<?php |
|
2
|
|
|
namespace Hideyo\Ecommerce\Framework\Services\Product\Entity; |
|
3
|
|
|
|
|
4
|
|
|
use Hideyo\Ecommerce\Framework\Repositories\ProductImageRepository; |
|
|
|
|
|
|
5
|
|
|
use Hideyo\Ecommerce\Framework\Services\Redirect\Entity\RedirectRepository; |
|
6
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\Entity\Product; |
|
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductImage; |
|
8
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductAttribute; |
|
9
|
|
|
use Hideyo\Ecommerce\Framework\Services\BaseRepository; |
|
10
|
|
|
|
|
11
|
|
|
class ProductRepository extends BaseRepository |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
protected $model; |
|
15
|
|
|
|
|
16
|
|
|
protected $guard = 'admin'; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public function __construct(Product $model, ProductImage $modelImage, RedirectRepository $redirect) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->model = $model; |
|
22
|
|
|
$this->modelImage = $modelImage; |
|
|
|
|
|
|
23
|
|
|
$this->redirect = $redirect; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
public function selectByLimitAndOrderBy($shopId, $limit, $orderBy) |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->model->with(array('productCategory', 'relatedProducts', 'productImages' => function ($query) { |
|
30
|
|
|
$query->orderBy('rank', 'asc'); |
|
31
|
|
|
}))->where('shop_id', $shopId)->where('active', 1)->limit($limit)->orderBy('id', $orderBy)->get(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function selectAllByShopId($shopId) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
return $this->model->where('shop_id', $shopId)->get(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function selectAllExport() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->model->with(array('productImages' => function ($query) { |
|
42
|
|
|
$query->orderBy('rank', 'asc'); |
|
43
|
|
|
}))->where('active', 1)->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function selectAllWithCombinations() |
|
47
|
|
|
{ |
|
48
|
|
|
$result = $this->model->with(array('attributes'))->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get(); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$newResult = array(); |
|
51
|
|
|
foreach ($result as $product) { |
|
52
|
|
|
$newResult[$product->id] = $product->title; |
|
53
|
|
|
if ($product->attributes->count()) { |
|
|
|
|
|
|
54
|
|
|
foreach ($product->attributes as $attribute) { |
|
55
|
|
|
$attributesArray = array(); |
|
56
|
|
|
foreach ($attribute->combinations as $combination) { |
|
57
|
|
|
$attributesArray[] = $combination->attribute->value; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$newResult[$product->id.'-'.$attribute->id] = $product->title.' - '.implode(', ', $attributesArray); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $newResult; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function selectAllByProductParentId($productParentId) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->where('product_parent_id', '=', $productParentId)->get(); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function selectOneById($productId) |
|
74
|
|
|
{ |
|
75
|
|
|
$result = $this->model->with(array('productCategory', 'relatedProducts', 'productImages' => function ($query) { |
|
76
|
|
|
$query->orderBy('rank', 'asc'); |
|
77
|
|
|
}))->where('active', 1)->where('id', '=', $productId)->get()->first(); |
|
78
|
|
|
return $result; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function findImage($imageId) |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->modelImage->find($imageId); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getImageModel() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->modelImage; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
function selectAllByShopIdAndProductCategoryId($shopId, $productCategoryId, $filters = false) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$result = $this->model |
|
96
|
|
|
->with(array('subcategories', 'extraFields' => function ($query) { |
|
97
|
|
|
$query->with('extraField')->orderBy('id', 'desc'); |
|
98
|
|
|
}, 'taxRate', 'productCategory', 'relatedProducts' => function ($query) { |
|
99
|
|
|
$query->with('productImages')->orderBy('rank', 'asc'); |
|
100
|
|
|
}, 'productImages' => function ($query) { |
|
101
|
|
|
$query->orderBy('rank', 'asc'); |
|
102
|
|
|
})) |
|
103
|
|
|
->where('shop_id', $shopId) |
|
104
|
|
|
->where('active', 1) |
|
105
|
|
|
->whereNotNull('product.product_category_id') |
|
106
|
|
|
->where(function ($query) use ($productCategoryId) { |
|
107
|
|
|
$query->where('product_category_id', '=', $productCategoryId); |
|
108
|
|
|
$query->orWhereHas('subcategories', function ($query) use ($productCategoryId) { |
|
109
|
|
|
$query->where('product_category_id', '=', $productCategoryId); |
|
110
|
|
|
}); |
|
111
|
|
|
}); |
|
112
|
|
|
|
|
113
|
|
|
$result->orderBy(\DB::raw('product.rank = 0, '.'product.rank'), 'ASC'); |
|
114
|
|
|
|
|
115
|
|
|
return $result->get(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function selectOneByShopIdAndId($shopId, $productId = false, $attributeId = false) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
return $this->model->with( |
|
121
|
|
|
array( |
|
122
|
|
|
'attributeGroup', |
|
123
|
|
|
'attributes' => function ($query) { |
|
124
|
|
|
$query->with( |
|
125
|
|
|
array( |
|
126
|
|
|
'combinations' => function ($query) { |
|
127
|
|
|
$query->with( |
|
128
|
|
|
array( |
|
129
|
|
|
'productAttribute', |
|
130
|
|
|
'attribute' => function ($query) { |
|
131
|
|
|
$query->with( |
|
132
|
|
|
array( |
|
133
|
|
|
'attributeGroup' |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
) |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
) |
|
141
|
|
|
)->orderBy('default_on', 'desc'); |
|
142
|
|
|
}, |
|
143
|
|
|
'extraFields' => function ($query) { |
|
144
|
|
|
$query->where( |
|
145
|
|
|
'value', |
|
146
|
|
|
'!=', |
|
147
|
|
|
'' |
|
148
|
|
|
)->orWhereNotNull('extra_field_default_value_id')->with(array('extraField', |
|
149
|
|
|
'extraFieldDefaultValue'))->orderBy( |
|
150
|
|
|
'id', |
|
151
|
|
|
'desc' |
|
152
|
|
|
); |
|
153
|
|
|
}, |
|
154
|
|
|
'relatedProducts' => function ($query) { |
|
155
|
|
|
$query->with( |
|
156
|
|
|
'productImages', |
|
157
|
|
|
'productCategory' |
|
158
|
|
|
)->orderBy( |
|
159
|
|
|
'rank', |
|
160
|
|
|
'asc' |
|
161
|
|
|
); |
|
162
|
|
|
}, |
|
163
|
|
|
'productImages' => function ($query) { |
|
164
|
|
|
$query->orderBy( |
|
165
|
|
|
'rank', |
|
166
|
|
|
'asc' |
|
167
|
|
|
)->with(array('relatedProductAttributes', |
|
168
|
|
|
'relatedAttributes')); |
|
169
|
|
|
}) |
|
170
|
|
|
)->where('shop_id', $shopId)->where('active', 1)->whereNotNull('product_category_id')->where('id', '=', $productId)->get()->first(); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function ajaxProductImages($product, $combinationsIds, $productAttributeId = false) |
|
174
|
|
|
{ |
|
175
|
|
|
$images = array(); |
|
176
|
|
|
|
|
177
|
|
|
if($product->productImages->count()) { |
|
178
|
|
|
|
|
179
|
|
|
$images = $product->productImages()->has('relatedAttributes', '=', 0)->has('relatedProductAttributes', '=', 0)->orderBy('rank', '=', 'asc')->get(); |
|
180
|
|
|
|
|
181
|
|
|
if($combinationsIds) { |
|
182
|
|
|
|
|
183
|
|
|
$imagesRelatedAttributes = ProductImage:: |
|
184
|
|
|
whereHas('relatedAttributes', function($query) use ($combinationsIds, $product) { $query->with(array('productImage'))->whereIn('attribute_id', $combinationsIds); }) |
|
|
|
|
|
|
185
|
|
|
->where('product_id', '=', $product->id) |
|
186
|
|
|
->get(); |
|
187
|
|
|
|
|
188
|
|
|
if($imagesRelatedAttributes) { |
|
189
|
|
|
$images = $images->merge($imagesRelatedAttributes)->sortBy('rank'); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if($productAttributeId) { |
|
195
|
|
|
|
|
196
|
|
|
$imagesRelatedProductAttributes = ProductImage:: |
|
197
|
|
|
whereHas('relatedProductAttributes', function($query) use ($productAttributeId, $product) { $query->where('product_attribute_id', '=', $productAttributeId); }) |
|
|
|
|
|
|
198
|
|
|
->where('product_id', '=', $product->id) |
|
199
|
|
|
->get(); |
|
200
|
|
|
|
|
201
|
|
|
if($imagesRelatedProductAttributes) { |
|
202
|
|
|
$images = $images->merge($imagesRelatedProductAttributes)->sortBy('rank'); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
$images->toArray(); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $images; |
|
212
|
|
|
} |
|
213
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths