1 <?php
2
3 4 5 6 7 8
9 class SimpleOrderButton extends ViewableData implements OrderButtonInterface {
10
11 private $product = 0;
12
13 function __construct($product) {
14 parent::__construct();
15 $this->product = $product;
16 }
17
18 19 20 21 22 23 24
25 public function Show($withNum = false) {
26 $fields = new FieldSet();
27 $fields->push(new HiddenField('itemId', '', $this->product));
28 if ($withNum) {
29 $fields->push($f = new NumericField('Num', '', 1));
30 $f->addExtraClass('OrderNumField');
31 $f->addExtraClass('AddProductNum');
32 $f->addExtraAttribute('title', _t('SimpleOrderButton.OrderNum', 'Product count to add...'));
33 }
34 $actions = new FieldSet($a = new FormAction("checkout", _t('SimpleOrderButton.AddToCart', 'Checkout')));
35 $a->addExtraClass('AddProductAction');
36
37 $form = new Form(SimpleOrderPage_Controller::get_instance(), "checkout", $fields, $actions);
38
39 $form->setTemplate('SimpleOrderButton');
40 $form->setHTMLID('AddProductForm_'. $this->product);
41 $form->addExtraClass('AddProductForm');
42 $form->getValidator()->setJavascriptValidationHandler('none');
43 $form->disableSecurityToken();
44 $form->setFormMethod('GET');
45 return $form;
46 }
47
48 49 50 51 52
53 public function One() {
54 return $this->Show();
55 }
56
57 58 59 60 61
62 public function WithNum() {
63 return $this->Show(true);
64 }
65
66 67 68 69 70
71 public function forTemplate() {
72 return $this->One()->forTemplate();
73 }
74 }
75
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-