ProductPageController::PurchaseForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Dynamic\FoxyStripe\Page;
4
5
use Dynamic\FoxyStripe\Form\FoxyStripePurchaseForm;
6
use SilverStripe\View\Requirements;
7
8
/**
9
 * Class ProductPageController
10
 * @package Dynamic\FoxyStripe\Page
11
 *
12
 * @mixin ProductPage
13
 */
14
class ProductPageController extends \PageController
15
{
16
    private static $allowed_actions = array(
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
17
        'PurchaseForm',
18
    );
19
20
    public function init()
21
    {
22
        parent::init();
23
        Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
24
        if ($this->data()->Available && $this->ProductOptions()->exists()) {
0 ignored issues
show
Bug introduced by
The method ProductOptions() does not exist on Dynamic\FoxyStripe\Page\ProductPageController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        if ($this->data()->Available && $this->/** @scrutinizer ignore-call */ ProductOptions()->exists()) {
Loading history...
25
            $formName = $this->PurchaseForm()->FormName();
0 ignored issues
show
Unused Code introduced by
The assignment to $formName is dead and can be removed.
Loading history...
26
            /*Requirements::javascriptTemplate(
27
                'dynamic/foxystripe: javascript/out_of_stock.js',
28
                [
29
                    'FormName' => $formName,
30
                ],
31
                'foxystripe.out_of_stock'
32
            );*/
33
            Requirements::javascript('dynamic/foxystripe: javascript/product_options.js');
34
        }
35
36
        Requirements::customScript(<<<JS
37
		var productID = {$this->data()->ID};
38
JS
39
        );
40
    }
41
42
    /**
43
     * @return FoxyStripePurchaseForm
44
     */
45
    public function PurchaseForm()
46
    {
47
        $form = FoxyStripePurchaseForm::create($this, __FUNCTION__, null, null, null, $this->data());
48
49
        $this->extend('updateFoxyStripePurchaseForm', $form);
50
51
        return $form;
52
    }
53
}
54