|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Page; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Controller\ShippableProductController; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\NumericField; |
|
8
|
|
|
use SilverStripe\Forms\RequiredFields; |
|
9
|
|
|
|
|
10
|
|
|
class ShippableProduct extends Product |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private static $table_name = 'ShippableProduct'; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
private static $db = [ |
|
|
|
|
|
|
21
|
|
|
'Weight' => 'Decimal(9,3)', |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
private static $defaults = [ |
|
|
|
|
|
|
28
|
|
|
'Weight' => '1.0', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param bool $includerelations |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
|
|
public function fieldLabels($includerelations = true) |
|
36
|
|
|
{ |
|
37
|
|
|
$labels = parent::fieldLabels($includerelations); |
|
38
|
|
|
|
|
39
|
|
|
$labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Product Name'); |
|
40
|
|
|
$labels['Weight'] = _t(__CLASS__ . '.WeightLabel', 'Weight'); |
|
41
|
|
|
$labels['Image.CMSThumbnail'] = _t(__CLASS__ . '.ImageThumbnailLabel', 'Image'); |
|
42
|
|
|
$labels['Price.Nice'] = _t(__CLASS__ . '.PriceLabel', 'Price'); |
|
43
|
|
|
|
|
44
|
|
|
return $labels; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return FieldList |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getCMSFields() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
53
|
|
|
$fields->addFieldsToTab( |
|
54
|
|
|
'Root.Ecommerce', |
|
55
|
|
|
[ |
|
56
|
|
|
NumericField::create('Weight') |
|
57
|
|
|
->setTitle($this->owner->fieldLabel('Weight')) |
|
|
|
|
|
|
58
|
|
|
->setDescription(_t( |
|
59
|
|
|
__CLASS__ . '.WeightDescription', |
|
60
|
|
|
'Base weight for this product in lbs. Can be modified using Product Options. Only supports up to 3 decimal places' |
|
61
|
|
|
)) |
|
62
|
|
|
->setScale(3), |
|
63
|
|
|
], |
|
64
|
|
|
'FoxyCategoryID' |
|
65
|
|
|
); |
|
66
|
|
|
}); |
|
67
|
|
|
|
|
68
|
|
|
return parent::getCMSFields(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return RequiredFields |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCMSValidator() |
|
75
|
|
|
{ |
|
76
|
|
|
$validator = parent::getCMSValidator(); |
|
77
|
|
|
|
|
78
|
|
|
$validator->appendRequiredFields( |
|
79
|
|
|
new RequiredFields([ |
|
80
|
|
|
'Weight', |
|
81
|
|
|
]) |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
return $validator; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getControllerName() |
|
91
|
|
|
{ |
|
92
|
|
|
return ShippableProductController::class; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|