1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AntonyThorpe\SilverShopProductModel; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
6
|
|
|
use SilverStripe\ORM\ArrayLib; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\ORM\DataExtension; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Add model dropdown to Product where available |
12
|
|
|
* Extends SilverShop\Page\Product |
13
|
|
|
*/ |
14
|
|
|
class ProductExtension extends DataExtension |
15
|
|
|
{ |
16
|
|
|
public function updateCMSFields(FieldList $fields) |
17
|
|
|
{ |
18
|
|
|
// if there are Models set in the Product Category then use a dropdown to select |
19
|
|
|
if ($this->owner->Parent && $this->owner->Parent->ProductModels()->count()) { |
20
|
|
|
$fields->replaceField( |
21
|
|
|
'Model', |
22
|
|
|
DropdownField::create( |
23
|
|
|
'Model', |
24
|
|
|
_t(self::class . 'ModelRequired', 'Model (required)'), |
25
|
|
|
ArrayLib::valuekey($this->owner->Parent->ProductModels()->column('Title')) |
26
|
|
|
) |
27
|
|
|
->setEmptyString(_t(self::class . 'ModelSelect', 'Select...')) |
28
|
|
|
->setAttribute('Required', true) |
29
|
|
|
); |
30
|
|
|
} else { |
31
|
|
|
// Update Model for extended length |
32
|
|
|
// see config.yml for updated db settings |
33
|
|
|
$model = $fields->dataFieldByName('Model'); |
34
|
|
|
$model->setMaxLength(100); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* For the template within the GroupedList, provide the model's Description recorded within the ProductModel Class |
40
|
|
|
* @return string description of the model |
41
|
|
|
*/ |
42
|
|
|
public function getModelDescription() |
43
|
|
|
{ |
44
|
|
|
$productmodels = $this->owner->Parent->ProductModels(); |
|
|
|
|
45
|
|
|
if ($productmodels->count() && $model = $this->owner->Model) { |
46
|
|
|
return $productmodels->find('Title', $model)->Description; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.