$this->addField(['name' => 'product_type',
'label' => 'Type de produit',
'type' => 'SelectFromModel',
- 'model' => 'App\Models\ProductType',
+ 'optionsmodel' => 'App\Models\ProductType',
'column' => true,
'tab' => 'Spécifications']);
- $specifications = Specification::all();
- $types = ProductType::all();
- foreach ($specifications as $spec) {
- $in = [];
- foreach ($types as $type) {
- foreach ($type->specifications as $rel_specification) {
- if ($spec->id == $rel_specification->id) {
- $in[] = $type->id;
- break;
- }
- }
- foreach ($type->filters as $rel_specification) {
- if ($spec->id == $rel_specification->id) {
- $in[] = $type->id;
- break;
- }
- }
- $in = array_unique($in);
- }
- if (!count($in)) {
- continue;
- }
- $params = ['tab' => 'Spécifications',
- 'name' => 's_' . Str::snake($spec->name),
- 'label' => $spec->name,
- 'fake' => true,
- 'store_in' => 'specifications',
- 'when' => ['product_type' => $in],
- ];
-
- if ($spec->prefix) {
- $params['prefix'] = $spec->prefix;
- }
- if ($spec->unit) {
- $params['suffix'] = $spec->unit;
- }
-
- if ($spec->type == 'numeric') {
- $params['type'] = 'Number';
- } else if ($spec->type == 'range') {
- $params['type'] = 'Range';
- } else if ($spec->type == 'text') {
- $params['type'] = 'Text';
- } else if ($spec->type == 'numeric_list') {
- $params['type'] = 'Table';
- $params['entity_singular'] = 'valeur';
- $params['columns'] = ['value' => 'Value'];
- } else {
- $params['type'] = 'SelectFromArray';
- $options = [];
- if (is_string($spec->options)) {
- $decoded = json_decode($spec->options);
- }
- foreach ($decoded as $option) {
- $options[] = $option->name;
- }
- $params['options'] = $options;
- }
- $this->addField($params);
- }
-
+ $this->addSpecifications();
$this->addField(['name' => 'slug',
'type' => 'Slug',
'tab' => 'Textes']);
}
+
+ public function addSpecifications()
+ {
+
+ $specifications = Specification::all();
+ $types = ProductType::all();
+ foreach ($specifications as $spec) {
+ $in = [];
+ foreach ($types as $type) {
+ $lists = [$type->specifications, $type->filters];
+ foreach ($lists as $list) {
+ if (!is_array($list)) {
+ continue;
+ }
+ foreach ($list as $rel_specification) {
+ if ($spec->id == $rel_specification) {
+ if (!in_array($type->getIdValue(), $in)) {
+ $in[] = $type->getIdValue();
+ }
+ break;
+ }
+ }
+ }
+ $in = array_unique($in);
+ }
+ if (!count($in)) {
+ continue;
+ }
+ $params = ['tab' => 'Spécifications',
+ 'name' => 's_' . Str::snake($spec->name),
+ 'label' => $spec->name,
+ 'fake' => true,
+ 'store_in' => 'specifications',
+ 'when' => ['product_type' => $in],
+ ];
+
+ if ($spec->prefix) {
+ $params['prefix'] = $spec->prefix;
+ }
+ if ($spec->unit) {
+ $params['suffix'] = $spec->unit;
+ }
+
+ if ($spec->type == 'numeric') {
+ $params['type'] = 'Number';
+ } else if ($spec->type == 'range') {
+ $params['type'] = 'Range';
+ } else if ($spec->type == 'text') {
+ $params['type'] = 'Text';
+ } else if ($spec->type == 'numeric_list') {
+ $params['type'] = 'Table';
+ $params['entity_singular'] = 'valeur';
+ $params['columns'] = ['value' => 'Value'];
+ } else {
+ $params['type'] = 'SelectFromArray';
+ $options = [];
+ if (is_string($spec->options)) {
+ $decoded = json_decode($spec->options);
+ }
+ if (is_array($decoded)) {
+ foreach ($decoded as $option) {
+ $options[] = $option->name;
+ }
+
+ }
+ $params['options'] = $options;
+ }
+ $this->addField($params);
+ }
+
+ }
}
$this->addField(['name' => 'specifications',
'label' => 'Spécifications',
- 'type' => 'SelectFromModelMultiple',
- 'model' => "App\Models\Specification",
+ 'type' => 'SelectFromModel',
+ 'optionsmodel' => "App\Models\Specification",
+ 'order' => true,
+ 'multiple' => true,
]);
$this->addField(['name' => 'filters',
'label' => 'Spécifications utilisées comme filtre',
- 'type' => 'SelectFromModelMultiple',
- 'model' => 'App\Models\Specification']);
- }
-
- public function specifications()
- {
- return $this->relationship('specifications');
- }
-
- public function filters()
- {
- return $this->relationship('filters');
+ 'type' => 'SelectFromModel',
+ 'optionsmodel' => 'App\Models\Specification',
+ 'order' => true,
+ 'multiple' => true]);
}
}