1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Form; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Model\Setting; |
6
|
|
|
use Dynamic\Products\Page\Product; |
|
|
|
|
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 = [ |
|
|
|
|
22
|
|
|
'newvalue', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array $properties |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function Field($properties = []) |
30
|
|
|
{ |
31
|
|
|
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.min.js'); |
32
|
|
|
Requirements::javascript('dynamic/silverstripe-foxy: client/dist/javascript/quantity.js'); |
33
|
|
|
Requirements::css('dynamic/silverstripe-foxy: client/dist/css/quantityfield.css'); |
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
|
|
|
$this->setAttribute('id', 'quantity-toggle-field'); |
39
|
|
|
if ($this->getProduct()->QuantityMax > 0) { |
40
|
|
|
$this->setAttribute('data-limit', $this->getProduct()->QuantityMax); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return parent::Field($properties); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return Product |
48
|
|
|
*/ |
49
|
|
|
public function getProduct() |
50
|
|
|
{ |
51
|
|
|
return $this->getForm()->getProduct(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param HTTPRequest $request |
56
|
|
|
* @return bool|string |
57
|
|
|
*/ |
58
|
|
|
public function newvalue(HTTPRequest $request) |
59
|
|
|
{ |
60
|
|
|
$value = $request->getVar('value'); |
61
|
|
|
if (!$value && $value != 0) { |
|
|
|
|
62
|
|
|
return ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!$code = $request->getVar('code')) { |
66
|
|
|
return ''; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->extend('updateQuantity', $value); |
70
|
|
|
|
71
|
|
|
$data = [ |
72
|
|
|
'quantity' => $value, |
73
|
|
|
'quantityGenerated' => AddToCartForm::getGeneratedValue($code, 'quantity', $value, 'value'), |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
if ($this->getProduct()->QuantityMax > 0) { |
77
|
|
|
$data['limit'] = $this->getProduct()->QuantityMax; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->extend('updateData', $data); |
81
|
|
|
|
82
|
|
|
return json_encode($data); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths