Conditions | 2 |
Paths | 2 |
Total Lines | 156 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
65 | public function updateCMSFields(FieldList $fields){ |
||
66 | |||
67 | // set TabSet names to avoid spaces from camel case |
||
68 | $fields->addFieldToTab('Root', new TabSet('FoxyStripe', 'FoxyStripe')); |
||
69 | |||
70 | // settings tab |
||
71 | $fields->addFieldsToTab('Root.FoxyStripe.Settings', array( |
||
72 | // Store Details |
||
73 | HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), |
||
74 | LiteralField::create('DetailsIntro', _t( |
||
75 | 'FoxyStripeSiteConfig.DetailsIntro', |
||
76 | '<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank">FoxyCart store settings</a>.' |
||
77 | )), |
||
78 | TextField::create('StoreTitle') |
||
79 | ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name')) |
||
80 | ->setDescription(_t('FoxyStripeSiteConfig.StoreTitleDescription', 'The name of your store as you\'d like it displayed to your customers')), |
||
81 | TextField::create('StoreName') |
||
82 | ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain')) |
||
83 | ->setDescription(_t('FoxyStripeSiteConfig.StoreNameDescription', 'This is a unique FoxyCart subdomain for your cart, checkout, and receipt')), |
||
84 | TextField::create('StoreURL') |
||
85 | ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL')) |
||
86 | ->setDescription(_t('FoxyStripeSiteConfig.StoreURLDescription', 'The URL of your online store')), |
||
87 | TextField::create('ReceiptURL') |
||
88 | ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL')) |
||
89 | ->setDescription(_t('FoxyStripeSiteConfig.ReceiptURLDescription', 'By default, FoxyCart sends customers back to the page referrer after completing a purchase. Instead, you can set a specific URL here')), |
||
90 | TextField::create('StoreEmail') |
||
91 | ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email')) |
||
92 | ->setDescription(_t('FoxyStripeSiteConfig.StoreEmailDescription', 'This is the email address of your store. By default, this will be the from address for your store receipts. ')), |
||
93 | TextField::create('FromEmail') |
||
94 | ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email')) |
||
95 | ->setDescription(_t('FoxyStripeSiteConfig.FromEmailDescription', 'Used for when you want to specify a different from email than your store\'s email address')), |
||
96 | TextField::create('StorePostalCode', 'Postal Code'), |
||
97 | CountryDropdownField::create('StoreCountry', 'Country'), |
||
98 | TextField::create('StoreRegion', 'State/Region'), |
||
99 | TextField::create('StoreLocaleCode', 'Locale Code') |
||
100 | ->setDescription('example: en_US'), |
||
101 | TextField::create('StoreTimezone', 'Store timezone'), |
||
102 | TextField::create('StoreLogoURL', 'Logo URL') |
||
103 | ->setAttribute('placeholder', 'http://') |
||
104 | |||
105 | // Advanced Settings |
||
106 | /* |
||
107 | HeaderField::create('AdvanceHeader', _t('FoxyStripeSiteConfig.AdvancedHeader', 'Advanced Settings'), 3), |
||
108 | LiteralField::create('AdvancedIntro', _t( |
||
109 | 'FoxyStripeSiteConfig.AdvancedIntro', |
||
110 | '<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">FoxyCart advanced store settings</a>.</p>' |
||
111 | )), |
||
112 | ReadonlyField::create('DataFeedLink', _t('FoxyStripeSiteConfig.DataFeedLink', 'FoxyCart DataFeed URL'), self::getDataFeedLink()) |
||
113 | ->setDescription(_t('FoxyStripeSiteConfig.DataFeedLinkDescription', 'copy/paste to FoxyCart')), |
||
114 | CheckboxField::create('CartValidation') |
||
115 | ->setTitle(_t('FoxyStripeSiteConfig.CartValidation', 'Enable Cart Validation')) |
||
116 | ->setDescription(_t( |
||
117 | 'FoxyStripeSiteConfig.CartValidationDescription', |
||
118 | 'You must <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures#use_cart_validation" target="_blank">enable cart validation</a> in the FoxyCart admin.' |
||
119 | )), |
||
120 | ReadonlyField::create('StoreKey') |
||
121 | ->setTitle(_t('FoxyStripeSiteConfig.StoreKey', 'FoxyCart API Key')) |
||
122 | ->setDescription(_t('FoxyStripeSiteConfig.StoreKeyDescription', 'copy/paste to FoxyCart')), |
||
123 | ReadonlyField::create('SSOLink', _t('FoxyStripeSiteConfig.SSOLink', 'Single Sign On URL'), self::getSSOLink()) |
||
124 | ->setDescription(_t('FoxyStripeSiteConfig.SSOLinkDescription', 'copy/paste to FoxyCart')) |
||
125 | */ |
||
126 | )); |
||
127 | |||
128 | $fields->addFieldsToTab('Root.FoxyStripe.Advanced', [ |
||
129 | HeaderField::create('AdvanceHeader', _t('FoxyStripeSiteConfig.AdvancedHeader', 'Advanced Settings'), 3), |
||
130 | LiteralField::create('AdvancedIntro', _t( |
||
131 | 'FoxyStripeSiteConfig.AdvancedIntro', |
||
132 | '<p>Maps to data in your <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank">FoxyCart advanced store settings</a>.</p>' |
||
133 | )), |
||
134 | DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()), |
||
135 | CheckboxField::create('BccEmail', 'BCC Admin Email') |
||
136 | ->setDescription('bcc all receipts to store\'s email address'), |
||
137 | CheckboxField::create('UseWebhook', 'Use Webhook') |
||
138 | ->setDescription('record order history in CMS, allows customers to view their order history'), |
||
139 | ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()), |
||
140 | ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()), |
||
141 | CheckboxField::create('CartValidation', 'Use cart validation'), |
||
142 | CheckboxField::create('UseSingleSignOn', 'Use single sign on') |
||
143 | ->setDescription('Sync user accounts between FoxyCart and your website'), |
||
144 | ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()), |
||
145 | CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order') |
||
146 | ]); |
||
147 | |||
148 | // configuration warning |
||
149 | if(FoxyCart::store_name_warning()!==null){ |
||
150 | $fields->insertBefore(LiteralField::create( |
||
151 | "StoreSubDomainHeaderWarning", |
||
152 | _t( |
||
153 | 'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', |
||
154 | "<p class=\"message error\">Store sub-domain must be entered in the <a href=\"/admin/settings/\">site settings</a></p>" |
||
155 | ) |
||
156 | ), 'StoreDetails'); |
||
157 | } |
||
158 | |||
159 | // products tab |
||
160 | $fields->addFieldsToTab('Root.FoxyStripe.Products', array( |
||
161 | HeaderField::create('ProductHeader', _t('FoxyStripeSiteConfig.ProductHeader', 'Products'), 3), |
||
162 | CheckboxField::create('MultiGroup') |
||
163 | ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups')) |
||
164 | ->setDescription(_t( |
||
165 | 'FoxyStripeSiteConfig.MultiGroupDescription', |
||
166 | 'Allows products to be shown in multiple Product Groups' |
||
167 | )), |
||
168 | HeaderField::create('ProductGroupHD', _t('FoxyStripeSiteConfig.ProductGroupHD', 'Product Groups'), 3), |
||
169 | NumericField::create('ProductLimit') |
||
170 | ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page')) |
||
171 | ->setDescription(_t( |
||
172 | 'FoxyStripeSiteConfig.ProductLimitDescription', |
||
173 | 'Number of Products to show per page on a Product Group' |
||
174 | )), |
||
175 | HeaderField::create('ProductQuantityHD', _t('FoxyStripeSiteConfig.ProductQuantityHD', 'Product Form Max Quantity'), 3), |
||
176 | NumericField::create('MaxQuantity') |
||
177 | ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity')) |
||
178 | ->setDescription(_t( |
||
179 | 'FoxyStripeSiteConfig.MaxQuantityDescription', |
||
180 | 'Sets max quantity for product form dropdown (add to cart form - default 10)' |
||
181 | )) |
||
182 | )); |
||
183 | |||
184 | // categories tab |
||
185 | $fields->addFieldsToTab('Root.FoxyStripe.Categories', array( |
||
186 | HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), |
||
187 | LiteralField::create('CategoryDescrip', _t( |
||
188 | 'FoxyStripeSiteConfig.CategoryDescrip', |
||
189 | '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be accomplished by product options alone, including category specific coupon codes, shipping and handling fees, and email receipts. <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank">Learn More</a></p><p>Categories you\'ve created in FoxyStripe must also be created in your <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" target="_blank">FoxyCart Categories</a> admin panel.</p>' |
||
190 | )), |
||
191 | GridField::create( |
||
192 | 'ProductCategory', |
||
193 | _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), |
||
194 | ProductCategory::get(), |
||
195 | GridFieldConfig_RecordEditor::create() |
||
196 | ) |
||
197 | )); |
||
198 | |||
199 | // option groups tab |
||
200 | $fields->addFieldsToTab('Root.FoxyStripe.Groups', array( |
||
201 | HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), |
||
202 | LiteralField::create('OptionGroupsDescrip', _t( |
||
203 | 'FoxyStripeSiteConfig.OptionGroupsDescrip', |
||
204 | '<p>Product Option Groups allow you to name a set of product options.</p>' |
||
205 | )), |
||
206 | GridField::create( |
||
207 | 'OptionGroup', |
||
208 | _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), |
||
209 | OptionGroup::get(), |
||
210 | GridFieldConfig_RecordEditor::create() |
||
211 | ) |
||
212 | )); |
||
213 | |||
214 | // api tab |
||
215 | $fields->addFieldsToTab('Root.FoxyStripe.API', [ |
||
216 | HeaderField::create('APIHD', 'FoxyCart API Settings', 3), |
||
217 | TextField::create('client_id', 'FoxyCart Client ID'), |
||
218 | TextField::create('client_secret', 'FoxyCart Client Secret'), |
||
219 | TextField::create('access_token', 'FoxyCart Access Token'), |
||
220 | TextField::create('refresh_token', 'FoxyCart Refresh Token'), |
||
221 | ]); |
||
350 |