CheckoutStep_ShippingMethod   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 9
dl 0
loc 67
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shippingmethod() 0 11 2
B ShippingMethodForm() 0 32 2
A setShippingMethod() 0 14 3
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(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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