Passed
Push — master ( 91af14...32a131 )
by Jason
03:27
created

PurchasableExtension::onAfterInit()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Foxy\Extension;
4
5
use Dynamic\Foxy\Form\AddToCartForm;
6
use Dynamic\Foxy\Model\FoxyHelper;
7
use SilverStripe\Core\Extension;
8
use SilverStripe\View\Requirements;
9
10
class PurchasableExtension extends Extension
11
{
12
    /**
13
     * @var array
14
     */
15
    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...
16
        'AddToCartForm',
17
    );
18
19
    public function onAfterInit()
20
    {
21
        if ($this->owner->data()->isAvailable()) {
22
            if ($this->owner->data()->OptionTypes()->exists()) {
23
                Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
24
                Requirements::javascript('dynamic/silverstripe-foxy: client/dist/javascript/product_options.js');
25
            }
26
            Requirements::customScript(<<<JS
27
		        var productID = {$this->owner->data()->ID};
28
JS
29
            );
30
        }
31
    }
32
33
    /**
34
     * @return FoxyStripePurchaseForm
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Extension\FoxyStripePurchaseForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
     */
36
    public function AddToCartForm()
37
    {
38
        if ($this->owner->data()->isAvailable()) {
39
            $form = AddToCartForm::create($this->owner, __FUNCTION__, null, null, null, $this->owner->data());
40
        } else {
41
            $form = false;
42
        }
43
        $this->owner->extend('updateAddToCartForm', $form);
44
        return $form;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function StoreURL()
51
    {
52
        $helper = FoxyHelper::create();
53
        return $helper::StoreURL();
54
    }
55
}
56