1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Extension; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
6
|
|
|
use SilverStripe\Forms\NumericField; |
7
|
|
|
use SilverStripe\Forms\RequiredFields; |
8
|
|
|
use SilverStripe\ORM\DataExtension; |
9
|
|
|
use SilverStripe\ORM\ValidationResult; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Shippable |
13
|
|
|
* @package Dynamic\Foxy\Extension |
14
|
|
|
* |
15
|
|
|
* @property double Weight |
16
|
|
|
*/ |
17
|
|
|
class Shippable extends DataExtension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
private static $db = [ |
|
|
|
|
23
|
|
|
'Weight' => 'Decimal(9,3)', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $defaults = [ |
|
|
|
|
30
|
|
|
'Weight' => '1.0', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param bool $includerelations |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function updateFieldLabels(&$labels) |
39
|
|
|
{ |
40
|
|
|
$labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Product Name'); |
41
|
|
|
$labels['Weight'] = _t(__CLASS__ . '.WeightLabel', 'Weight'); |
42
|
|
|
$labels['Image.CMSThumbnail'] = _t(__CLASS__ . '.ImageThumbnailLabel', 'Image'); |
43
|
|
|
$labels['Price.Nice'] = _t(__CLASS__ . '.PriceLabel', 'Price'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param FieldList $fields |
48
|
|
|
*/ |
49
|
|
|
public function updateCMSFields(FieldList $fields) |
50
|
|
|
{ |
51
|
|
|
parent::updateCMSFields($fields); |
52
|
|
|
|
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
|
|
|
/** |
69
|
|
|
* @return RequiredFields |
70
|
|
|
*/ |
71
|
|
|
public function getCMSValidator() |
72
|
|
|
{ |
73
|
|
|
return new RequiredFields([ |
74
|
|
|
"Price", |
75
|
|
|
"Code", |
76
|
|
|
"FoxyCategoryID", |
77
|
|
|
'Weight', |
78
|
|
|
]); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|