|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Gives methods to ship by, based on previously given address and order items. |
|
4
|
|
|
* |
|
5
|
|
|
* @package silvershop-shipping |
|
6
|
|
|
*/ |
|
7
|
|
|
class CheckoutStep_ShippingMethod extends CheckoutStep |
|
8
|
|
|
{ |
|
9
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
10
|
|
|
'shippingmethod', |
|
11
|
|
|
'ShippingMethodForm' |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
public function shippingmethod() |
|
15
|
|
|
{ |
|
16
|
|
|
$form = $this->ShippingMethodForm(); |
|
17
|
|
|
$cart = ShoppingCart::singleton()->current(); |
|
18
|
|
|
if ($cart->ShippingMethodID) { |
|
19
|
|
|
$form->loadDataFrom($cart); |
|
20
|
|
|
} |
|
21
|
|
|
return array( |
|
22
|
|
|
'OrderForm' => $form |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function ShippingMethodForm() |
|
27
|
|
|
{ |
|
28
|
|
|
$order = $this->owner->Cart(); |
|
29
|
|
|
$estimates = $order->getShippingEstimates(); |
|
30
|
|
|
$fields = new FieldList(); |
|
31
|
|
|
if ($estimates->exists()) { |
|
32
|
|
|
$fields->push( |
|
33
|
|
|
OptionsetField::create( |
|
34
|
|
|
"ShippingMethodID", |
|
35
|
|
|
_t('CheckoutStep_ShippingMethod.ShippingOptions', 'Shipping Options'), |
|
36
|
|
|
$estimates->map(), |
|
37
|
|
|
$estimates->First()->ID |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
} else { |
|
41
|
|
|
$fields->push( |
|
42
|
|
|
LiteralField::create( |
|
43
|
|
|
"NoShippingMethods", |
|
44
|
|
|
_t('CheckoutStep_ShippingMethod.NoShippingMethods', |
|
45
|
|
|
'<p class=\"message warning\">There are no shipping methods available</p>' |
|
46
|
|
|
) |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
$actions = new FieldList( |
|
51
|
|
|
|
|
52
|
|
|
new FormAction("setShippingMethod", _t('CheckoutStep.Continue', 'Continue')) |
|
53
|
|
|
); |
|
54
|
|
|
$form = new Form($this->owner, "ShippingMethodForm", $fields, $actions); |
|
55
|
|
|
$this->owner->extend('updateShippingMethodForm', $form); |
|
56
|
|
|
return $form; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setShippingMethod($data, $form) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$order = $this->owner->Cart(); |
|
62
|
|
|
$option = null; |
|
63
|
|
|
if (isset($data['ShippingMethodID'])) { |
|
64
|
|
|
$option = ShippingMethod::get() |
|
65
|
|
|
->byID((int)$data['ShippingMethodID']); |
|
66
|
|
|
} |
|
67
|
|
|
//assign option to order / modifier |
|
68
|
|
|
if ($option) { |
|
69
|
|
|
$order->setShippingMethod($option); |
|
70
|
|
|
} |
|
71
|
|
|
$this->owner->redirect($this->NextStepLink()); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|