|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hideyo\Ecommerce\Framework\Services\Product\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Hideyo\Ecommerce\Framework\Services\BaseModel; |
|
6
|
|
|
use Carbon\Carbon; |
|
7
|
|
|
|
|
8
|
|
|
class ProductAmountOption extends BaseModel |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The database table used by the model. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $table = 'product_amount_option'; |
|
16
|
|
|
|
|
17
|
|
|
// Add the 'avatar' attachment to the fillable array so that it's mass-assignable on this model. |
|
18
|
|
|
protected $fillable = ['product_id', 'amount', 'discount_type', 'discount_value', 'discount_start_date', 'discount_end_date', 'modified_by_user_id']; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
public function setDiscountStartDateAttribute($value) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->attributes['discount_start_date'] = null; |
|
25
|
|
|
|
|
26
|
|
|
if ($value) { |
|
27
|
|
|
$date = explode('/', $value); |
|
28
|
|
|
|
|
29
|
|
|
$value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString(); |
|
|
|
|
|
|
30
|
|
|
$this->attributes['discount_start_date'] = $value; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getDiscountStartDateAttribute($value) |
|
35
|
|
|
{ |
|
36
|
|
|
if ($value) { |
|
37
|
|
|
$date = explode('-', $value); |
|
38
|
|
|
return $date[2].'/'.$date[1].'/'.$date[0]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setDiscountEndDateAttribute($value) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->attributes['discount_end_date'] = null; |
|
47
|
|
|
|
|
48
|
|
|
if ($value) { |
|
49
|
|
|
$date = explode('/', $value); |
|
50
|
|
|
$value = Carbon::createFromDate($date[2], $date[1], $date[0])->toDateTimeString(); |
|
|
|
|
|
|
51
|
|
|
$this->attributes['discount_end_date'] = $value; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getDiscountEndDateAttribute($value) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($value) { |
|
58
|
|
|
$date = explode('-', $value); |
|
59
|
|
|
return $date[2].'/'.$date[1].'/'.$date[0]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function product() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->belongsTo('Hideyo\Ecommerce\Framework\Services\Product\Entity\Product'); |
|
68
|
|
|
} |
|
69
|
|
|
} |