| Conditions | 2 |
| Paths | 2 |
| Total Lines | 194 |
| Code Lines | 146 |
| 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 |
||
| 97 | public function getCMSFields() |
||
| 98 | { |
||
| 99 | $fields = FieldList::create( |
||
| 100 | TabSet::create( |
||
| 101 | 'Root', |
||
| 102 | $tabMain = Tab::create( |
||
| 103 | 'Main' |
||
| 104 | ) |
||
| 105 | ), |
||
| 106 | HiddenField::create('ID') |
||
| 107 | ); |
||
| 108 | $tabMain->setTitle('Settings'); |
||
| 109 | |||
| 110 | // settings tab |
||
| 111 | $fields->addFieldsToTab('Root.Main', array( |
||
| 112 | // Store Details |
||
| 113 | HeaderField::create('StoreDetails', _t('FoxyStripeSiteConfig.StoreDetails', 'Store Settings'), 3), |
||
| 114 | LiteralField::create('DetailsIntro', _t( |
||
| 115 | 'FoxyStripeSiteConfig.DetailsIntro', |
||
| 116 | '<p>Maps to data in your |
||
| 117 | <a href="https://admin.foxycart.com/admin.php?ThisAction=EditStore" target="_blank"> |
||
| 118 | FoxyCart store settings |
||
| 119 | </a>.' |
||
| 120 | )), |
||
| 121 | TextField::create('StoreTitle') |
||
| 122 | ->setTitle(_t('FoxyStripeSiteConfig.StoreTitle', 'Store Name')) |
||
| 123 | ->setDescription(_t( |
||
| 124 | 'FoxyStripeSiteConfig.StoreTitleDescription', |
||
| 125 | 'The name of your store as you\'d like it displayed to your customers' |
||
| 126 | )), |
||
| 127 | TextField::create('StoreName') |
||
| 128 | ->setTitle(_t('FoxyStripeSiteConfig.StoreName', 'Store Domain')) |
||
| 129 | ->setDescription(_t( |
||
| 130 | 'FoxyStripeSiteConfig.StoreNameDescription', |
||
| 131 | 'This is a unique FoxyCart subdomain for your cart, checkout, and receipt' |
||
| 132 | )), |
||
| 133 | TextField::create('StoreURL') |
||
| 134 | ->setTitle(_t('FoxyStripeSiteConfig.StoreURL', 'Store URL')) |
||
| 135 | ->setDescription(_t( |
||
| 136 | 'FoxyStripeSiteConfig.StoreURLDescription', |
||
| 137 | 'The URL of your online store' |
||
| 138 | )), |
||
| 139 | TextField::create('ReceiptURL') |
||
| 140 | ->setTitle(_t('FoxyStripeSiteConfig.ReceiptURL', 'Receipt URL')) |
||
| 141 | ->setDescription(_t( |
||
| 142 | 'FoxyStripeSiteConfig.ReceiptURLDescription', |
||
| 143 | 'By default, FoxyCart sends customers back to the page referrer after completing a purchase. |
||
| 144 | Instead, you can set a specific URL here.' |
||
| 145 | )), |
||
| 146 | TextField::create('StoreEmail') |
||
| 147 | ->setTitle(_t('FoxyStripeSiteConfig.StoreEmail', 'Store Email')) |
||
| 148 | ->setDescription(_t( |
||
| 149 | 'FoxyStripeSiteConfig.StoreEmailDescription', |
||
| 150 | 'This is the email address of your store. By default, this will be the from address for your |
||
| 151 | store receipts. ' |
||
| 152 | )), |
||
| 153 | TextField::create('FromEmail') |
||
| 154 | ->setTitle(_t('FoxyStripeSiteConfig.FromEmail', 'From Email')) |
||
| 155 | ->setDescription(_t( |
||
| 156 | 'FoxyStripeSiteConfig.FromEmailDescription', |
||
| 157 | 'Used for when you want to specify a different from email than your store\'s email address' |
||
| 158 | )), |
||
| 159 | TextField::create('StorePostalCode', 'Postal Code'), |
||
| 160 | CountryDropdownField::create('StoreCountry', 'Country'), |
||
| 161 | TextField::create('StoreRegion', 'State/Region'), |
||
| 162 | TextField::create('StoreLocaleCode', 'Locale Code') |
||
| 163 | ->setDescription('example: en_US'), |
||
| 164 | TextField::create('StoreTimezone', 'Store timezone'), |
||
| 165 | TextField::create('StoreLogoURL', 'Logo URL') |
||
| 166 | ->setAttribute('placeholder', 'http://'), |
||
| 167 | )); |
||
| 168 | |||
| 169 | $fields->addFieldsToTab('Root.Advanced', [ |
||
| 170 | HeaderField::create('AdvanceHeader', _t( |
||
| 171 | 'FoxyStripeSiteConfig.AdvancedHeader', |
||
| 172 | 'Advanced Settings' |
||
| 173 | ), 3), |
||
| 174 | LiteralField::create('AdvancedIntro', _t( |
||
| 175 | 'FoxyStripeSiteConfig.AdvancedIntro', |
||
| 176 | '<p>Maps to data in your |
||
| 177 | <a href="https://admin.foxycart.com/admin.php?ThisAction=EditAdvancedFeatures" target="_blank"> |
||
| 178 | FoxyCart advanced store settings |
||
| 179 | </a>.</p>' |
||
| 180 | )), |
||
| 181 | DropdownField::create('CheckoutType', 'Checkout Type', $this->getCheckoutTypes()), |
||
| 182 | CheckboxField::create('BccEmail', 'BCC Admin Email') |
||
| 183 | ->setDescription('bcc all receipts to store\'s email address'), |
||
| 184 | CheckboxField::create('UseWebhook', 'Use Webhook') |
||
| 185 | ->setDescription('record order history in CMS, allows customers to view their order history'), |
||
| 186 | ReadonlyField::create('WebhookURL', 'Webhook URL', self::getDataFeedLink()), |
||
| 187 | ReadonlyField::create('StoreKey', 'Webhook Key', self::getDataFeedLink()), |
||
| 188 | CheckboxField::create('CartValidation', 'Use cart validation'), |
||
| 189 | CheckboxField::create('UseSingleSignOn', 'Use single sign on') |
||
| 190 | ->setDescription('Sync user accounts between FoxyCart and your website'), |
||
| 191 | ReadonlyField::create('SingleSignOnURL', 'Single sign on URL', self::getSSOLink()), |
||
| 192 | CheckboxField::create('AllowMultiship', 'Allow multiple shipments per order'), |
||
| 193 | ]); |
||
| 194 | |||
| 195 | // configuration warning |
||
| 196 | if (FoxyCart::store_name_warning() !== null) { |
||
| 197 | $fields->insertBefore(LiteralField::create( |
||
| 198 | 'StoreSubDomainHeaderWarning', |
||
| 199 | _t( |
||
| 200 | 'FoxyStripeSiteConfig.StoreSubDomainHeadingWarning', |
||
| 201 | '<p class="message error">Store Domain must be entered below |
||
| 202 | </a></p>' |
||
| 203 | ) |
||
| 204 | ), 'StoreDetails'); |
||
| 205 | } |
||
| 206 | |||
| 207 | // products tab |
||
| 208 | $fields->addFieldsToTab('Root.Products', array( |
||
| 209 | HeaderField::create('ProductHeader', _t( |
||
| 210 | 'FoxyStripeSiteConfig.ProductHeader', |
||
| 211 | 'Products' |
||
| 212 | ), 3), |
||
| 213 | CheckboxField::create('MultiGroup') |
||
| 214 | ->setTitle(_t('FoxyStripeSiteConfig.MultiGroup', 'Multiple Groups')) |
||
| 215 | ->setDescription(_t( |
||
| 216 | 'FoxyStripeSiteConfig.MultiGroupDescription', |
||
| 217 | 'Allows products to be shown in multiple Product Groups' |
||
| 218 | )), |
||
| 219 | HeaderField::create('ProductGroupHD', _t( |
||
| 220 | 'FoxyStripeSiteConfig.ProductGroupHD', |
||
| 221 | 'Product Groups' |
||
| 222 | ), 3), |
||
| 223 | NumericField::create('ProductLimit') |
||
| 224 | ->setTitle(_t('FoxyStripeSiteConfig.ProductLimit', 'Products per Page')) |
||
| 225 | ->setDescription(_t( |
||
| 226 | 'FoxyStripeSiteConfig.ProductLimitDescription', |
||
| 227 | 'Number of Products to show per page on a Product Group' |
||
| 228 | )), |
||
| 229 | HeaderField::create('ProductQuantityHD', _t( |
||
| 230 | 'FoxyStripeSiteConfig.ProductQuantityHD', |
||
| 231 | 'Product Form Max Quantity' |
||
| 232 | ), 3), |
||
| 233 | NumericField::create('MaxQuantity') |
||
| 234 | ->setTitle(_t('FoxyStripeSiteConfig.MaxQuantity', 'Max Quantity')) |
||
| 235 | ->setDescription(_t( |
||
| 236 | 'FoxyStripeSiteConfig.MaxQuantityDescription', |
||
| 237 | 'Sets max quantity for product form dropdown (add to cart form - default 10)' |
||
| 238 | )), |
||
| 239 | )); |
||
| 240 | |||
| 241 | // categories tab |
||
| 242 | $fields->addFieldsToTab('Root.Categories', array( |
||
| 243 | HeaderField::create('CategoryHD', _t('FoxyStripeSiteConfig.CategoryHD', 'FoxyStripe Categories'), 3), |
||
| 244 | LiteralField::create('CategoryDescrip', _t( |
||
| 245 | 'FoxyStripeSiteConfig.CategoryDescrip', |
||
| 246 | '<p>FoxyCart Categories offer a way to give products additional behaviors that cannot be |
||
| 247 | accomplished by product options alone, including category specific coupon codes, |
||
| 248 | shipping and handling fees, and email receipts. |
||
| 249 | <a href="https://wiki.foxycart.com/v/2.0/categories" target="_blank"> |
||
| 250 | Learn More |
||
| 251 | </a></p> |
||
| 252 | <p>Categories you\'ve created in FoxyStripe must also be created in your |
||
| 253 | <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" |
||
| 254 | target="_blank">FoxyCart Categories</a> admin panel.</p>' |
||
| 255 | )), |
||
| 256 | GridField::create( |
||
| 257 | 'ProductCategory', |
||
| 258 | _t('FoxyStripeSiteConfig.ProductCategory', 'FoxyCart Categories'), |
||
| 259 | ProductCategory::get(), |
||
| 260 | GridFieldConfig_RecordEditor::create() |
||
| 261 | ), |
||
| 262 | )); |
||
| 263 | |||
| 264 | // option groups tab |
||
| 265 | $fields->addFieldsToTab('Root.Groups', array( |
||
| 266 | HeaderField::create('OptionGroupsHead', _t('FoxyStripeSiteConfig', 'Product Option Groups'), 3), |
||
| 267 | LiteralField::create('OptionGroupsDescrip', _t( |
||
| 268 | 'FoxyStripeSiteConfig.OptionGroupsDescrip', |
||
| 269 | '<p>Product Option Groups allow you to name a set of product options.</p>' |
||
| 270 | )), |
||
| 271 | GridField::create( |
||
| 272 | 'OptionGroup', |
||
| 273 | _t('FoxyStripeSiteConfig.OptionGroup', 'Product Option Groups'), |
||
| 274 | OptionGroup::get(), |
||
| 275 | GridFieldConfig_RecordEditor::create() |
||
| 276 | ), |
||
| 277 | )); |
||
| 278 | |||
| 279 | // api tab |
||
| 280 | $fields->addFieldsToTab('Root.API', [ |
||
| 281 | HeaderField::create('APIHD', 'FoxyCart API Settings', 3), |
||
| 282 | TextField::create('client_id', 'FoxyCart Client ID'), |
||
| 283 | TextField::create('client_secret', 'FoxyCart Client Secret'), |
||
| 284 | TextField::create('access_token', 'FoxyCart Access Token'), |
||
| 285 | TextField::create('refresh_token', 'FoxyCart Refresh Token'), |
||
| 286 | ]); |
||
| 287 | |||
| 288 | $this->extend('updateCMSFields', $fields); |
||
| 289 | |||
| 290 | return $fields; |
||
| 291 | } |
||
| 530 | } |