Passed
Push — master ( 44cbe3...1a2823 )
by Jason
01:49
created

QuantityField::getProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Foxy\Form;
4
5
use Dynamic\Foxy\Model\Setting;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Forms\NumericField;
9
use SilverStripe\View\Requirements;
10
11
/**
12
 * Class QuantityField
13
 * @package Dynamic\FoxyStripe\Form
14
 */
15
class QuantityField extends NumericField
16
{
17
    /**
18
     * @var array
19
     */
20
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
21
        'newvalue',
22
    ];
23
24
    /**
25
     * @param array $properties
26
     * @return string
27
     */
28
    public function Field($properties = [])
29
    {
30
        //Requirements::javascript('dynamic/foxystripe: javascript/quantity.js');
31
        //Requirements::css('dynamic/foxystripe: client/dist/css/quantityfield.css');
32
33
34
        $this->setAttribute('data-link', $this->Link('newvalue'));
35
        $this->setAttribute('data-code', $this->getProduct()->Code);
36
        $this->setAttribute('data-id', $this->getProduct()->ID);
37
38
        return parent::Field($properties);
39
    }
40
41
    /**
42
     * @return ProductPage
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Form\ProductPage 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...
43
     */
44
    public function getProduct()
45
    {
46
        return $this->getForm()->getProduct();
47
    }
48
49
    /**
50
     * @param SS_HTTPRequest $request
0 ignored issues
show
Bug introduced by
The type Dynamic\Foxy\Form\SS_HTTPRequest 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...
51
     * @return bool|string
52
     */
53
    public function newvalue(HTTPRequest $request)
54
    {
55
        if (!$value = $request->getVar('value')) {
56
            return '';
57
        }
58
59
        if (!$code = $request->getVar('code')) {
60
            return '';
61
        }
62
63
        $this->extend('updateQuantity', $value);
64
65
        $data = array(
66
            'quantity' => $value,
67
            'quantityGenerated' => AddToCartForm::getGeneratedValue($code, 'quantity', $value, 'value'),
68
        );
69
70
        $this->extend('updateData', $data);
71
        return json_encode($data);
72
    }
73
}
74