QuantityField::newvalue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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