|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverShop\Model\Variation; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
|
6
|
|
|
use SilverStripe\ORM\DataObject; |
|
7
|
|
|
use SilverStripe\ORM\ManyManyList; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Product Attribute Value |
|
11
|
|
|
* The actual values for a type of product attribute. |
|
12
|
|
|
* eg: red, green, blue... 12, 13, 15 |
|
13
|
|
|
* |
|
14
|
|
|
* @property string $Value |
|
15
|
|
|
* @property int $Sort |
|
16
|
|
|
* @method AttributeType Type() |
|
17
|
|
|
* @method Variation[]|ManyManyList ProductVariation() |
|
18
|
|
|
*/ |
|
19
|
|
|
class AttributeValue extends DataObject |
|
20
|
|
|
{ |
|
21
|
|
|
private static $db = [ |
|
|
|
|
|
|
22
|
|
|
'Value' => 'Varchar', |
|
23
|
|
|
'Sort' => 'Int', |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
27
|
|
|
'Type' => AttributeType::class, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
private static $belongs_many_many = [ |
|
|
|
|
|
|
31
|
|
|
'ProductVariation' => Variation::class, |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
private static $summary_fields = [ |
|
|
|
|
|
|
35
|
|
|
'Value' => 'Value', |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
private static $indexes = [ |
|
|
|
|
|
|
39
|
|
|
'LastEdited' => true, |
|
40
|
|
|
'Sort' => true, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
private static $table_name = 'SilverShop_AttributeValue'; |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
private static $default_sort = '"TypeID" ASC, "Sort" ASC, "Value" ASC'; |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
private static $singular_name = 'Value'; |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
private static $plural_name = 'Values'; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function getCMSFields() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->beforeUpdateCMSFields( |
|
54
|
|
|
function (FieldList $fields) { |
|
55
|
|
|
|
|
56
|
|
|
$fields->removeByName('TypeID'); |
|
57
|
|
|
$fields->removeByName('Sort'); |
|
58
|
|
|
} |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
return parent::getCMSFields(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|