Completed
Pull Request — master (#316)
by Matthew
12:03 queued 08:57
created

FoxyStripeSetting::make_foxystripe_setting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use Dynamic\CountryDropdownField\Fields\CountryDropdownField;
6
use Dynamic\FoxyStripe\Admin\FoxyStripeAdmin;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Forms\CheckboxField;
9
use SilverStripe\Forms\DropdownField;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\Forms\FormAction;
12
use SilverStripe\Forms\GridField\GridField;
13
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
14
use SilverStripe\Forms\HeaderField;
15
use SilverStripe\Forms\HiddenField;
16
use SilverStripe\Forms\LiteralField;
17
use SilverStripe\Forms\NumericField;
18
use SilverStripe\Forms\ReadonlyField;
19
use SilverStripe\Forms\Tab;
20
use SilverStripe\Forms\TabSet;
21
use SilverStripe\Forms\TextField;
22
use SilverStripe\ORM\DataObject;
23
use SilverStripe\ORM\DB;
24
use SilverStripe\ORM\ValidationException;
25
use SilverStripe\Security\Permission;
26
use SilverStripe\Security\PermissionProvider;
27
use SilverStripe\Security\Security;
28
use SilverStripe\View\TemplateGlobalProvider;
29
30
/**
31
 * Class FoxyStripeSetting
32
 * @package Dynamic\FoxyStripe\Model
33
 *
34
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreTitle
35
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreName
36
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreURL
37
 * @property \SilverStripe\ORM\FieldType\DBVarchar ReceiptURL
38
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreEmail
39
 * @property \SilverStripe\ORM\FieldType\DBVarchar FromEmail
40
 * @property \SilverStripe\ORM\FieldType\DBVarchar StorePostalCode
41
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreCountry
42
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreRegion
43
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreLocaleCode
44
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreLogoURL
45
 * @property \SilverStripe\ORM\FieldType\DBVarchar CheckoutType
46
 * @property \SilverStripe\ORM\FieldType\DBBoolean BccEmail
47
 * @property \SilverStripe\ORM\FieldType\DBBoolean UseWebhook
48
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreKey
49
 * @property \SilverStripe\ORM\FieldType\DBBoolean CartValidation
50
 * @property \SilverStripe\ORM\FieldType\DBBoolean UseSingleSignOn
51
 * @property \SilverStripe\ORM\FieldType\DBBoolean AllowMultiship
52
 * @property \SilverStripe\ORM\FieldType\DBVarchar StoreTimezone
53
 * @property \SilverStripe\ORM\FieldType\DBBoolean MultiGroup
54
 * @property \SilverStripe\ORM\FieldType\DBInt ProductLimit
55
 * @property \SilverStripe\ORM\FieldType\DBInt MaxQuantity
56
 * @property \SilverStripe\ORM\FieldType\DBVarchar client_id
57
 * @property \SilverStripe\ORM\FieldType\DBVarchar client_secret
58
 * @property \SilverStripe\ORM\FieldType\DBVarchar access_token
59
 * @property \SilverStripe\ORM\FieldType\DBVarchar refresh_token
60
 */
61
class FoxyStripeSetting extends DataObject implements PermissionProvider, TemplateGlobalProvider
62
{
63
    /**
64
     * @var string
65
     */
66
    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...
67
    /**
68
     * @var string
69
     */
70
    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...
71
    /**
72
     * @var string
73
     */
74
    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...
75
76
    /**
77
     * @var array
78
     */
79
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
80
        'StoreTitle' => 'Varchar(255)',
81
        'StoreName' => 'Varchar(255)',
82
        'StoreURL' => 'Varchar(255)',
83
        'ReceiptURL' => 'Varchar(255)',
84
        'StoreEmail' => 'Varchar(255)',
85
        'FromEmail' => 'Varchar(255)',
86
        'StorePostalCode' => 'Varchar(10)',
87
        'StoreCountry' => 'Varchar(100)',
88
        'StoreRegion' => 'Varchar(100)',
89
        'StoreLocaleCode' => 'Varchar(10)',
90
        'StoreLogoURL' => 'Varchar(255)',
91
        'CheckoutType' => 'Varchar(50)',
92
        'BccEmail' => 'Boolean',
93
        'UseWebhook' => 'Boolean',
94
        'StoreKey' => 'Varchar(60)',
95
        'CartValidation' => 'Boolean',
96
        'UseSingleSignOn' => 'Boolean',
97
        'AllowMultiship' => 'Boolean',
98
        'StoreTimezone' => 'Varchar(100)',
99
        'MultiGroup' => 'Boolean',
100
        'ProductLimit' => 'Int',
101
        'MaxQuantity' => 'Int',
102
        'client_id' => 'Varchar(255)',
103
        'client_secret' => 'Varchar(255)',
104
        'access_token' => 'Varchar(255)',
105
        'refresh_token' => 'Varchar(255)',
106
    ];
107
108
    // Set Default values
109
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
110
        'ProductLimit' => 10,
111
    ];
112
113
    /**
114
     * @var string
115
     */
116
    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...
117
118
    /**
119
     * Default permission to check for 'LoggedInUsers' to create or edit pages.
120
     *
121
     * @var array
122
     * @config
123
     */
124
    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...
125
126
    /**
127
     * @return FieldList
128
     */
129 1
    public function getCMSFields()
130
    {
131 1
        $fields = FieldList::create(
132 1
            TabSet::create(
133 1
                'Root',
134 1
                $tabMain = Tab::create(
135 1
                    'Main'
0 ignored issues
show
Bug introduced by
'Main' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
                    /** @scrutinizer ignore-type */ 'Main'
Loading history...
136
                )
137
            ),
138 1
            HiddenField::create('ID')
139
        );
140 1
        $tabMain->setTitle('Settings');
141
142
        // settings tab
143 1
        $fields->addFieldsToTab('Root.Main', [
144
            // Store Details
145 1
            HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3),
0 ignored issues
show
Bug introduced by
3 of type integer is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
            HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), /** @scrutinizer ignore-type */ 3),
Loading history...
146 1
            LiteralField::create('DetailsIntro', _t(
147 1
                'FoxyStripeSiteConfig.DetailsIntro',
148 1
                '<p>Maps to data in your 
149
                        <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">
150
                            FoxyCart store settings
151
                        </a>.'
152
            )),
153 1
            TextField::create('StoreTitle')
154 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name'))
155 1
                ->setDescription(_t(
156 1
                    'FoxyStripeSiteConfig.StoreTitleDescription',
157 1
                    'The name of your store as you\'d like it displayed to your customers'
158
                )),
159 1
            TextField::create('StoreName')
160 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain'))
161 1
                ->setDescription(_t(
162 1
                    'FoxyStripeSiteConfig.StoreNameDescription',
163 1
                    'This is a unique FoxyCart subdomain for your cart, checkout, and receipt'
164
                )),
165 1
            TextField::create('StoreURL')
166 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL'))
167 1
                ->setDescription(_t(
168 1
                    'FoxyStripeSiteConfig.StoreURLDescription',
169 1
                    'The URL of your online store'
170
                )),
171 1
            TextField::create('ReceiptURL')
172 1
                ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL'))
173 1
                ->setDescription(_t(
174 1
                    'FoxyStripeSiteConfig.ReceiptURLDescription',
175 1
                    'By default, FoxyCart sends customers back to the page referrer after completing a purchase. 
176
                            Instead, you can set a specific URL here.'
177
                )),
178 1
            TextField::create('StoreEmail')
179 1
                ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email'))
180 1
                ->setDescription(_t(
181 1
                    'FoxyStripeSiteConfig.StoreEmailDescription',
182 1
                    'This is the email address of your store. By default, this will be the from address for your 
183
                            store receipts. '
184
                )),
185 1
            TextField::create('FromEmail')
186 1
                ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email'))
187 1
                ->setDescription(_t(
188 1
                    'FoxyStripeSiteConfig.FromEmailDescription',
189 1
                    'Used for when you want to specify a different from email than your store\'s email address'
190
                )),
191 1
            TextField::create('StorePostalCode', 'Postal Code'),
192 1
            CountryDropdownField::create('StoreCountry', 'Country'),
193 1
            TextField::create('StoreRegion', 'State/Region'),
194 1
            TextField::create('StoreLocaleCode', 'Locale Code')
195 1
                ->setDescription('example: en_US'),
196 1
            TextField::create('StoreTimezone', 'Store timezone'),
197 1
            TextField::create('StoreLogoURL', 'Logo URL')
198 1
                ->setAttribute('placeholder', 'http://'),
199
        ]);
200
201 1
        $fields->addFieldsToTab('Root.Advanced', [
202 1
            HeaderField::create('AdvanceHeader', _t(
203 1
                'FoxyStripeSiteConfig.AdvancedHeader',
204 1
                'Advanced Settings'
205 1
            ), 3),
206 1
            LiteralField::create('AdvancedIntro', _t(
207 1
                'FoxyStripeSiteConfig.AdvancedIntro',
208 1
                '<p>Maps to data in your 
209
                    <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">
210
                        FoxyCart advanced store settings
211
                    </a>.</p>'
212
            )),
213 1
            DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()),
214 1
            CheckboxField::create('BccEmail', 'BCC Admin Email')
215 1
                ->setDescription('bcc all receipts to store\'s email address'),
216 1
            CheckboxField::create('UseWebhook', 'Use Webhook')
217 1
                ->setDescription('record order history in CMS, allows customers to view their order history'),
218 1
            ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()),
219 1
            ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()),
220 1
            CheckboxField::create('CartValidation', 'Use cart validation'),
221 1
            CheckboxField::create('UseSingleSignOn', 'Use single sign on')
222 1
                ->setDescription('Sync user accounts between FoxyCart and your website'),
223 1
            ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()),
224 1
            CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'),
225
        ]);
226
227
        // configuration warning
228 1
        if (FoxyCart::store_name_warning() !== null) {
229
            $fields->insertBefore(LiteralField::create(
230
                'StoreSubDomainHeaderWarning',
231
                _t(
232
                    'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning',
233
                    '<p class="message error">Store Domain must be entered below
234
                        </a></p>'
235
                )
236
            ), 'StoreDetails');
237
        }
238
239
        // products tab
240 1
        $fields->addFieldsToTab('Root.Products', [
241 1
            HeaderField::create('ProductHeader', _t(
242 1
                'FoxyStripeSiteConfig.ProductHeader',
243 1
                'Products'
244 1
            ), 3),
245 1
            CheckboxField::create('MultiGroup')
246 1
                ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups'))
247 1
                ->setDescription(_t(
248 1
                    'FoxyStripeSiteConfig.MultiGroupDescription',
249 1
                    'Allows products to be shown in multiple Product Groups'
250
                )),
251 1
            HeaderField::create('ProductGroupHD', _t(
252 1
                'FoxyStripeSiteConfig.ProductGroupHD',
253 1
                'Product Groups'
254 1
            ), 3),
255 1
            NumericField::create('ProductLimit')
256 1
                ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page'))
257 1
                ->setDescription(_t(
258 1
                    'FoxyStripeSiteConfig.ProductLimitDescription',
259 1
                    'Number of Products to show per page on a Product Group'
260
                )),
261 1
            HeaderField::create('ProductQuantityHD', _t(
262 1
                'FoxyStripeSiteConfig.ProductQuantityHD',
263 1
                'Product Form Max Quantity'
264 1
            ), 3),
265 1
            NumericField::create('MaxQuantity')
266 1
                ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity'))
267 1
                ->setDescription(_t(
268 1
                    'FoxyStripeSiteConfig.MaxQuantityDescription',
269 1
                    'Sets max quantity for product form dropdown (add to cart form - default 10)'
270
                )),
271
        ]);
272
273
        // categories tab
274 1
        $fields->addFieldsToTab('Root.Categories', [
275 1
            HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3),
276 1
            LiteralField::create('CategoryDescrip', _t(
277 1
                'FoxyStripeSiteConfig.CategoryDescrip',
278 1
                '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be 
279
                        accomplished by product options alone, including category specific coupon codes, 
280
                        shipping and handling fees, and email receipts. 
281
                        <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">
282
                            Learn More
283
                        </a></p>
284
                        <p>Categories you\'ve created in FoxyStripe must also be created in your 
285
                            <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" 
286
                                target="_blank">FoxyCart Categories</a> admin panel.</p>'
287
            )),
288 1
            GridField::create(
289 1
                'ProductCategory',
290 1
                _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'),
291 1
                ProductCategory::get(),
0 ignored issues
show
Bug introduced by
Dynamic\FoxyStripe\Model\ProductCategory::get() of type SilverStripe\ORM\DataList is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

291
                /** @scrutinizer ignore-type */ ProductCategory::get(),
Loading history...
292 1
                GridFieldConfig_RecordEditor::create()
293
            ),
294
        ]);
295
296
        // option groups tab
297 1
        $fields->addFieldsToTab('Root.Groups', [
298 1
            HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3),
299 1
            LiteralField::create('OptionGroupsDescrip', _t(
300 1
                'FoxyStripeSiteConfig.OptionGroupsDescrip',
301 1
                '<p>Product Option Groups allow you to name a set of product options.</p>'
302
            )),
303 1
            GridField::create(
304 1
                'OptionGroup',
305 1
                _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'),
306 1
                OptionGroup::get(),
307 1
                GridFieldConfig_RecordEditor::create()
308
            ),
309
        ]);
310
311
        // api tab
312 1
        $fields->addFieldsToTab('Root.API', [
313 1
            HeaderField::create('APIHD', 'FoxyCart API Settings', 3),
314 1
            TextField::create('client_id', 'FoxyCart Client ID'),
315 1
            TextField::create('client_secret', 'FoxyCart Client Secret'),
316 1
            TextField::create('access_token', 'FoxyCart Access Token'),
317 1
            TextField::create('refresh_token', 'FoxyCart Refresh Token'),
318
        ]);
319
320 1
        $this->extend('updateCMSFields', $fields);
321
322 1
        return $fields;
323
    }
324
325
    /**
326
     * @return FieldList
327
     */
328
    public function getCMSActions()
329
    {
330
        if (Permission::check('ADMIN') || Permission::check('EDIT_FOXYSTRIPE_SETTING')) {
331
            $actions = new FieldList(
332
                FormAction::create('save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save'))
0 ignored issues
show
Bug introduced by
'save_foxystripe_setting' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

332
                FormAction::create(/** @scrutinizer ignore-type */ 'save_foxystripe_setting', _t('FoxyStripeSetting.SAVE', 'Save'))
Loading history...
333
                    ->addExtraClass('btn-primary font-icon-save')
334
            );
335
        } else {
336
            $actions = FieldList::create();
337
        }
338
        $this->extend('updateCMSActions', $actions);
339
340
        return $actions;
341
    }
342
343
    /**
344
     * @throws \SilverStripe\ORM\ValidationException
345
     */
346 3
    public function requireDefaultRecords()
347
    {
348 3
        parent::requireDefaultRecords();
349 3
        $config = self::current_foxystripe_setting();
350
351 3
        if (!$config) {
352
            self::make_foxystripe_setting();
353
            DB::alteration_message('Added default FoxyStripe Setting', 'created');
354
        }
355
356 3
        if (!$config->StoreKey) {
357 3
            $key = FoxyCart::setStoreKey();
358 3
            while (!ctype_alnum($key)) {
359
                $key = FoxyCart::setStoreKey();
360
            }
361 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...
362 3
            $config->write();
363 3
            DB::alteration_message('Created FoxyCart Store Key ' . $key, 'created');
364
        }
365
    }
366
367
    /**
368
     * @return string
369
     */
370
    public function CMSEditLink()
371
    {
372
        return FoxyStripeAdmin::singleton()->Link();
373
    }
374
375
    /**
376
     * @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...
377
     *
378
     * @return bool|int|null
379
     */
380
    public function canEdit($member = null)
381
    {
382
        if (!$member) {
383
            $member = Security::getCurrentUser();
384
        }
385
386
        $extended = $this->extendedCan('canEdit', $member);
387
        if ($extended !== null) {
388
            return $extended;
389
        }
390
391
        return Permission::checkMember($member, 'EDIT_FOXYSTRIPE_SETTING');
392
    }
393
394
    /**
395
     * @return array
396
     */
397
    public function providePermissions()
398
    {
399
        return [
400
            'EDIT_FOXYSTRIPE_SETTING' => [
401
                'name' => _t(
402
                    'FoxyStripeSetting.EDIT_FOXYSTRIPE_SETTING',
403
                    'Manage FoxyStripe settings'
404
                ),
405
                'category' => _t(
406
                    'Permissions.PERMISSIONS_FOXYSTRIPE_SETTING',
407
                    'FoxyStripe'
408
                ),
409
                'help' => _t(
410
                    'FoxyStripeSetting.EDIT_PERMISSION_FOXYSTRIPE_SETTING',
411
                    'Ability to edit the settings of a FoxyStripe Store.'
412
                ),
413
                'sort' => 400,
414
            ],
415
        ];
416
    }
417
418
    /**
419
     * Get the current sites {@link GlobalSiteSetting}, and creates a new one
420
     * through {@link make_global_config()} if none is found.
421
     *
422
     * @return FoxyStripeSetting|DataObject
423
     */
424 49
    public static function current_foxystripe_setting()
425
    {
426 49
        if ($config = self::get()->first()) {
427 49
            return $config;
428
        }
429
430 49
        return self::make_foxystripe_setting();
431
    }
432
433
    /**
434
     * Create {@link GlobalSiteSetting} with defaults from language file.
435
     *
436
     * @return static
437
     */
438 49
    public static function make_foxystripe_setting()
439
    {
440 49
        $config = self::create();
441
        try {
442 49
            $config->write();
443
        } catch (ValidationException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
444
445
        }
446
447 49
        return $config;
448
    }
449
450
    /**
451
     * Add $GlobalConfig to all SSViewers.
452
     */
453
    public static function get_template_global_variables()
454
    {
455
        return [
456
            'FoxyStripe' => 'current_foxystripe_config',
457
        ];
458
    }
459
460
    /**
461
     * @return string
462
     */
463 2
    private static function getSSOLink()
464
    {
465 2
        return Director::absoluteBaseURL() . 'foxystripe/sso/';
466
    }
467
468
    /**
469
     * @return string
470
     */
471 2
    private static function getDataFeedLink()
472
    {
473 2
        return Director::absoluteBaseURL() . 'foxystripe/';
474
    }
475
476
    /**
477
     * @return array
478
     */
479 1
    public function getCheckoutTypes()
480
    {
481
        return [
482 1
            'default_account' => 'Allow guest and customer accounts, default to account',
483
            'default_guest' => 'Allow guest and customer accounts, default to guest',
484
            'account_only' => 'Allow customer accounts only',
485
            'guest_only' => 'Allow guests only',
486
        ];
487
    }
488
489
    /**
490
     * @return array
491
     */
492 1
    public function getDataMap()
493
    {
494
        return [
495 1
            'store_name' => $this->StoreTitle,
496 1
            'store_domain' => $this->StoreName,
497 1
            'store_url' => $this->StoreURL,
498 1
            'receipt_continue_url' => $this->ReceiptURL,
499 1
            'store_email' => $this->StoreEmail,
500 1
            'from_email' => $this->FromEmail,
501 1
            'postal_code' => $this->StorePostalCode,
502 1
            'country' => $this->StoreCountry,
503 1
            'region' => $this->StoreRegion,
504 1
            'locale_code' => $this->StoreLocaleCode,
505 1
            'logo_url' => $this->StoreLogoURL,
506 1
            'checkout_type' => $this->CheckoutType,
507 1
            'bcc_on_receipt_email' => $this->BccEmail,
508 1
            'use_webhook' => $this->UseWebhook,
509 1
            'webhook_url' => $this->getDataFeedLink(),
510 1
            'webhook_key' => $this->StoreKey,
511 1
            'use_cart_validation' => $this->CartValidation,
512 1
            'use_single_sign_on' => $this->UseSingleSignOn,
513 1
            'single_sign_on_url' => $this->getSSOLink(),
514 1
            'customer_password_hash_type' => 'sha1_salted_suffix',
515 1
            'customer_password_hash_config' => 40,
516 1
            'features_multiship' => $this->AllowMultiship,
517
            //'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...
518
        ];
519
    }
520
521
    /**
522
     * if StoreTitle is empty, grab values from FoxyCart.
523
     *
524
     * example of 2 way sync for future reference
525
     *
526
     * @throws \Psr\Container\NotFoundExceptionInterface
527
     */
528 49
    public function onBeforeWrite()
529
    {
530 49
        parent::onBeforeWrite();
531
532 49
        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...
533
            /*
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...
534
            if ($fc = new FoxyStripeClient()) {
535
                $client = $fc->getClient();
536
                $errors = [];
537
538
                $result = $client->get($fc->getCurrentStore());
539
                $this->owner->StoreTitle = $result['store_name'];
540
541
                $errors = array_merge($errors, $client->getErrors($result));
542
                if (count($errors)) {
543
                    Injector::inst()->get(LoggerInterface::class)
544
                        ->error('FoxyStripeSiteConfig::onBeforeWrite errors - ' . json_encode($errors));
545
                }
546
            }
547
            */
548
        }
549
    }
550
551
    /**
552
     * @throws \Psr\Container\NotFoundExceptionInterface
553
     */
554 49
    public function onAfterWrite()
555
    {
556 49
        parent::onAfterWrite();
557
558 49
        if ($this->isChanged() && $this->access_token) {
559
            if ($fc = new FoxyStripeClient()) {
560
                $fc->updateStore($this->getDataMap());
561
            }
562
        }
563
    }
564
}
565