{
protected static $_specifications = null;
protected static $_productTypes = null;
+ protected static $_specificationFields = null;
protected $table = 'catalog_products';
{
self::_getRelatedEntities();
- foreach (self::$_specifications as $spec) {
- $in = [];
- foreach (self::$_productTypes as $type) {
- $lists = [$type->specifications, $type->filters];
- foreach ($lists as $list) {
- if (!is_array($list)) {
- continue;
- }
- foreach ($list as $order => $rel_specification) {
- if ($spec->id == $rel_specification) {
- if (!in_array($type->getIdValue(), $in)) {
- $in[] = ['id' => $type->getIdValue(), 'order' => $order];
+ if (null === self::$_specificationFields) {
+ foreach (self::$_specifications as $spec) {
+ $in = [];
+ foreach (self::$_productTypes as $type) {
+ $lists = [$type->specifications, $type->filters];
+ foreach ($lists as $list) {
+ if (!is_array($list)) {
+ continue;
+ }
+ foreach ($list as $order => $rel_specification) {
+ if ($spec->id == $rel_specification) {
+ if (!in_array($type->getIdValue(), $in)) {
+ $in[] = ['id' => $type->getIdValue(), 'order' => $order];
+ }
+ break;
}
- break;
}
}
}
- }
- 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 (!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'] = 'Tags';
+ 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'] = 'Tags';
// $params['entity_singular'] = 'valeur';
// $params['columns'] = ['value' => 'Value'];
- } else {
- $params['type'] = 'SelectFromArray';
- $options = [];
- if (is_string($spec->options)) {
- $decoded = [];
- if ($spec->options) {
- $decoded = json_decode($spec->options);
- }
} else {
- $decoded = $spec->options;
- }
- if (is_array($decoded)) {
- foreach ($decoded as $option) {
- if (isset($option->fr)) {
- $options[] = $option->fr;
+ $params['type'] = 'SelectFromArray';
+ $options = [];
+ if (is_string($spec->options)) {
+ $decoded = [];
+ if ($spec->options) {
+ $decoded = json_decode($spec->options);
}
+ } else {
+ $decoded = $spec->options;
}
+ if (is_array($decoded)) {
+ foreach ($decoded as $option) {
+ if (isset($option->fr)) {
+ $options[] = $option->fr;
+ }
+ }
+ }
+ $params['options'] = $options;
}
- $params['options'] = $options;
+ self::$_specificationFields[] = $params;
}
- $this->addField($params);
}
-
+ foreach (self::$_specificationFields as $specificationField) {
+ $this->addField($specificationField);
+ }
}
public function getDocuments()
public function setMenuChildren($menu)
{
+ \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog', 'Make Products sub navigation');
parent::setMenuChildren($menu);
$families = ['captor' => __('Capteurs'), 'system' => __('Systèmes de mesure')];
+ \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models', 'Request catalog models');
+ \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models_types', 'Request catalog models (types)');
$productTypes = ProductType::all();
+ \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models_types');
+ \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models_products', 'Request catalog models (products)');
$products = Product::all();
+ \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models_products');
+ \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models');
+
$menu->setType('mega');
foreach ($families as $key => $family) {
}
}
}
+ \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog');
}
}