Conditions | 14 |
Paths | 384 |
Total Lines | 223 |
Code Lines | 160 |
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 |
||
243 | public function getCMSFields() |
||
244 | { |
||
245 | $fields = parent::getCMSFields(); |
||
246 | //remove all unneccessary fields and tabs |
||
247 | $fields->removeByName("AlsoShowHere"); |
||
248 | $fields->removeByName("Tax"); |
||
249 | $fields->removeByName("Links"); |
||
250 | $fields->removeByName("Details"); |
||
251 | $fields->removeByName("Images"); |
||
252 | $fields->removeFieldFromTab('Root', 'Title'); |
||
253 | $fields->removeFieldFromTab('Root', 'URLSegment'); |
||
254 | $fields->removeFieldFromTab('Root', 'MenuTitle'); |
||
255 | $fields->removeFieldFromTab('Root', 'ShortDescription'); |
||
256 | $fields->removeFieldFromTab('Root', 'Content'); |
||
257 | $fields->removeFieldFromTab('Root', 'Metadata'); |
||
258 | $fields->removeFieldFromTab('Root', 'AddToCartLink'); |
||
259 | |||
260 | $fields->addFieldsToTab( |
||
261 | 'Root.Main', |
||
262 | array( |
||
263 | $allowPurchaseField = CheckboxField::create("AllowPurchase", "<strong>Allow product to be purchased</strong>"), |
||
264 | $sellinOnBehalf = CheckboxField::create("SellingOnBehalf", "<strong>Selling on behalf</strong>"), |
||
265 | $featuredProductField = CheckboxField::create('FeaturedProduct', _t('Product.FEATURED', '<strong>Featured Product</strong>')), |
||
266 | TextField::create('Title', 'Product Title'), |
||
267 | ) |
||
268 | ); |
||
269 | $secondhandProductCategories = SecondHandProductGroup::get(); |
||
270 | if ($secondhandProductCategories->count()) { |
||
271 | $fields->addFieldToTab( |
||
272 | 'Root.Main', |
||
273 | $categoryField = DropdownField::create( |
||
274 | 'ParentID', |
||
275 | 'Product Category', |
||
276 | $secondhandProductCategories->map() |
||
277 | ) |
||
278 | ); |
||
279 | } |
||
280 | $fields->addFieldsToTab( |
||
281 | 'Root.Main', |
||
282 | array( |
||
283 | ReadonlyField::create('CanBeSold', "For Sale", DBField::create_field('Boolean', $this->canPurchase())->Nice()), |
||
284 | ReadonlyField::create('CreatedNice', "First Entered", $this->getCreatedNice()), |
||
285 | TextField::create('InternalItemID', "Product Code"), |
||
286 | $salePriceField = NumericField::create('Price', 'Sale Price'), |
||
287 | $purchasePriceField = NumericField::create('PurchasePrice', 'Purchase Price'), |
||
288 | $serialNumberField = TextField::create('SerialNumber', 'Serial Number'), |
||
289 | $productQualityField = DropdownField::create( |
||
290 | "ProductQuality", |
||
291 | "Product Condition/Quality", |
||
292 | $this->dbObject('ProductQuality')->enumValues() |
||
293 | ), |
||
294 | $boxOrCaseField = DropdownField::create( |
||
295 | "IncludesBoxOrCase", |
||
296 | "Includes Box/Case", |
||
297 | $this->dbObject('IncludesBoxOrCase')->enumValues() |
||
298 | ), |
||
299 | $originalManualField = CheckboxField::create("OriginalManual", "Includes Original Manual"), |
||
300 | $contentField = TextField::create("ShortDescription", "Description"), |
||
301 | $boughtDate = DateField::create('DateItemWasBought', 'Date this item was bought'), |
||
302 | $soldDate = DateField::create('DateItemWasSold', 'Date this item was sold'), |
||
303 | $mainImageField = UploadField::create("Image", "Main Product Image"), |
||
304 | $additionalImagesField = UploadField::create("AdditionalImages", "More Images"), |
||
305 | $metaFieldDesc = TextareaField::create("MetaDescription", 'Meta Description') |
||
306 | ) |
||
307 | ); |
||
308 | $soldDate->setDisabled(true); |
||
309 | |||
310 | //set right titles and descriptions |
||
311 | $featuredProductField->setDescription('If this box is ticked then this product will appear in the "Featured Products" box on the home page'); |
||
312 | $allowPurchaseField->setDescription("This box must be ticked to allow a customer to purchase it"); |
||
313 | $sellinOnBehalf->setDescription('This box must be ticked if this product is being sold on behalf'); |
||
314 | $salePriceField->setRightTitle("Selling price"); |
||
315 | $purchasePriceField->setRightTitle("Price paid for the product"); |
||
316 | $serialNumberField->setRightTitle("Enter the serial number of the product here"); |
||
317 | $originalManualField->setDescription("Tick this box if the product includes the original manual, otherwise leave it empty"); |
||
318 | $boxOrCaseField->setRightTitle("Does this product come with a box, case or both?"); |
||
319 | $contentField->setRightTitle("Optional text only description, the maximum length of this description is 255 characters."); |
||
320 | $contentField->setMaxLength(255); |
||
321 | $qualityFieldDescription = "A <strong>Condition Rating Page</strong> has yet to be setup"; |
||
322 | $obj = $this->EcomConfig()->SecondHandExplanationPage(); |
||
323 | if ($obj->exists()) { |
||
324 | $qualityFieldDescription = 'An explanation of the ratings scale can be found by clicking this <a href="' . $obj->Link() . '">link</a>'; |
||
325 | } |
||
326 | $productQualityField->setRightTitle($qualityFieldDescription); |
||
327 | $boughtDate->setRightTitle('Date Format (dd-mm-YYYY). Example: 3rd of May 1992 should be entered as 03-05-1992'); |
||
328 | $mainImageField->setRightTitle( |
||
329 | "<strong>Upload the main image for the product here.</strong><br> |
||
330 | Recommended size: 810px wide x 418px high - but you can choose any width up to 810px, height must |
||
331 | ALWAYS BE 418px. Should be provided to FTP data upload as productcode.jpg - e.g. 1003040.jpg. |
||
332 | Images should be compressed up to 50%." |
||
333 | ); |
||
334 | $additionalImagesField->setRightTitle( |
||
335 | "<strong>Upload additional images here, you can upload as many as you want.</strong><br> |
||
336 | Recommended size: 810px wide x 418px high - but you can choose any width up to 810px, height must |
||
337 | ALWAYS BE 418px. Should be provided to FTP data upload as productcode.jpg - e.g. 1003040.jpg. |
||
338 | Images should be compressed up to 50%." |
||
339 | ); |
||
340 | //replace InternalItemID field with a read only field |
||
341 | $fields->replaceField( |
||
342 | 'InternalItemID', |
||
343 | $fields->dataFieldByName('InternalItemID')->performReadonlyTransformation() |
||
344 | ); |
||
345 | |||
346 | $lastEditedItems = SecondHandProduct::get()->sort('Created', 'DESC')->limit(100); |
||
347 | |||
348 | $lastItems = array( |
||
349 | 0 => '--- not based on previous sale ---' |
||
350 | ); |
||
351 | |||
352 | foreach ($lastEditedItems as $lastEditedItem) { |
||
353 | $details = $lastEditedItem->getSellerSummary(); |
||
354 | if ($details) { |
||
355 | $lastItems[$lastEditedItem->ID] = $details; |
||
356 | } |
||
357 | } |
||
358 | |||
359 | $fields->addFieldsToTab( |
||
360 | 'Root.SellersDetails', |
||
361 | array( |
||
362 | HeaderField::create('SellersDetails', 'Enter the details of the person who the product was purchased from'), |
||
363 | DropdownField::create( |
||
364 | 'BasedOnID', |
||
365 | 'Autocomplete from saved items', |
||
366 | $lastItems), |
||
367 | TextField::create('SellersName', 'Name'), |
||
368 | TextField::create('SellersPhone', 'Phone'), |
||
369 | TextField::create('SellersEmail', 'Email Address'), |
||
370 | DropdownField::create( |
||
371 | 'SellersIDType', |
||
372 | 'ID Type', |
||
373 | $this->dbObject('SellersIDType')->enumValues()), |
||
374 | TextField::create('SellersIDNumber', 'ID Number'), |
||
375 | DateField::create('SellersDateOfBirth', 'Date of Birth'), |
||
376 | DateField::create('SellersIDExpiryDate', 'ID Expiry Date'), |
||
377 | CheckboxField::create('SellersIDPhotocopy', 'ID Photocopy') |
||
378 | ) |
||
379 | ); |
||
380 | |||
381 | if (class_exists('GoogleAddressField')) { |
||
382 | $mappingArray = $this->Config()->get('fields_to_google_geocode_conversion'); |
||
383 | if (is_array($mappingArray) && count($mappingArray)) { |
||
384 | $fields->addFieldToTab( |
||
385 | 'Root.SellersDetails', |
||
386 | $geocodingField = new GoogleAddressField( |
||
387 | 'SellersAddressGeocodingField', |
||
388 | _t('OrderAddress.FIND_ADDRESS', 'Find address'), |
||
389 | Session::get('SellersAddressGeocodingFieldValue') |
||
390 | ) |
||
391 | ); |
||
392 | $geocodingField->setFieldMap($mappingArray); |
||
393 | |||
394 | $country_code = Config::inst()->get('SecondHandProduct', 'country_code'); |
||
395 | if ($country_code) { |
||
396 | $geocodingField->setRestrictToCountryCode($country_code); |
||
397 | } |
||
398 | //$geocodingField->setAlwaysShowFields(true); |
||
399 | } |
||
400 | } |
||
401 | |||
402 | $fields->addFieldsToTab( |
||
403 | 'Root.SellersDetails', |
||
404 | array( |
||
405 | TextField::create('SellersAddress', 'Address'), |
||
406 | TextField::create('SellersAddress2', 'Suburb'), |
||
407 | TextField::create('SellersCity', 'City/Town'), |
||
408 | TextField::create('SellersPostalCode', 'Postal Code'), |
||
409 | TextField::create('SellersRegionCode', 'Region Code'), |
||
410 | TextField::create('SellersCountry', 'Country'), |
||
411 | ) |
||
412 | ); |
||
413 | //add all fields to the main tab |
||
414 | $fields->addFieldToTab( |
||
415 | 'Root.SellersDetails', |
||
416 | EcommerceCMSButtonField::create( |
||
417 | 'PrintView', |
||
418 | $this->getPrintLink(), |
||
419 | 'Print Details', |
||
420 | $newWindow = true |
||
421 | ) |
||
422 | ); |
||
423 | if ($this->BasedOnID) { |
||
424 | $list = Config::inst()->get('SecondHandProduct', 'seller_summary_detail_fields'); |
||
425 | $labels = $this->FieldLabels(); |
||
426 | foreach ($list as $listField) { |
||
427 | $fields->replaceField( |
||
428 | $listField, |
||
429 | ReadonlyField::create( |
||
430 | $listField, |
||
431 | $fields->dataFieldByName($listField)->Title() |
||
432 | ) |
||
433 | ); |
||
434 | } |
||
435 | $fields->removeByName('SellersAddressGeocodingField'); |
||
436 | } |
||
437 | $fields->addFieldToTab( |
||
438 | 'Root.Categorisation', |
||
439 | $categoriesTable = $this->getProductGroupsTableField() |
||
440 | ); |
||
441 | |||
442 | // If the product has been sold all fields should be disabled |
||
443 | // Only the shop administrator is allowed to undo this. |
||
444 | if ($this->HasBeenSold()) { |
||
445 | $fields = $fields->makeReadonly(); |
||
446 | $fields->replaceField($categoriesTable->Name, $categoriesTable); |
||
447 | $categoriesTable->setConfig(GridFieldConfig_RecordViewer::create()); |
||
448 | $fields->replaceField( |
||
449 | 'EnquiresList', |
||
450 | GridField::create( |
||
451 | 'EnquiresList', |
||
452 | 'Enquiries List', |
||
453 | $this->PageEnquiries(), |
||
454 | GridFieldConfig_RecordViewer::create() |
||
455 | ) |
||
456 | ); |
||
457 | } |
||
458 | |||
459 | if ($this->HasBeenSold() && Permission::check('ADMIN')) { |
||
460 | $fields->replaceField('AllowPurchase', CheckboxField::create('AllowPurchase', '<strong>Allow product to be purchased</strong>')); |
||
461 | $fields->replaceField('DateItemWasSold', DateField::create('DateItemWasSold', 'Date this item was sold')); |
||
462 | } |
||
463 | |||
464 | return $fields; |
||
465 | } |
||
466 | |||
717 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.