1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Create Product Models in the Product Category and use these for the dropdown when editing a product |
4
|
|
|
* (instead of a textfield). |
5
|
|
|
* In addition, loop over the models on the Product Category Page |
6
|
|
|
*/ |
7
|
|
|
namespace AntonyThorpe\SilverShopProductModel; |
8
|
|
|
|
9
|
|
|
use SilverShop\Page\ProductCategory; |
|
|
|
|
10
|
|
|
use SilverStripe\Forms\FieldList; |
|
|
|
|
11
|
|
|
use SilverStripe\Forms\TextField; |
|
|
|
|
12
|
|
|
use SilverStripe\ORM\DataObject; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class ProductModel extends DataObject |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @config |
18
|
|
|
*/ |
19
|
|
|
private static array $db = [ |
|
|
|
|
20
|
|
|
'Title' => 'Varchar(100)', |
21
|
|
|
'Description' => 'Varchar(255)', |
22
|
|
|
'Sort' => 'Int' |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @config |
27
|
|
|
*/ |
28
|
|
|
private static array $has_one = [ |
|
|
|
|
29
|
|
|
'ProductCategory' => ProductCategory::class |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @config |
34
|
|
|
*/ |
35
|
|
|
private static array $required_fields = ['Title']; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @config |
39
|
|
|
*/ |
40
|
|
|
private static string $table_name = 'SilverShop_ProductModel'; |
|
|
|
|
41
|
|
|
|
42
|
|
|
public function getCMSFields() |
43
|
|
|
{ |
44
|
|
|
return FieldList::create( |
45
|
|
|
TextField::create('Title', _t(self::class . 'Title', 'Model Title')) |
|
|
|
|
46
|
|
|
->setMaxLength(100), |
47
|
|
|
TextField::create('Description', _t(self::class . 'Description', 'Model Description')) |
48
|
|
|
->setRightTitle(_t(self::class . 'DescriptionRightTitle', 'An additional description if needed by the website')) |
49
|
|
|
->setMaxLength(255) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function validate() |
54
|
|
|
{ |
55
|
|
|
$result = parent::validate(); |
56
|
|
|
|
57
|
|
|
if (empty($this->Title)) { |
58
|
|
|
$result->addError( |
59
|
|
|
_t( |
|
|
|
|
60
|
|
|
self::class . 'ValidationMessageTitle', |
61
|
|
|
'ProductModel Class validation - missing the Model Title field' |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (empty($this->ProductCategoryID)) { |
67
|
|
|
$result->addError( |
68
|
|
|
_t( |
69
|
|
|
self::class . 'ValidationMessageProductCategoryID', |
70
|
|
|
'ProductModel Class validation - missing ProductCategoryID field' |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $result; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths