1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Inventory\Test\TestOnly\Form; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Form\AddToCartForm; |
6
|
|
|
use Dynamic\Foxy\Inventory\Extension\AddToCartFormExtension; |
7
|
|
|
use Dynamic\Foxy\Model\FoxyHelper; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\Forms\RequiredFields; |
10
|
|
|
|
11
|
|
|
class TestAddToCartForm extends AddToCartForm |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private static $extensions = [ |
|
|
|
|
17
|
|
|
AddToCartFormExtension::class, |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
$controller, |
22
|
|
|
$name, |
23
|
|
|
FieldList $fields = null, |
24
|
|
|
FieldList $actions = null, |
25
|
|
|
$validator = null, |
26
|
|
|
$product = null, |
27
|
|
|
$helper = null |
28
|
|
|
) { |
29
|
|
|
$this->setProduct($product); |
30
|
|
|
$this->setFoxyHelper($helper); |
31
|
|
|
|
32
|
|
|
$fields = ($fields != null && $fields->exists()) ? |
33
|
|
|
$this->getProductFields($fields) : |
34
|
|
|
$this->getProductFields(FieldList::create()); |
35
|
|
|
|
36
|
|
|
$actions = ($actions != null && $actions->exists()) ? |
37
|
|
|
$this->getProductActions($actions) : |
38
|
|
|
$this->getProductActions(FieldList::create()); |
39
|
|
|
|
40
|
|
|
$validator = (!empty($validator) || $validator != null) ? $validator : RequiredFields::create(); |
41
|
|
|
|
42
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator); |
43
|
|
|
|
44
|
|
|
//have to call after parent::__construct() |
45
|
|
|
$this->setAttribute('action', FoxyHelper::FormActionURL()); |
46
|
|
|
$this->disableSecurityToken(); |
47
|
|
|
$this->setHTMLID($this->getTemplateHelper()->generateFormID($this) . "_{$product->ID}"); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|