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

PurchaseFormExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
ccs 2
cts 11
cp 0.1818
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A updatePurchaseFormFields() 0 12 2
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