Passed
Push — master ( 5a6133...83a442 )
by Jason
03:06
created

FoxyStripeSetting   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 512
Duplicated Lines 0 %

Test Coverage

Coverage 81.66%

Importance

Changes 0
Metric Value
wmc 32
eloc 275
dl 0
loc 512
ccs 187
cts 229
cp 0.8166
rs 9.84
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getSSOLink() 0 3 1
A onAfterWrite() 0 7 4
A providePermissions() 0 17 1
A canEdit() 0 12 3
A getDataFeedLink() 0 3 1
A getDataMap() 0 25 1
A requireDefaultRecords() 0 18 4
A getCheckoutTypes() 0 7 1
A current_foxystripe_setting() 0 7 2
A getCMSActions() 0 13 3
B getCMSFields() 0 203 3
A CMSEditLink() 0 3 1
A make_foxystripe_setting() 0 9 2
A get_template_global_variables() 0 4 1
A onBeforeWrite() 0 5 4
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';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
69
    /**
70
     * @var string
71
     */
72
    private static $plural_name = 'FoxyStripe Settings';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
73
    /**
74
     * @var string
75
     */
76
    private static $description = 'Update the settings for your store';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
77
78
    /**
79
     * @var array
80
     */
81
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
82
        'StoreTitle' => 'Varchar(255)',
83
        'StoreName' => 'Varchar(255)',
84
        'StoreURL' => 'Varchar(255)',
85
        'ReceiptURL' => 'Varchar(255)',
86
        'StoreEmail' => 'Varchar(255)',
87
        'FromEmail' => 'Varchar(255)',
88
        'StorePostalCode' => 'Varchar(10)',
89
        'StoreCountry' => 'Varchar(100)',
90
        'StoreRegion' => 'Varchar(100)',
91
        'StoreLocaleCode' => 'Varchar(10)',
92
        'StoreLogoURL' => 'Varchar(255)',
93
        'CheckoutType' => 'Varchar(50)',
94
        'BccEmail' => 'Boolean',
95
        'UseWebhook' => 'Boolean',
96
        'StoreKey' => 'Varchar(60)',
97
        'CartValidation' => 'Boolean',
98
        'UseSingleSignOn' => 'Boolean',
99
        'AllowMultiship' => 'Boolean',
100
        'StoreTimezone' => 'Varchar(100)',
101
        'MultiGroup' => 'Boolean',
102
        'ProductLimit' => 'Int',
103
        'MaxQuantity' => 'Int',
104
        'EnableAPI' => 'Boolean',
105
        'client_id' => 'Varchar(255)',
106
        'client_secret' => 'Varchar(255)',
107
        'access_token' => 'Varchar(255)',
108
        'refresh_token' => 'Varchar(255)',
109
        'EnableSidecart' => 'Boolean',
110
    ];
111
112
    // Set Default values
113
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
114
        'ProductLimit' => 10,
115
        'EnableSidecart' => 1,
116
    ];
117
118
    /**
119
     * @var string
120
     */
121
    private static $table_name = 'FoxyStripeSetting';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
122
123
    /**
124
     * Default permission to check for 'LoggedInUsers' to create or edit pages.
125
     *
126
     * @var array
127
     * @config
128
     */
129
    private static $required_permission = ['CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'];
0 ignored issues
show
introduced by
The private property $required_permission is not used, and could be removed.
Loading history...
130
131
    /**
132
     * @return FieldList
133
     */
134 1
    public function getCMSFields()
135
    {
136 1
        $fields = FieldList::create(
137 1
            TabSet::create(
138 1
                'Root',
139 1
                $tabMain = Tab::create(
140 1
                    'Main'
141
                )
142
            ),
143 1
            HiddenField::create('ID')
144
        );
145 1
        $tabMain->setTitle('Settings');
146
147
        // settings tab
148 1
        $fields->addFieldsToTab('Root.Main', [
149
            // Store Details
150 1
            HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3),
151 1
            LiteralField::create('DetailsIntro', _t(
152 1
                'FoxyStripeSiteConfig.DetailsIntro',
153 1
                '<p>Maps to data in your 
154
                        <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">
155
                            FoxyCart store settings
156
                        </a>.'
157
            )),
158 1
            TextField::create('StoreTitle')
159 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name'))
160 1
                ->setDescription(_t(
161 1
                    'FoxyStripeSiteConfig.StoreTitleDescription',
162 1
                    'The name of your store as you\'d like it displayed to your customers'
163
                )),
164 1
            TextField::create('StoreName')
165 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain'))
166 1
                ->setDescription(_t(
167 1
                    'FoxyStripeSiteConfig.StoreNameDescription',
168 1
                    'This is a unique FoxyCart subdomain for your cart, checkout, and receipt'
169
                )),
170 1
            TextField::create('StoreURL')
171 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL'))
172 1
                ->setDescription(_t(
173 1
                    'FoxyStripeSiteConfig.StoreURLDescription',
174 1
                    'The URL of your online store'
175
                )),
176 1
            TextField::create('ReceiptURL')
177 1
                ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL'))
178 1
                ->setDescription(_t(
179 1
                    'FoxyStripeSiteConfig.ReceiptURLDescription',
180 1
                    'By default, FoxyCart sends customers back to the page referrer after completing a purchase. 
181
                            Instead, you can set a specific URL here.'
182
                )),
183 1
            TextField::create('StoreEmail')
184 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email'))
185 1
                ->setDescription(_t(
186 1
                    'FoxyStripeSiteConfig.StoreEmailDescription',
187 1
                    'This is the email address of your store. By default, this will be the from address for your 
188
                            store receipts. '
189
                )),
190 1
            TextField::create('FromEmail')
191 1
                ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email'))
192 1
                ->setDescription(_t(
193 1
                    'FoxyStripeSiteConfig.FromEmailDescription',
194 1
                    'Used for when you want to specify a different from email than your store\'s email address'
195
                )),
196 1
            TextField::create('StorePostalCode', 'Postal Code'),
197 1
            CountryDropdownField::create('StoreCountry', 'Country'),
198 1
            TextField::create('StoreRegion', 'State/Region'),
199 1
            TextField::create('StoreLocaleCode', 'Locale Code')
200 1
                ->setDescription('example: en_US'),
201 1
            TextField::create('StoreTimezone', 'Store timezone'),
202 1
            TextField::create('StoreLogoURL', 'Logo URL')
203 1
                ->setAttribute('placeholder', 'http://'),
204
        ]);
205
206 1
        $fields->addFieldsToTab('Root.Advanced', [
207 1
            HeaderField::create('AdvanceHeader', _t(
208 1
                'FoxyStripeSiteConfig.AdvancedHeader',
209 1
                'Advanced Settings'
210 1
            ), 3),
211 1
            LiteralField::create('AdvancedIntro', _t(
212 1
                'FoxyStripeSiteConfig.AdvancedIntro',
213 1
                '<p>Maps to data in your 
214
                    <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">
215
                        FoxyCart advanced store settings
216
                    </a>.</p>'
217
            )),
218 1
            DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()),
219 1
            CheckboxField::create('BccEmail', 'BCC Admin Email')
220 1
                ->setDescription('bcc all receipts to store\'s email address'),
221 1
            CheckboxField::create('UseWebhook', 'Use Webhook')
222 1
                ->setDescription('record order history in CMS, allows customers to view their order history'),
223 1
            ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()),
224 1
            ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()),
225 1
            CheckboxField::create('CartValidation', 'Use cart validation'),
226 1
            CheckboxField::create('UseSingleSignOn', 'Use single sign on')
227 1
                ->setDescription('Sync user accounts between FoxyCart and your website'),
228 1
            ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()),
229 1
            CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'),
230
        ]);
231
232
        // configuration warning
233 1
        if (FoxyCart::store_name_warning() !== null) {
234
            $fields->insertBefore(LiteralField::create(
235
                'StoreSubDomainHeaderWarning',
236
                _t(
237
                    'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning',
238
                    '<p class="message error">Store Domain must be entered below
239
                        </a></p>'
240
                )
241
            ), 'StoreDetails');
242
        }
243
244
        // products tab
245 1
        $fields->addFieldsToTab('Root.Products', [
246 1
            HeaderField::create('ProductHeader', _t(
247 1
                'FoxyStripeSiteConfig.ProductHeader',
248 1
                'Products'
249 1
            ), 3),
250 1
            CheckboxField::create('MultiGroup')
251 1
                ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups'))
252 1
                ->setDescription(_t(
253 1
                    'FoxyStripeSiteConfig.MultiGroupDescription',
254 1
                    'Allows products to be shown in multiple Product Groups'
255
                )),
256 1
            HeaderField::create('ProductGroupHD', _t(
257 1
                'FoxyStripeSiteConfig.ProductGroupHD',
258 1
                'Product Groups'
259 1
            ), 3),
260 1
            NumericField::create('ProductLimit')
261 1
                ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page'))
262 1
                ->setDescription(_t(
263 1
                    'FoxyStripeSiteConfig.ProductLimitDescription',
264 1
                    'Number of Products to show per page on a Product Group'
265
                )),
266 1
            HeaderField::create('ProductQuantityHD', _t(
267 1
                'FoxyStripeSiteConfig.ProductQuantityHD',
268 1
                'Product Form Max Quantity'
269 1
            ), 3),
270 1
            NumericField::create('MaxQuantity')
271 1
                ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity'))
272 1
                ->setDescription(_t(
273 1
                    'FoxyStripeSiteConfig.MaxQuantityDescription',
274 1
                    'Sets max quantity for product form dropdown (add to cart form - default 10)'
275
                )),
276
        ]);
277
278
        // categories tab
279 1
        $fields->addFieldsToTab('Root.Categories', [
280 1
            HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3),
281 1
            LiteralField::create('CategoryDescrip', _t(
282 1
                'FoxyStripeSiteConfig.CategoryDescrip',
283 1
                '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be 
284
                        accomplished by product options alone, including category specific coupon codes, 
285
                        shipping and handling fees, and email receipts. 
286
                        <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">
287
                            Learn More
288
                        </a></p>
289
                        <p>Categories you\'ve created in FoxyStripe must also be created in your 
290
                            <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" 
291
                                target="_blank">FoxyCart Categories</a> admin panel.</p>'
292
            )),
293 1
            GridField::create(
294 1
                'ProductCategory',
295 1
                _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'),
296 1
                ProductCategory::get(),
297 1
                GridFieldConfig_RecordEditor::create()
298
            ),
299
        ]);
300
301
        // option groups tab
302 1
        $fields->addFieldsToTab('Root.Groups', [
303 1
            HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3),
304 1
            LiteralField::create('OptionGroupsDescrip', _t(
305 1
                'FoxyStripeSiteConfig.OptionGroupsDescrip',
306 1
                '<p>Product Option Groups allow you to name a set of product options.</p>'
307
            )),
308 1
            GridField::create(
309 1
                'OptionGroup',
310 1
                _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'),
311 1
                OptionGroup::get(),
312 1
                GridFieldConfig_RecordEditor::create()
313
            ),
314
        ]);
315
316
        // api tab
317 1
        if (Permission::check('ADMIN')) {
318 1
            $fields->addFieldsToTab('Root.API', [
319 1
                HeaderField::create('APIHD', 'FoxyCart API Settings', 3),
320 1
                CheckboxField::create('EnableAPI', 'Enable FoxyCart API'),
321 1
                TextField::create('client_id', 'FoxyCart Client ID'),
322 1
                TextField::create('client_secret', 'FoxyCart Client Secret'),
323 1
                TextField::create('access_token', 'FoxyCart Access Token'),
324 1
                TextField::create('refresh_token', 'FoxyCart Refresh Token'),
325
            ]);
326
        }
327
328 1
        $fields->addFieldsToTab('Root.Template', [
329 1
            HeaderField::create('TemplateHD', _t('FoxyStripeSiteConfig.TemplateHD', 'Template Options'), 3),
330 1
            CheckboxField::create('EnableSidecart')
331 1
                ->setDescription('Turns on the Sidebar cart. Uncheck to use the full page cart.'),
332
        ]);
333
334 1
        $this->extend('updateCMSFields', $fields);
335
336 1
        return $fields;
337
    }
338
339
    /**
340
     * @return FieldList
341
     */
342
    public function getCMSActions()
343
    {
344
        if (Permission::check('ADMIN') || Permission::check('EDIT_FOXYSTRIPE_SETTING')) {
345
            $actions = new FieldList(
346
                FormAction::create('save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save'))
347
                    ->addExtraClass('btn-primary font-icon-save')
348
            );
349
        } else {
350
            $actions = FieldList::create();
351
        }
352
        $this->extend('updateCMSActions', $actions);
353
354
        return $actions;
355
    }
356
357
    /**
358
     * @throws \SilverStripe\ORM\ValidationException
359
     */
360 3
    public function requireDefaultRecords()
361
    {
362 3
        parent::requireDefaultRecords();
363 3
        $config = self::current_foxystripe_setting();
364
365 3
        if (!$config) {
0 ignored issues
show
introduced by
$config is of type Dynamic\FoxyStripe\Model\FoxyStripeSetting, thus it always evaluated to true.
Loading history...
366
            self::make_foxystripe_setting();
367
            DB::alteration_message('Added default FoxyStripe Setting', 'created');
368
        }
369
370 3
        if (!$config->StoreKey) {
371 3
            $key = FoxyCart::setStoreKey();
372 3
            while (!ctype_alnum($key)) {
373
                $key = FoxyCart::setStoreKey();
374
            }
375 3
            $config->StoreKey = $key;
0 ignored issues
show
Documentation Bug introduced by
It seems like $key of type string is incompatible with the declared type SilverStripe\ORM\FieldType\DBVarchar of property $StoreKey.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
376 3
            $config->write();
377 3
            DB::alteration_message('Created FoxyCart Store Key ' . $key, 'created');
378
        }
379
    }
380
381
    /**
382
     * @return string
383
     */
384
    public function CMSEditLink()
385
    {
386
        return FoxyStripeAdmin::singleton()->Link();
387
    }
388
389
    /**
390
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
391
     *
392
     * @return bool|int|null
393
     */
394
    public function canEdit($member = null)
395
    {
396
        if (!$member) {
0 ignored issues
show
introduced by
$member is of type null, thus it always evaluated to false.
Loading history...
397
            $member = Security::getCurrentUser();
398
        }
399
400
        $extended = $this->extendedCan('canEdit', $member);
401
        if ($extended !== null) {
402
            return $extended;
403
        }
404
405
        return Permission::checkMember($member, 'EDIT_FOXYSTRIPE_SETTING');
406
    }
407
408
    /**
409
     * @return array
410
     */
411
    public function providePermissions()
412
    {
413
        return [
414
            'EDIT_FOXYSTRIPE_SETTING' => [
415
                'name' => _t(
416
                    'FoxyStripeSetting.EDIT_FOXYSTRIPE_SETTING',
417
                    'Manage FoxyStripe settings'
418
                ),
419
                'category' => _t(
420
                    'Permissions.PERMISSIONS_FOXYSTRIPE_SETTING',
421
                    'FoxyStripe'
422
                ),
423
                'help' => _t(
424
                    'FoxyStripeSetting.EDIT_PERMISSION_FOXYSTRIPE_SETTING',
425
                    'Ability to edit the settings of a FoxyStripe Store.'
426
                ),
427
                'sort' => 400,
428
            ],
429
        ];
430
    }
431
432
    /**
433
     * Get the current sites {@link GlobalSiteSetting}, and creates a new one
434
     * through {@link make_global_config()} if none is found.
435
     *
436
     * @return FoxyStripeSetting|DataObject
437
     * @throws \SilverStripe\ORM\ValidationException
438
     */
439 49
    public static function current_foxystripe_setting()
440
    {
441 49
        if ($config = self::get()->first()) {
442 49
            return $config;
443
        }
444
445 9
        return self::make_foxystripe_setting();
446
    }
447
448
    /**
449
     * Create {@link GlobalSiteSetting} with defaults from language file.
450
     *
451
     * @return static
452
     */
453 9
    public static function make_foxystripe_setting()
454
    {
455 9
        $config = self::create();
456
        try {
457 9
            $config->write();
458
        } catch (ValidationException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
459
        }
460
461 9
        return $config;
462
    }
463
464
    /**
465
     * Add $GlobalConfig to all SSViewers.
466
     */
467
    public static function get_template_global_variables()
468
    {
469
        return [
470
            'FoxyStripe' => 'current_foxystripe_config',
471
        ];
472
    }
473
474
    /**
475
     * @return string
476
     */
477 2
    private static function getSSOLink()
478
    {
479 2
        return Director::absoluteBaseURL() . 'foxystripe/sso/';
480
    }
481
482
    /**
483
     * @return string
484
     */
485 2
    private static function getDataFeedLink()
486
    {
487 2
        return Director::absoluteBaseURL() . 'foxystripe/';
488
    }
489
490
    /**
491
     * @return array
492
     */
493 1
    public function getCheckoutTypes()
494
    {
495
        return [
496 1
            'default_account' => 'Allow guest and customer accounts, default to account',
497
            'default_guest' => 'Allow guest and customer accounts, default to guest',
498
            'account_only' => 'Allow customer accounts only',
499
            'guest_only' => 'Allow guests only',
500
        ];
501
    }
502
503
    /**
504
     * @return array
505
     */
506 1
    public function getDataMap()
507
    {
508
        return [
509 1
            'store_name' => $this->StoreTitle,
510 1
            'store_domain' => $this->StoreName,
511 1
            'store_url' => $this->StoreURL,
512 1
            'receipt_continue_url' => $this->ReceiptURL,
513 1
            'store_email' => $this->StoreEmail,
514 1
            'from_email' => $this->FromEmail,
515 1
            'postal_code' => $this->StorePostalCode,
516 1
            'country' => $this->StoreCountry,
517 1
            'region' => $this->StoreRegion,
518 1
            'locale_code' => $this->StoreLocaleCode,
519 1
            'logo_url' => $this->StoreLogoURL,
520 1
            'checkout_type' => $this->CheckoutType,
521 1
            'bcc_on_receipt_email' => $this->BccEmail,
522 1
            'use_webhook' => $this->UseWebhook,
523 1
            'webhook_url' => $this->getDataFeedLink(),
524 1
            'webhook_key' => $this->StoreKey,
525 1
            'use_cart_validation' => $this->CartValidation,
526 1
            'use_single_sign_on' => $this->UseSingleSignOn,
527 1
            'single_sign_on_url' => $this->getSSOLink(),
528 1
            'customer_password_hash_type' => 'sha1_salted_suffix',
529 1
            'customer_password_hash_config' => 40,
530 1
            'features_multiship' => $this->AllowMultiship,
531
            //'timezone' => $this->StoreTimezone,
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
532
        ];
533
    }
534
535
    /**
536
     * if StoreTitle is empty, grab values from FoxyCart.
537
     *
538
     * example of 2 way sync for future reference
539
     *
540
     * @throws \Psr\Container\NotFoundExceptionInterface
541
     */
542 11
    public function onBeforeWrite()
543
    {
544 11
        parent::onBeforeWrite();
545
546 11
        if ($this->ID && !$this->StoreTitle && $this->access_token) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
547
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
548
            if ($fc = new FoxyStripeClient()) {
549
                $client = $fc->getClient();
550
                $errors = [];
551
552
                $result = $client->get($fc->getCurrentStore());
553
                $this->owner->StoreTitle = $result['store_name'];
554
555
                $errors = array_merge($errors, $client->getErrors($result));
556
                if (count($errors)) {
557
                    Injector::inst()->get(LoggerInterface::class)
558
                        ->error('FoxyStripeSiteConfig::onBeforeWrite errors - ' . json_encode($errors));
559
                }
560
            }
561
            */
562
        }
563
    }
564
565
    /**
566
     * @throws \SilverStripe\ORM\ValidationException
567
     */
568 11
    public function onAfterWrite()
569
    {
570 11
        parent::onAfterWrite();
571
572 11
        if (FoxyStripeClient::is_valid() && $this->isChanged()) {
573
            if ($fc = new FoxyStripeClient()) {
574
                $fc->updateStore($this->getDataMap());
575
            }
576
        }
577
    }
578
}
579