1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hideyo\Ecommerce\Framework\Services\Product\Entity; |
4
|
|
|
|
5
|
|
|
use Hideyo\Ecommerce\Framework\Services\BaseModel; |
6
|
|
|
use Cviebrock\EloquentSluggable\Sluggable; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Elasticquent\ElasticquentTrait; |
|
|
|
|
9
|
|
|
|
10
|
|
|
class Product extends BaseModel |
11
|
|
|
{ |
12
|
|
|
use ElasticquentTrait, Sluggable; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The database table used by the model. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $table = 'product'; |
20
|
|
|
|
21
|
|
|
// Add the 'avatar' attachment to the fillable array so that it's mass-assignable on this model. |
22
|
|
|
protected $fillable = ['active', 'discount_promotion', 'discount_type', 'discount_value', 'discount_start_date', 'discount_end_date', 'title', 'brand_id', 'product_category_id', 'reference_code', 'ean_code', 'mpn_code', 'short_description', 'description', 'ingredients', 'price', 'commercial_price', 'tax_rate_id', 'amount', 'meta_title', 'meta_description', 'meta_keywords', 'shop_id', 'modified_by_user_id', 'weight', 'leading_atrribute_group_id', 'rank']; |
23
|
|
|
|
24
|
|
|
public function sluggable() |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
'slug' => [ |
28
|
|
|
'source' => 'title' |
29
|
|
|
] |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function getIndexName() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return 'product'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function setDiscountStartDateAttribute($value) |
39
|
|
|
{ |
40
|
|
|
$this->attributes['discount_start_date'] = null; |
41
|
|
|
|
42
|
|
|
if ($value) { |
43
|
|
|
$date = explode('/', $value); |
44
|
|
|
$value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString(); |
|
|
|
|
45
|
|
|
$this->attributes['discount_start_date'] = $value; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getDiscountStartDateAttribute($value) |
50
|
|
|
{ |
51
|
|
|
if ($value) { |
52
|
|
|
$date = explode('-', $value); |
53
|
|
|
return $date[2].'/'.$date[1].'/'.$date[0]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setDiscountEndDateAttribute($value) |
60
|
|
|
{ |
61
|
|
|
$this->attributes['discount_end_date'] = null; |
62
|
|
|
|
63
|
|
|
if ($value) { |
64
|
|
|
$date = explode('/', $value); |
65
|
|
|
$value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString(); |
|
|
|
|
66
|
|
|
$this->attributes['discount_end_date'] = $value; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setRankAttribute($value) |
71
|
|
|
{ |
72
|
|
|
if (is_null($value)) { |
73
|
|
|
$value = 0; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getDiscountEndDateAttribute($value) |
78
|
|
|
{ |
79
|
|
|
if ($value) { |
80
|
|
|
$date = explode('-', $value); |
81
|
|
|
return $date[2].'/'.$date[1].'/'.$date[0]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getPriceDetails() |
88
|
|
|
{ |
89
|
|
|
if ($this->price) { |
90
|
|
|
$taxRate = 0; |
91
|
|
|
$priceInc = 0; |
92
|
|
|
$taxValue = 0; |
93
|
|
|
|
94
|
|
|
if (isset($this->taxRate->rate)) { |
95
|
|
|
$taxRate = $this->taxRate->rate; |
96
|
|
|
$priceInc = (($this->taxRate->rate / 100) * $this->price) + $this->price; |
97
|
|
|
$taxValue = $priceInc - $this->price; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$discountPriceInc = false; |
101
|
|
|
$discountPriceEx = false; |
102
|
|
|
$discountTaxRate = 0; |
103
|
|
|
if ($this->discount_value) { |
104
|
|
|
if ($this->discount_type == 'amount') { |
105
|
|
|
$discountPriceInc = $priceInc - $this->discount_value; |
106
|
|
|
$discountPriceEx = $discountPriceInc / 1.21; |
107
|
|
|
} elseif ($this->discount_type == 'percent') { |
108
|
|
|
$tax = ($this->discount_value / 100) * $priceInc; |
109
|
|
|
$discountPriceInc = $priceInc - $tax; |
110
|
|
|
$discountPriceEx = $discountPriceInc / 1.21; |
111
|
|
|
} |
112
|
|
|
$discountTaxRate = $discountPriceInc - $discountPriceEx; |
113
|
|
|
$discountPriceInc = $discountPriceInc; |
114
|
|
|
$discountPriceEx = $discountPriceEx; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$commercialPrice = null; |
118
|
|
|
if ($this->commercial_price) { |
119
|
|
|
$commercialPrice = number_format($this->commercial_price, 2, '.', ''); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return array( |
123
|
|
|
'original_price_ex_tax' => $this->price, |
124
|
|
|
'original_price_ex_tax_number_format' => number_format($this->price, 2, '.', ''), |
125
|
|
|
'original_price_inc_tax' => $priceInc, |
126
|
|
|
'original_price_inc_tax_number_format' => number_format($priceInc, 2, '.', ''), |
127
|
|
|
'commercial_price_number_format' => $commercialPrice, |
128
|
|
|
'tax_rate' => $taxRate, |
129
|
|
|
'tax_value' => $taxValue, |
130
|
|
|
'currency' => 'EU', |
131
|
|
|
'discount_price_inc' => $discountPriceInc, |
132
|
|
|
'discount_price_inc_number_format' => number_format($discountPriceInc, 2, '.', ''), |
|
|
|
|
133
|
|
|
'discount_price_ex' => $discountPriceEx, |
134
|
|
|
'discount_price_ex_number_format' => number_format($discountPriceEx, 2, '.', ''), |
135
|
|
|
'discount_tax_value' => $discountTaxRate, |
136
|
|
|
'discount_value' => $this->discount_value, |
137
|
|
|
'amount' => $this->amount |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return null; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function shop() |
145
|
|
|
{ |
146
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\Shop\Entity\Shop'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function attributeGroup() |
150
|
|
|
{ |
151
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\Attribute\Entity\AttributeGroup', 'leading_atrribute_group_id'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function extraFields() |
155
|
|
|
{ |
156
|
|
|
return $this->hasMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductExtraFieldValue'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function taxRate() |
160
|
|
|
{ |
161
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\TaxRate\Entity\TaxRate'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function brand() |
165
|
|
|
{ |
166
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\Brand\Entity\Brand'); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function productCategory() |
170
|
|
|
{ |
171
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\ProductCategory\Entity\ProductCategory'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function subcategories() |
175
|
|
|
{ |
176
|
|
|
return $this->belongsToMany('Hideyo\Ecommerce\Framework\Services\ProductCategory\Entity\ProductCategory', 'product_sub_product_category'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function relatedProducts() |
180
|
|
|
{ |
181
|
|
|
return $this->belongsToMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\Product', 'product_related_product', 'product_id', 'related_product_id'); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function relatedProductsActive() |
185
|
|
|
{ |
186
|
|
|
return $this->belongsToMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\Product', 'product_related_product', 'product_id', 'related_product_id')->whereHas('productCategory', function ($query) { |
187
|
|
|
$query->where('active', '=', '1'); |
188
|
|
|
})->where('product.active', '=', '1'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function productImages() |
192
|
|
|
{ |
193
|
|
|
return $this->hasMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductImage'); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function attributes() |
197
|
|
|
{ |
198
|
|
|
return $this->hasMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductAttribute'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function amountOptions() |
202
|
|
|
{ |
203
|
|
|
return $this->hasMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductAmountOption'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function amountSeries() |
207
|
|
|
{ |
208
|
|
|
return $this->hasMany('Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductAmountSeries'); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
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