AddToCartFormExtension::updateProductFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 12
rs 9.9332
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
/**
11
 * Class AddToCartFormExtension
12
 * @package Dynamic\Foxy\Inventory\Extension
13
 */
14
class AddToCartFormExtension extends Extension
15
{
16
    /**
17
     * @param FieldList $fields
18
     */
19
    public function updateProductFields(FieldList &$fields)
20
    {
21
        if ($this->owner->getProduct()->CartExpiration) {
22
            $fields->insertAfter(
23
                'url',
24
                HiddenField::create('expires')
25
                    ->setValue(
26
                        AddToCartForm::getGeneratedValue(
27
                            $this->owner->getProduct()->Code,
28
                            'expires',
29
                            $this->owner->getProduct()->ExpirationMinutes,
30
                            'value'
31
                        )
32
                    )
33
            );
34
        }
35
    }
36
}
37