Passed
Push — master ( 14d1c0...a78c29 )
by Jason
01:30
created

Shippable::updateCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 14
rs 9.9666
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\ORM\ValidationResult;
8
9
class Shippable extends Purchasable
10
{
11
    /**
12
     * @var array
13
     */
14
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
15
        'Weight' => 'Decimal',
16
    ];
17
18
    /**
19
     * @var array
20
     */
21
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
22
        'Weight' => '0.0',
23
    ];
24
25
    /**
26
     * @param bool $includerelations
27
     *
28
     * @return array
29
     */
30
    public function updateFieldLabels(&$labels)
31
    {
32
        $labels['Weight'] = _t(__CLASS__ . '.WeightLabel', 'Weight');
33
    }
34
35
    /**
36
     * @param FieldList $fields
37
     */
38
    public function updateCMSFields(FieldList $fields)
39
    {
40
        $fields->addFieldsToTab(
41
            'Root.Main',
42
            [
43
                NumericField::create('Weight')
44
                    ->setTitle(_t('ProductPage.Weight', 'Weight'))
45
                    ->setDescription(_t(
46
                        'ProductPage.WeightDescription',
47
                        'Base weight for this product in lbs. Can be modified using Product Options'
48
                    ))
49
                    ->setScale(2),
50
            ],
51
            'Content'
52
        );
53
    }
54
55
    /**
56
     * @return \SilverStripe\ORM\ValidationResult
57
     */
58
    public function validate(ValidationResult $validationResult)
59
    {
60
        if (!$this->owner->Weight) {
61
            $validationResult->addError(
62
                _t(__CLASS__ . '.WeightRequired', 'You must set a product weight')
63
            );
64
        }
65
    }
66
}
67