Completed
Push — master ( 8827e6...300e34 )
by Nic
15s queued 12s
created

ProductController::AddToCartForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Dynamic\Foxy\Controller;
4
5
use Dynamic\Foxy\Form\AddToCartForm;
6
use Dynamic\Foxy\Model\FoxyHelper;
7
use Dynamic\Foxy\Model\Setting;
8
use SilverStripe\View\Requirements;
9
10
/**
11
 *
12
 */
13
class ProductController extends \PageController
14
{
15
    /**
16
     * @var array
17
     */
18
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
19
        'AddToCartForm',
20
    ];
21
22
    /**
23
     *
24
     */
25
    public function init()
26
    {
27
        parent::init();
28
29
        if ($this->hasMethod('isAvailable')) {
30
            if ($this->data()->getIsAvailable()) {
31
                if ($this->data()->Variations()->count()) {
32
                    Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
33
                    Requirements::javascript('dynamic/silverstripe-foxy: client/dist/javascript/product_options.js');
34
                }
35
            }
36
        }
37
38
        $config = Setting::current_foxy_setting();
39
        $helper = FoxyHelper::create();
40
41
        if ($config->EnableSidecart) {
42
            Requirements::javascript(
43
                "https://cdn.foxycart.com/" . $helper->getStoreCartURL() . "/loader.js",
44
                [
45
                    "async" => true,
46
                    "defer" => true,
47
                ]
48
            );
49
        }
50
    }
51
52
    /**
53
     * @return AddToCartForm
54
     */
55
    public function AddToCartForm()
56
    {
57
        if ($this->data()->getIsAvailable()) {
58
            $form = AddToCartForm::create($this, __FUNCTION__, null, null, null, $this->data());
59
        } else {
60
            $form = false;
61
        }
62
        $this->extend('updateAddToCartForm', $form);
63
64
        return $form;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function StoreURL()
71
    {
72
        $helper = FoxyHelper::create();
73
74
        return $helper::StoreURL();
75
    }
76
77
}
78