Passed
Pull Request — master (#27)
by Jason
02:14
created

AddToCartFormExtension::updateProductActions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Extension;
4
5
use Dynamic\Foxy\Form\AddToCartForm;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\HiddenField;
9
10
class AddToCartFormExtension extends Extension
11
{
12
    /**
13
     * @param FieldList $fields
14
     */
15
    public function updateProductFields(FieldList &$fields)
16
    {
17
        if ($this->owner->getProduct()->CartExpiration) {
18
            $fields->insertAfter(
19
                'url',
20
                HiddenField::create('expires')
21
                    ->setValue(
22
                        AddToCartForm::getGeneratedValue(
23
                            $this->owner->getProduct()->Code,
24
                            'expires',
25
                            $this->owner->getProduct()->ExpirationMinutes,
26
                            'value'
27
                        )
28
                    )
29
            );
30
        }
31
    }
32
}
33