1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @description: resets fields in the product group class to "inherit" in case their value does not exist. |
6
|
|
|
* |
7
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
8
|
|
|
* @package: ecommerce |
9
|
|
|
* @sub-package: tasks |
10
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
11
|
|
|
**/ |
12
|
|
|
class EcommerceTaskSetDefaultProductGroupValues extends BuildTask |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
protected $title = 'Set Default Product Group Values'; |
15
|
|
|
|
16
|
|
|
protected $description = 'Set default product group values such as DefaultSortOrder.'; |
17
|
|
|
|
18
|
|
|
protected $fieldsToCheck = array( |
19
|
|
|
'SORT' => 'DefaultSortOrder', |
20
|
|
|
'FILTER' => 'DefaultFilter', |
21
|
|
|
'DISPLAY' => 'DisplayStyle', |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
public function run($request) |
25
|
|
|
{ |
26
|
|
|
$productGroup = ProductGroup::get()->First(); |
27
|
|
|
if ($productGroup) { |
28
|
|
|
foreach ($this->fieldsToCheck as $method => $fieldName) { |
29
|
|
|
$acceptableValuesArray = array_flip($productGroup->getUserPreferencesOptionsForDropdown($method)); |
30
|
|
|
$this->checkField($fieldName, $acceptableValuesArray, 'inherit'); |
31
|
|
|
} |
32
|
|
|
} else { |
33
|
|
|
DB::alteration_message('There are no ProductGroup pages to correct', 'created'); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function checkField($fieldName, $acceptableValuesArray, $resetValue) |
38
|
|
|
{ |
39
|
|
|
$faultyProductGroups = ProductGroup::get() |
40
|
|
|
->exclude(array($fieldName => $acceptableValuesArray)); |
41
|
|
|
if ($faultyProductGroups->count()) { |
42
|
|
|
foreach ($faultyProductGroups as $faultyProductGroup) { |
43
|
|
|
$faultyProductGroup->$fieldName = $resetValue; |
44
|
|
|
$faultyProductGroup->writeToStage('Stage'); |
45
|
|
|
$faultyProductGroup->publish('Stage', 'Live'); |
46
|
|
|
DB::alteration_message("Reset $fieldName for ".$faultyProductGroup->Title, 'created'); |
47
|
|
|
} |
48
|
|
|
} else { |
49
|
|
|
DB::alteration_message("Could not find any faulty records for ProductGroup.$fieldName"); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
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.