1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverShop\Checkout\Step; |
4
|
|
|
|
5
|
|
|
use SilverShop\Cart\ShoppingCart; |
6
|
|
|
use SilverShop\Checkout\CheckoutComponentConfig; |
7
|
|
|
use SilverShop\Checkout\Component\CustomerDetails; |
8
|
|
|
use SilverShop\Forms\CheckoutForm; |
9
|
|
|
use SilverStripe\Control\Controller; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\Forms\FormAction; |
12
|
|
|
use SilverStripe\Security\Security; |
13
|
|
|
|
14
|
|
|
class ContactDetails extends CheckoutStep |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Whether or not this step should be skipped if user is logged in |
18
|
|
|
* |
19
|
|
|
* @config |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
private static $skip_if_logged_in = false; |
23
|
|
|
|
24
|
|
|
private static $allowed_actions = [ |
|
|
|
|
25
|
|
|
'contactdetails', |
26
|
|
|
'ContactDetailsForm', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
public function contactdetails() |
30
|
|
|
{ |
31
|
|
|
$form = $this->ContactDetailsForm(); |
32
|
|
|
if (ShoppingCart::curr() |
33
|
|
|
&& self::config()->skip_if_logged_in |
34
|
|
|
) { |
35
|
|
|
if (Security::getCurrentUser()) { |
36
|
|
|
if ($form->getValidator()->validate()) { |
37
|
|
|
return Controller::curr()->redirect($this->NextStepLink()); |
38
|
|
|
} else { |
39
|
|
|
$form->clearMessage(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return [ |
45
|
|
|
'OrderForm' => $form, |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function ContactDetailsForm() |
50
|
|
|
{ |
51
|
|
|
$cart = ShoppingCart::curr(); |
52
|
|
|
if (!$cart) { |
|
|
|
|
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
$config = CheckoutComponentConfig::create(ShoppingCart::curr()); |
56
|
|
|
$config->addComponent(CustomerDetails::create()); |
57
|
|
|
$form = CheckoutForm::create($this->owner, 'ContactDetailsForm', $config); |
58
|
|
|
$form->setRedirectLink($this->NextStepLink()); |
59
|
|
|
$form->setActions( |
60
|
|
|
FieldList::create( |
61
|
|
|
FormAction::create('checkoutSubmit', _t('SilverShop\Checkout\Step\CheckoutStep.Continue', 'Continue')) |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
$this->owner->extend('updateContactDetailsForm', $form); |
65
|
|
|
|
66
|
|
|
return $form; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|