Completed
Push — master ( 10c38a...3a9e00 )
by Jason
03:24
created

FoxyStripeSetting   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 503
Duplicated Lines 0 %

Test Coverage

Coverage 84%

Importance

Changes 0
Metric Value
wmc 31
eloc 268
dl 0
loc 503
ccs 189
cts 225
cp 0.84
rs 9.92
c 0
b 0
f 0

15 Methods

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