1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Model; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Configurable; |
6
|
|
|
use SilverStripe\Core\Extensible; |
7
|
|
|
use SilverStripe\Core\Injector\Injectable; |
8
|
|
|
|
9
|
|
|
class FoxyHelper extends \FoxyCart_Helper |
10
|
|
|
{ |
11
|
|
|
use Configurable; |
12
|
|
|
use Injectable; |
13
|
|
|
use Extensible; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var |
17
|
|
|
*/ |
18
|
|
|
private static $secret; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var |
22
|
|
|
*/ |
23
|
|
|
protected static $cart_url; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var |
27
|
|
|
*/ |
28
|
|
|
private static $custom_ssl; |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var |
32
|
|
|
*/ |
33
|
|
|
private static $max_quantity = 10; |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var |
37
|
|
|
*/ |
38
|
|
|
private $foxy_secret; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var |
42
|
|
|
*/ |
43
|
|
|
private $foxy_cart_url; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var |
47
|
|
|
*/ |
48
|
|
|
private $foxy_custom_ssl; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var |
52
|
|
|
*/ |
53
|
|
|
private $foxy_max_quantity; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
public function getStoreSecret() |
59
|
|
|
{ |
60
|
|
|
if (!$this->foxy_secret) { |
61
|
|
|
$this->setStoreSecret(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->foxy_secret; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function setStoreSecret() |
71
|
|
|
{ |
72
|
|
|
$this->foxy_secret = $this->config()->get('secret'); |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
|
|
public function getStoreCartURL() |
81
|
|
|
{ |
82
|
|
|
if (!$this->foxy_cart_url) { |
83
|
|
|
$this->setStoreCartURL(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this->foxy_cart_url; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
|
|
public function setStoreCartURL() |
93
|
|
|
{ |
94
|
|
|
$this->foxy_cart_url = $this->config()->get('cart_url'); |
95
|
|
|
|
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function getCustomSSL() |
103
|
|
|
{ |
104
|
|
|
if (!$this->foxy_custom_ssl) { |
105
|
|
|
$this->setCustomSSL(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $this->foxy_custom_ssl; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setCustomSSL() |
115
|
|
|
{ |
116
|
|
|
$this->foxy_custom_ssl = $this->config()->get('custom_ssl'); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return mixed |
123
|
|
|
*/ |
124
|
|
|
public function getMaxQuantity() |
125
|
|
|
{ |
126
|
|
|
if (!$this->foxy_max_quantity) { |
127
|
|
|
$this->setMaxQuantity(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->foxy_max_quantity; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
|
|
public function setMaxQuantity() |
137
|
|
|
{ |
138
|
|
|
$this->foxy_max_quantity = $this->config()->get('max_quantity'); |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* FoxyHelper constructor. |
145
|
|
|
* |
146
|
|
|
* Set the private statics $secret and $cart_url in FoxyCart_Helper |
147
|
|
|
* |
148
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
149
|
|
|
*/ |
150
|
|
|
public function __construct() |
151
|
|
|
{ |
152
|
|
|
self::setCartURL($this->getStoreCartURL()); |
153
|
|
|
self::setSecret($this->getStoreSecret()); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public static function StoreURL() |
160
|
|
|
{ |
161
|
|
|
$helper = FoxyHelper::create(); |
162
|
|
|
if ($helper->getCustomSSL()) { |
163
|
|
|
return sprintf('https://%s/', $helper->getStoreCartURL()); |
164
|
|
|
} else { |
165
|
|
|
return sprintf('https://%s.foxycart.com/', $helper->getStoreCartURL()); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return string |
171
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
172
|
|
|
*/ |
173
|
|
|
public static function FormActionURL() |
174
|
|
|
{ |
175
|
|
|
return self::StoreURL() . 'cart'; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|