Passed
Push — master ( 1900ed...f72112 )
by Nic
02:54 queued 13s
created

Shippable::getCMSValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
23
        'Weight' => 'Decimal(9,3)',
24
    ];
25
26
    /**
27
     * @var array
28
     */
29
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
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