|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\FoxyStripe\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\CountryDropdownField\Fields\CountryDropdownField; |
|
6
|
|
|
use Dynamic\FoxyStripe\Admin\FoxyStripeAdmin; |
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use SilverStripe\Control\Director; |
|
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
10
|
|
|
use SilverStripe\Forms\CheckboxField; |
|
11
|
|
|
use SilverStripe\Forms\DropdownField; |
|
12
|
|
|
use SilverStripe\Forms\FieldList; |
|
13
|
|
|
use SilverStripe\Forms\FormAction; |
|
14
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
15
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; |
|
16
|
|
|
use SilverStripe\Forms\HeaderField; |
|
17
|
|
|
use SilverStripe\Forms\HiddenField; |
|
18
|
|
|
use SilverStripe\Forms\LiteralField; |
|
19
|
|
|
use SilverStripe\Forms\NumericField; |
|
20
|
|
|
use SilverStripe\Forms\ReadonlyField; |
|
21
|
|
|
use SilverStripe\Forms\Tab; |
|
22
|
|
|
use SilverStripe\Forms\TabSet; |
|
23
|
|
|
use SilverStripe\Forms\TextField; |
|
24
|
|
|
use SilverStripe\ORM\DataObject; |
|
25
|
|
|
use SilverStripe\ORM\DB; |
|
26
|
|
|
use SilverStripe\ORM\ValidationException; |
|
27
|
|
|
use SilverStripe\Security\Permission; |
|
28
|
|
|
use SilverStripe\Security\PermissionProvider; |
|
29
|
|
|
use SilverStripe\Security\Security; |
|
30
|
|
|
use SilverStripe\View\TemplateGlobalProvider; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class FoxyStripeSetting |
|
34
|
|
|
* @package Dynamic\FoxyStripe\Model |
|
35
|
|
|
* |
|
36
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreTitle |
|
37
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreName |
|
38
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreURL |
|
39
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar ReceiptURL |
|
40
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreEmail |
|
41
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar FromEmail |
|
42
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StorePostalCode |
|
43
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreCountry |
|
44
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreRegion |
|
45
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreLocaleCode |
|
46
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreLogoURL |
|
47
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar CheckoutType |
|
48
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean BccEmail |
|
49
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean UseWebhook |
|
50
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreKey |
|
51
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean CartValidation |
|
52
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean UseSingleSignOn |
|
53
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean AllowMultiship |
|
54
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar StoreTimezone |
|
55
|
|
|
* @property \SilverStripe\ORM\FieldType\DBBoolean MultiGroup |
|
56
|
|
|
* @property \SilverStripe\ORM\FieldType\DBInt ProductLimit |
|
57
|
|
|
* @property \SilverStripe\ORM\FieldType\DBInt MaxQuantity |
|
58
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar client_id |
|
59
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar client_secret |
|
60
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar access_token |
|
61
|
|
|
* @property \SilverStripe\ORM\FieldType\DBVarchar refresh_token |
|
62
|
|
|
*/ |
|
63
|
|
|
class FoxyStripeSetting extends DataObject implements PermissionProvider, TemplateGlobalProvider |
|
64
|
|
|
{ |
|
65
|
|
|
/** |
|
66
|
|
|
* @var string |
|
67
|
|
|
*/ |
|
68
|
|
|
private static $singular_name = 'FoxyStripe Setting'; |
|
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var string |
|
71
|
|
|
*/ |
|
72
|
|
|
private static $plural_name = 'FoxyStripe Settings'; |
|
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
private static $description = 'Update the settings for your store'; |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var array |
|
80
|
|
|
*/ |
|
81
|
|
|
private static $db = [ |
|
|
|
|
|
|
82
|
|
|
'StoreTitle' => 'Varchar(255)', |
|
83
|
|
|
'StoreName' => 'Varchar(255)', |
|
84
|
|
|
'CustomSSL' => 'Boolean', |
|
85
|
|
|
'RemoteDomain' => 'Varchar(255)', |
|
86
|
|
|
'StoreURL' => 'Varchar(255)', |
|
87
|
|
|
'ReceiptURL' => 'Varchar(255)', |
|
88
|
|
|
'StoreEmail' => 'Varchar(255)', |
|
89
|
|
|
'FromEmail' => 'Varchar(255)', |
|
90
|
|
|
'StorePostalCode' => 'Varchar(10)', |
|
91
|
|
|
'StoreCountry' => 'Varchar(100)', |
|
92
|
|
|
'StoreRegion' => 'Varchar(100)', |
|
93
|
|
|
'StoreLocaleCode' => 'Varchar(10)', |
|
94
|
|
|
'StoreLogoURL' => 'Varchar(255)', |
|
95
|
|
|
'CheckoutType' => 'Varchar(50)', |
|
96
|
|
|
'BccEmail' => 'Boolean', |
|
97
|
|
|
'UseWebhook' => 'Boolean', |
|
98
|
|
|
'StoreKey' => 'Varchar(60)', |
|
99
|
|
|
'CartValidation' => 'Boolean', |
|
100
|
|
|
'UseSingleSignOn' => 'Boolean', |
|
101
|
|
|
'AllowMultiship' => 'Boolean', |
|
102
|
|
|
'StoreTimezone' => 'Varchar(100)', |
|
103
|
|
|
'MultiGroup' => 'Boolean', |
|
104
|
|
|
'ProductLimit' => 'Int', |
|
105
|
|
|
'MaxQuantity' => 'Int', |
|
106
|
|
|
'EnableAPI' => 'Boolean', |
|
107
|
|
|
'client_id' => 'Varchar(255)', |
|
108
|
|
|
'client_secret' => 'Varchar(255)', |
|
109
|
|
|
'access_token' => 'Varchar(255)', |
|
110
|
|
|
'refresh_token' => 'Varchar(255)', |
|
111
|
|
|
'EnableSidecart' => 'Boolean', |
|
112
|
|
|
]; |
|
113
|
|
|
|
|
114
|
|
|
// Set Default values |
|
115
|
|
|
private static $defaults = [ |
|
|
|
|
|
|
116
|
|
|
'ProductLimit' => 10, |
|
117
|
|
|
'EnableSidecart' => 1, |
|
118
|
|
|
]; |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @var string |
|
122
|
|
|
*/ |
|
123
|
|
|
private static $table_name = 'FoxyStripeSetting'; |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Default permission to check for 'LoggedInUsers' to create or edit pages. |
|
127
|
|
|
* |
|
128
|
|
|
* @var array |
|
129
|
|
|
* @config |
|
130
|
|
|
*/ |
|
131
|
|
|
private static $required_permission = ['CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain']; |
|
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return FieldList |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function getCMSFields() |
|
137
|
|
|
{ |
|
138
|
1 |
|
$fields = FieldList::create( |
|
139
|
1 |
|
TabSet::create( |
|
140
|
1 |
|
'Root', |
|
141
|
1 |
|
$tabMain = Tab::create( |
|
142
|
1 |
|
'Main' |
|
143
|
|
|
) |
|
144
|
|
|
), |
|
145
|
1 |
|
HiddenField::create('ID') |
|
146
|
|
|
); |
|
147
|
1 |
|
$tabMain->setTitle('Settings'); |
|
148
|
|
|
|
|
149
|
|
|
// settings tab |
|
150
|
1 |
|
$fields->addFieldsToTab('Root.Main', [ |
|
151
|
|
|
// Store Details |
|
152
|
1 |
|
HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), |
|
153
|
1 |
|
LiteralField::create('DetailsIntro', _t( |
|
154
|
1 |
|
'FoxyStripeSiteConfig.DetailsIntro', |
|
155
|
1 |
|
'<p>Maps to data in your |
|
156
|
|
|
<a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank"> |
|
157
|
|
|
FoxyCart store settings |
|
158
|
|
|
</a>.' |
|
159
|
|
|
)), |
|
160
|
1 |
|
TextField::create('StoreTitle') |
|
161
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name')) |
|
162
|
1 |
|
->setDescription(_t( |
|
163
|
1 |
|
'FoxyStripeSiteConfig.StoreTitleDescription', |
|
164
|
1 |
|
'The name of your store as you\'d like it displayed to your customers' |
|
165
|
|
|
)), |
|
166
|
1 |
|
CheckboxField::create('CustomSSL', 'Use custom SSL'), |
|
167
|
1 |
|
TextField::create('RemoteDomain') |
|
168
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.RemoteDomain', 'Store Remote Domain')) |
|
169
|
1 |
|
->setDescription(_t( |
|
170
|
1 |
|
'FoxyStripeSiteConfig.RemoteDomainDescription', |
|
171
|
1 |
|
'custom subdomain for FoxyCart' |
|
172
|
|
|
)) |
|
173
|
1 |
|
->displayIf('CustomSSL')->isChecked()->end(), |
|
174
|
1 |
|
TextField::create('StoreName') |
|
175
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain')) |
|
176
|
1 |
|
->setDescription(_t( |
|
177
|
1 |
|
'FoxyStripeSiteConfig.StoreNameDescription', |
|
178
|
1 |
|
'This is a unique FoxyCart subdomain for your cart, checkout, and receipt' |
|
179
|
|
|
)) |
|
180
|
1 |
|
->hideIf('CustomSSL')->isChecked()->end(), |
|
181
|
1 |
|
TextField::create('StoreURL') |
|
182
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL')) |
|
183
|
1 |
|
->setDescription(_t( |
|
184
|
1 |
|
'FoxyStripeSiteConfig.StoreURLDescription', |
|
185
|
1 |
|
'The URL of your online store' |
|
186
|
|
|
)), |
|
187
|
1 |
|
TextField::create('ReceiptURL') |
|
188
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL')) |
|
189
|
1 |
|
->setDescription(_t( |
|
190
|
1 |
|
'FoxyStripeSiteConfig.ReceiptURLDescription', |
|
191
|
1 |
|
'By default, FoxyCart sends customers back to the page referrer after completing a purchase. |
|
192
|
|
|
Instead, you can set a specific URL here.' |
|
193
|
|
|
)), |
|
194
|
1 |
|
TextField::create('StoreEmail') |
|
195
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email')) |
|
196
|
1 |
|
->setDescription(_t( |
|
197
|
1 |
|
'FoxyStripeSiteConfig.StoreEmailDescription', |
|
198
|
1 |
|
'This is the email address of your store. By default, this will be the from address for your |
|
199
|
|
|
store receipts. ' |
|
200
|
|
|
)), |
|
201
|
1 |
|
TextField::create('FromEmail') |
|
202
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email')) |
|
203
|
1 |
|
->setDescription(_t( |
|
204
|
1 |
|
'FoxyStripeSiteConfig.FromEmailDescription', |
|
205
|
1 |
|
'Used for when you want to specify a different from email than your store\'s email address' |
|
206
|
|
|
)), |
|
207
|
1 |
|
TextField::create('StorePostalCode', 'Postal Code'), |
|
208
|
1 |
|
CountryDropdownField::create('StoreCountry', 'Country'), |
|
209
|
1 |
|
TextField::create('StoreRegion', 'State/Region'), |
|
210
|
1 |
|
TextField::create('StoreLocaleCode', 'Locale Code') |
|
211
|
1 |
|
->setDescription('example: en_US'), |
|
212
|
1 |
|
TextField::create('StoreTimezone', 'Store timezone'), |
|
213
|
1 |
|
TextField::create('StoreLogoURL', 'Logo URL') |
|
214
|
1 |
|
->setAttribute('placeholder', 'http://'), |
|
215
|
|
|
]); |
|
216
|
|
|
|
|
217
|
1 |
|
$fields->addFieldsToTab('Root.Advanced', [ |
|
218
|
1 |
|
HeaderField::create('AdvanceHeader', _t( |
|
219
|
1 |
|
'FoxyStripeSiteConfig.AdvancedHeader', |
|
220
|
1 |
|
'Advanced Settings' |
|
221
|
1 |
|
), 3), |
|
222
|
1 |
|
LiteralField::create('AdvancedIntro', _t( |
|
223
|
1 |
|
'FoxyStripeSiteConfig.AdvancedIntro', |
|
224
|
1 |
|
'<p>Maps to data in your |
|
225
|
|
|
<a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank"> |
|
226
|
|
|
FoxyCart advanced store settings |
|
227
|
|
|
</a>.</p>' |
|
228
|
|
|
)), |
|
229
|
1 |
|
DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()), |
|
230
|
1 |
|
CheckboxField::create('BccEmail', 'BCC Admin Email') |
|
231
|
1 |
|
->setDescription('bcc all receipts to store\'s email address'), |
|
232
|
1 |
|
CheckboxField::create('UseWebhook', 'Use Webhook') |
|
233
|
1 |
|
->setDescription('record order history in CMS, allows customers to view their order history'), |
|
234
|
1 |
|
ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()), |
|
235
|
1 |
|
ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()), |
|
236
|
1 |
|
CheckboxField::create('CartValidation', 'Use cart validation'), |
|
237
|
1 |
|
CheckboxField::create('UseSingleSignOn', 'Use single sign on') |
|
238
|
1 |
|
->setDescription('Sync user accounts between FoxyCart and your website'), |
|
239
|
1 |
|
ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()), |
|
240
|
1 |
|
CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'), |
|
241
|
|
|
]); |
|
242
|
|
|
|
|
243
|
|
|
// configuration warning |
|
244
|
1 |
|
if (FoxyCart::store_name_warning() !== null) { |
|
245
|
|
|
$fields->insertBefore(LiteralField::create( |
|
246
|
|
|
'StoreSubDomainHeaderWarning', |
|
247
|
|
|
_t( |
|
248
|
|
|
'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', |
|
249
|
|
|
'<p class="message error">Store Domain must be entered below |
|
250
|
|
|
</a></p>' |
|
251
|
|
|
) |
|
252
|
|
|
), 'StoreDetails'); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
// products tab |
|
256
|
1 |
|
$fields->addFieldsToTab('Root.Products', [ |
|
257
|
1 |
|
HeaderField::create('ProductHeader', _t( |
|
258
|
1 |
|
'FoxyStripeSiteConfig.ProductHeader', |
|
259
|
1 |
|
'Products' |
|
260
|
1 |
|
), 3), |
|
261
|
1 |
|
CheckboxField::create('MultiGroup') |
|
262
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups')) |
|
263
|
1 |
|
->setDescription(_t( |
|
264
|
1 |
|
'FoxyStripeSiteConfig.MultiGroupDescription', |
|
265
|
1 |
|
'Allows products to be shown in multiple Product Groups' |
|
266
|
|
|
)), |
|
267
|
1 |
|
HeaderField::create('ProductGroupHD', _t( |
|
268
|
1 |
|
'FoxyStripeSiteConfig.ProductGroupHD', |
|
269
|
1 |
|
'Product Groups' |
|
270
|
1 |
|
), 3), |
|
271
|
1 |
|
NumericField::create('ProductLimit') |
|
272
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page')) |
|
273
|
1 |
|
->setDescription(_t( |
|
274
|
1 |
|
'FoxyStripeSiteConfig.ProductLimitDescription', |
|
275
|
1 |
|
'Number of Products to show per page on a Product Group' |
|
276
|
|
|
)), |
|
277
|
1 |
|
HeaderField::create('ProductQuantityHD', _t( |
|
278
|
1 |
|
'FoxyStripeSiteConfig.ProductQuantityHD', |
|
279
|
1 |
|
'Product Form Max Quantity' |
|
280
|
1 |
|
), 3), |
|
281
|
1 |
|
NumericField::create('MaxQuantity') |
|
282
|
1 |
|
->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity')) |
|
283
|
1 |
|
->setDescription(_t( |
|
284
|
1 |
|
'FoxyStripeSiteConfig.MaxQuantityDescription', |
|
285
|
1 |
|
'Sets max quantity for product form dropdown (add to cart form - default 10)' |
|
286
|
|
|
)), |
|
287
|
|
|
]); |
|
288
|
|
|
|
|
289
|
|
|
// categories tab |
|
290
|
1 |
|
$fields->addFieldsToTab('Root.Categories', [ |
|
291
|
1 |
|
HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), |
|
292
|
1 |
|
LiteralField::create('CategoryDescrip', _t( |
|
293
|
1 |
|
'FoxyStripeSiteConfig.CategoryDescrip', |
|
294
|
1 |
|
'<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be |
|
295
|
|
|
accomplished by product options alone, including category specific coupon codes, |
|
296
|
|
|
shipping and handling fees, and email receipts. |
|
297
|
|
|
<a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank"> |
|
298
|
|
|
Learn More |
|
299
|
|
|
</a></p> |
|
300
|
|
|
<p>Categories you\'ve created in FoxyStripe must also be created in your |
|
301
|
|
|
<a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" |
|
302
|
|
|
target="_blank">FoxyCart Categories</a> admin panel.</p>' |
|
303
|
|
|
)), |
|
304
|
1 |
|
GridField::create( |
|
305
|
1 |
|
'ProductCategory', |
|
306
|
1 |
|
_t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), |
|
307
|
1 |
|
ProductCategory::get(), |
|
308
|
1 |
|
GridFieldConfig_RecordEditor::create() |
|
309
|
|
|
), |
|
310
|
|
|
]); |
|
311
|
|
|
|
|
312
|
|
|
// option groups tab |
|
313
|
1 |
|
$fields->addFieldsToTab('Root.Groups', [ |
|
314
|
1 |
|
HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), |
|
315
|
1 |
|
LiteralField::create('OptionGroupsDescrip', _t( |
|
316
|
1 |
|
'FoxyStripeSiteConfig.OptionGroupsDescrip', |
|
317
|
1 |
|
'<p>Product Option Groups allow you to name a set of product options.</p>' |
|
318
|
|
|
)), |
|
319
|
1 |
|
GridField::create( |
|
320
|
1 |
|
'OptionGroup', |
|
321
|
1 |
|
_t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), |
|
322
|
1 |
|
OptionGroup::get(), |
|
323
|
1 |
|
GridFieldConfig_RecordEditor::create() |
|
324
|
|
|
), |
|
325
|
|
|
]); |
|
326
|
|
|
|
|
327
|
|
|
// api tab |
|
328
|
1 |
|
if (Permission::check('ADMIN')) { |
|
329
|
1 |
|
$fields->addFieldsToTab('Root.API', [ |
|
330
|
1 |
|
HeaderField::create('APIHD', 'FoxyCart API Settings', 3), |
|
331
|
1 |
|
CheckboxField::create('EnableAPI', 'Enable FoxyCart API'), |
|
332
|
1 |
|
TextField::create('client_id', 'FoxyCart Client ID'), |
|
333
|
1 |
|
TextField::create('client_secret', 'FoxyCart Client Secret'), |
|
334
|
1 |
|
TextField::create('access_token', 'FoxyCart Access Token'), |
|
335
|
1 |
|
TextField::create('refresh_token', 'FoxyCart Refresh Token'), |
|
336
|
|
|
]); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
1 |
|
$fields->addFieldsToTab('Root.Template', [ |
|
340
|
1 |
|
HeaderField::create('TemplateHD', _t('FoxyStripeSiteConfig.TemplateHD', 'Template Options'), 3), |
|
341
|
1 |
|
CheckboxField::create('EnableSidecart') |
|
342
|
1 |
|
->setDescription('Turns on the Sidebar cart. Uncheck to use the full page cart.'), |
|
343
|
|
|
]); |
|
344
|
|
|
|
|
345
|
1 |
|
$this->extend('updateCMSFields', $fields); |
|
346
|
|
|
|
|
347
|
1 |
|
return $fields; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* @return FieldList |
|
352
|
|
|
*/ |
|
353
|
|
|
public function getCMSActions() |
|
354
|
|
|
{ |
|
355
|
|
|
if (Permission::check('ADMIN') || Permission::check('EDIT_FOXYSTRIPE_SETTING')) { |
|
356
|
|
|
$actions = new FieldList( |
|
357
|
|
|
FormAction::create('save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save')) |
|
358
|
|
|
->addExtraClass('btn-primary font-icon-save') |
|
359
|
|
|
); |
|
360
|
|
|
} else { |
|
361
|
|
|
$actions = FieldList::create(); |
|
362
|
|
|
} |
|
363
|
|
|
$this->extend('updateCMSActions', $actions); |
|
364
|
|
|
|
|
365
|
|
|
return $actions; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
|
370
|
|
|
*/ |
|
371
|
3 |
|
public function requireDefaultRecords() |
|
372
|
|
|
{ |
|
373
|
3 |
|
parent::requireDefaultRecords(); |
|
374
|
3 |
|
$config = self::current_foxystripe_setting(); |
|
375
|
|
|
|
|
376
|
3 |
|
if (!$config) { |
|
|
|
|
|
|
377
|
|
|
self::make_foxystripe_setting(); |
|
378
|
|
|
DB::alteration_message('Added default FoxyStripe Setting', 'created'); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
3 |
|
if (!$config->StoreKey) { |
|
382
|
3 |
|
$key = FoxyCart::setStoreKey(); |
|
383
|
3 |
|
while (!ctype_alnum($key)) { |
|
384
|
|
|
$key = FoxyCart::setStoreKey(); |
|
385
|
|
|
} |
|
386
|
3 |
|
$config->StoreKey = $key; |
|
|
|
|
|
|
387
|
3 |
|
$config->write(); |
|
388
|
3 |
|
DB::alteration_message('Created FoxyCart Store Key ' . $key, 'created'); |
|
389
|
|
|
} |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* @return string |
|
394
|
|
|
*/ |
|
395
|
|
|
public function CMSEditLink() |
|
396
|
|
|
{ |
|
397
|
|
|
return FoxyStripeAdmin::singleton()->Link(); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* @param null $member |
|
|
|
|
|
|
402
|
|
|
* |
|
403
|
|
|
* @return bool|int|null |
|
404
|
|
|
*/ |
|
405
|
|
|
public function canEdit($member = null) |
|
406
|
|
|
{ |
|
407
|
|
|
if (!$member) { |
|
|
|
|
|
|
408
|
|
|
$member = Security::getCurrentUser(); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
$extended = $this->extendedCan('canEdit', $member); |
|
412
|
|
|
if ($extended !== null) { |
|
413
|
|
|
return $extended; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
return Permission::checkMember($member, 'EDIT_FOXYSTRIPE_SETTING'); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* @return array |
|
421
|
|
|
*/ |
|
422
|
|
|
public function providePermissions() |
|
423
|
|
|
{ |
|
424
|
|
|
return [ |
|
425
|
|
|
'EDIT_FOXYSTRIPE_SETTING' => [ |
|
426
|
|
|
'name' => _t( |
|
427
|
|
|
'FoxyStripeSetting.EDIT_FOXYSTRIPE_SETTING', |
|
428
|
|
|
'Manage FoxyStripe settings' |
|
429
|
|
|
), |
|
430
|
|
|
'category' => _t( |
|
431
|
|
|
'Permissions.PERMISSIONS_FOXYSTRIPE_SETTING', |
|
432
|
|
|
'FoxyStripe' |
|
433
|
|
|
), |
|
434
|
|
|
'help' => _t( |
|
435
|
|
|
'FoxyStripeSetting.EDIT_PERMISSION_FOXYSTRIPE_SETTING', |
|
436
|
|
|
'Ability to edit the settings of a FoxyStripe Store.' |
|
437
|
|
|
), |
|
438
|
|
|
'sort' => 400, |
|
439
|
|
|
], |
|
440
|
|
|
]; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Get the current sites {@link GlobalSiteSetting}, and creates a new one |
|
445
|
|
|
* through {@link make_global_config()} if none is found. |
|
446
|
|
|
* |
|
447
|
|
|
* @return FoxyStripeSetting|DataObject |
|
448
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
|
449
|
|
|
*/ |
|
450
|
49 |
|
public static function current_foxystripe_setting() |
|
451
|
|
|
{ |
|
452
|
49 |
|
if ($config = self::get()->first()) { |
|
453
|
49 |
|
return $config; |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
9 |
|
return self::make_foxystripe_setting(); |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* Create {@link GlobalSiteSetting} with defaults from language file. |
|
461
|
|
|
* |
|
462
|
|
|
* @return static |
|
463
|
|
|
*/ |
|
464
|
9 |
|
public static function make_foxystripe_setting() |
|
465
|
|
|
{ |
|
466
|
9 |
|
$config = self::create(); |
|
467
|
|
|
try { |
|
468
|
9 |
|
$config->write(); |
|
469
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
|
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
9 |
|
return $config; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* Add $GlobalConfig to all SSViewers. |
|
477
|
|
|
*/ |
|
478
|
|
|
public static function get_template_global_variables() |
|
479
|
|
|
{ |
|
480
|
|
|
return [ |
|
481
|
|
|
'FoxyStripe' => 'current_foxystripe_setting', |
|
482
|
|
|
]; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
/** |
|
486
|
|
|
* @return string |
|
487
|
|
|
*/ |
|
488
|
2 |
|
private static function getSSOLink() |
|
489
|
|
|
{ |
|
490
|
2 |
|
return Director::absoluteBaseURL() . 'foxystripe/sso/'; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
/** |
|
494
|
|
|
* @return string |
|
495
|
|
|
*/ |
|
496
|
2 |
|
private static function getDataFeedLink() |
|
497
|
|
|
{ |
|
498
|
2 |
|
return Director::absoluteBaseURL() . 'foxystripe/'; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* @return array |
|
503
|
|
|
*/ |
|
504
|
1 |
|
public function getCheckoutTypes() |
|
505
|
|
|
{ |
|
506
|
|
|
return [ |
|
507
|
1 |
|
'default_account' => 'Allow guest and customer accounts, default to account', |
|
508
|
|
|
'default_guest' => 'Allow guest and customer accounts, default to guest', |
|
509
|
|
|
'account_only' => 'Allow customer accounts only', |
|
510
|
|
|
'guest_only' => 'Allow guests only', |
|
511
|
|
|
]; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* @return array |
|
516
|
|
|
*/ |
|
517
|
1 |
|
public function getDataMap() |
|
518
|
|
|
{ |
|
519
|
|
|
return [ |
|
520
|
1 |
|
'store_name' => $this->StoreTitle, |
|
521
|
1 |
|
'store_domain' => $this->StoreName, |
|
522
|
1 |
|
'store_url' => $this->StoreURL, |
|
523
|
1 |
|
'receipt_continue_url' => $this->ReceiptURL, |
|
524
|
1 |
|
'store_email' => $this->StoreEmail, |
|
525
|
1 |
|
'from_email' => $this->FromEmail, |
|
526
|
1 |
|
'postal_code' => $this->StorePostalCode, |
|
527
|
1 |
|
'country' => $this->StoreCountry, |
|
528
|
1 |
|
'region' => $this->StoreRegion, |
|
529
|
1 |
|
'locale_code' => $this->StoreLocaleCode, |
|
530
|
1 |
|
'logo_url' => $this->StoreLogoURL, |
|
531
|
1 |
|
'checkout_type' => $this->CheckoutType, |
|
532
|
1 |
|
'bcc_on_receipt_email' => $this->BccEmail, |
|
533
|
1 |
|
'use_webhook' => $this->UseWebhook, |
|
534
|
1 |
|
'webhook_url' => $this->getDataFeedLink(), |
|
535
|
1 |
|
'webhook_key' => $this->StoreKey, |
|
536
|
1 |
|
'use_cart_validation' => $this->CartValidation, |
|
537
|
1 |
|
'use_single_sign_on' => $this->UseSingleSignOn, |
|
538
|
1 |
|
'single_sign_on_url' => $this->getSSOLink(), |
|
539
|
1 |
|
'customer_password_hash_type' => 'sha1_salted_suffix', |
|
540
|
1 |
|
'customer_password_hash_config' => 40, |
|
541
|
1 |
|
'features_multiship' => $this->AllowMultiship, |
|
542
|
|
|
//'timezone' => $this->StoreTimezone, |
|
543
|
|
|
]; |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
/** |
|
547
|
|
|
* if StoreTitle is empty, grab values from FoxyCart. |
|
548
|
|
|
* |
|
549
|
|
|
* example of 2 way sync for future reference |
|
550
|
|
|
* |
|
551
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
|
552
|
|
|
*/ |
|
553
|
11 |
|
public function onBeforeWrite() |
|
554
|
|
|
{ |
|
555
|
11 |
|
parent::onBeforeWrite(); |
|
556
|
|
|
|
|
557
|
11 |
|
if ($this->ID && !$this->StoreTitle && $this->access_token) { |
|
558
|
|
|
/* |
|
559
|
|
|
if ($fc = new FoxyStripeClient()) { |
|
560
|
|
|
$client = $fc->getClient(); |
|
561
|
|
|
$errors = []; |
|
562
|
|
|
|
|
563
|
|
|
$result = $client->get($fc->getCurrentStore()); |
|
564
|
|
|
$this->owner->StoreTitle = $result['store_name']; |
|
565
|
|
|
|
|
566
|
|
|
$errors = array_merge($errors, $client->getErrors($result)); |
|
567
|
|
|
if (count($errors)) { |
|
568
|
|
|
Injector::inst()->get(LoggerInterface::class) |
|
569
|
|
|
->error('FoxyStripeSiteConfig::onBeforeWrite errors - ' . json_encode($errors)); |
|
570
|
|
|
} |
|
571
|
|
|
} |
|
572
|
|
|
*/ |
|
573
|
|
|
} |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
/** |
|
577
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
|
578
|
|
|
*/ |
|
579
|
11 |
|
public function onAfterWrite() |
|
580
|
|
|
{ |
|
581
|
11 |
|
parent::onAfterWrite(); |
|
582
|
|
|
|
|
583
|
11 |
|
if (FoxyStripeClient::is_valid() && $this->isChanged()) { |
|
584
|
|
|
if ($fc = new FoxyStripeClient()) { |
|
585
|
|
|
$fc->updateStore($this->getDataMap()); |
|
586
|
|
|
} |
|
587
|
|
|
} |
|
588
|
|
|
} |
|
589
|
|
|
} |
|
590
|
|
|
|