1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\Postage\Tests\Control; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\TestOnly; |
6
|
|
|
use SilverStripe\Control\Director; |
7
|
|
|
use SilverStripe\Forms\HiddenField; |
8
|
|
|
use SilverStripe\Control\Controller; |
9
|
|
|
use SilverCommerce\Postage\Forms\PostageForm; |
10
|
|
|
use SilverCommerce\Postage\Tests\Model\ExtendableObject; |
11
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Controller used for testing form submissions |
15
|
|
|
*/ |
16
|
|
|
class PostageController extends Controller implements TestOnly |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
private static $url_segment = 'postagetest'; |
20
|
|
|
|
21
|
|
|
private static $allowed_actions = [ |
|
|
|
|
22
|
|
|
'index', |
23
|
|
|
'complete', |
24
|
|
|
'PostageForm' |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
public function getObject() |
28
|
|
|
{ |
29
|
|
|
$session = $this->getRequest()->getSession(); |
30
|
|
|
$id = $session->get("ObjectID"); |
31
|
|
|
return ExtendableObject::get()->byID($id); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function Link($action = null) |
35
|
|
|
{ |
36
|
|
|
return Controller::join_links( |
37
|
|
|
$this->config()->url_segment, |
38
|
|
|
$action |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function AbsoluteLink($action = null) |
43
|
|
|
{ |
44
|
|
|
return Director::absoluteURL($this->Link($action)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function RelativeLink($action = null) |
48
|
|
|
{ |
49
|
|
|
return Controller::join_links( |
50
|
|
|
$this->Link($action) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function index() |
55
|
|
|
{ |
56
|
|
|
$id = $this->getRequest()->param("ID"); |
57
|
|
|
$object = ExtendableObject::get()->byID($id); |
|
|
|
|
58
|
|
|
$session = $this->getRequest()->getSession(); |
59
|
|
|
$session->set("ObjectID", $object->ID); |
60
|
|
|
|
61
|
|
|
$html = '<p class="postage-key">'; |
62
|
|
|
$html .= $object->getPostage()->getKey(); |
63
|
|
|
$html .= '</p>'; |
64
|
|
|
$content = DBHTMLText::create(); |
65
|
|
|
$content->setValue($html); |
66
|
|
|
|
67
|
|
|
$this->customise([ |
68
|
|
|
"Content" => $content |
69
|
|
|
]); |
70
|
|
|
|
71
|
|
|
return $this->render(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function complete() |
75
|
|
|
{ |
76
|
|
|
$this->customise([ |
77
|
|
|
"Content" => '<p class="message">form submitted</p>' |
78
|
|
|
]); |
79
|
|
|
|
80
|
|
|
return $this->render(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function PostageForm() |
84
|
|
|
{ |
85
|
|
|
$object = $this->getObject(); |
86
|
|
|
|
87
|
|
|
$form = PostageForm::create( |
88
|
|
|
$this, |
|
|
|
|
89
|
|
|
"PostageForm", |
|
|
|
|
90
|
|
|
$object, |
|
|
|
|
91
|
|
|
$object->SubTotal, |
92
|
|
|
$object->TotalWeight, |
93
|
|
|
$object->TotalItems, |
94
|
|
|
$object->DeliveryCountry, |
95
|
|
|
$object->DeliveryCounty |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
return $form; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|