Completed
Pull Request — master (#12)
by Nic
03:57
created

PurchaseFormExtension::updatePurchaseFormFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.1909

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 12
ccs 2
cts 11
cp 0.1818
crap 4.1909
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Extension;
4
5
use Dynamic\FoxyStripe\Page\ProductPage;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\HiddenField;
9
10
/**
11
 * Class ProductFormExtension
12
 * @package Dynamic\Sheeps\ProductCartExpiry\Extension
13
 */
14
class PurchaseFormExtension extends Extension
15
{
16 1
    public function updatePurchaseFormFields(FieldList $fields)
17
    {
18 1
        if ($this->owner->getProduct()->CartExpiration) {
19
            $fields->insertBefore(
20
                'quantity',
21
                HiddenField::create('expires')
22
                    ->setValue(
23
                        ProductPage::getGeneratedValue(
24
                            $this->owner->getProduct()->Code,
25
                            'expires',
26
                            $this->owner->getProduct()->ExpirationMinutes,
27
                            'value'
28
                        )
29
                    )
30
            );
31
        }
32
    }
33
}
34