From 9e046229d758a15b4be3017576153aa971653831 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 26 Mar 2020 10:08:47 +0100 Subject: [PATCH] wip #3520 @3 --- app/Templates/Catalog.php | 89 ------------------- app/Templates/Category.php | 27 ++++++ app/Templates/CategoryGroup.php | 84 +++++++++++++++++ .../views/pages/category_group.blade.php | 1 + 4 files changed, 112 insertions(+), 89 deletions(-) delete mode 100644 app/Templates/Catalog.php create mode 100644 app/Templates/Category.php create mode 100644 app/Templates/CategoryGroup.php create mode 100644 resources/views/pages/category_group.blade.php diff --git a/app/Templates/Catalog.php b/app/Templates/Catalog.php deleted file mode 100644 index d5bfa45..0000000 --- a/app/Templates/Catalog.php +++ /dev/null @@ -1,89 +0,0 @@ - __('Capteurs'), 'system' => __('Systèmes de mesure')]; - - Debugbar::startMeasure('nav_catalog_models', 'Request catalog models'); - Debugbar::startMeasure('nav_catalog_models_types', 'Request catalog models (types)'); - $productTypes = ProductType::whereVariant($menu->getVariant())->get(); - Debugbar::stopMeasure('nav_catalog_models_types'); - Debugbar::startMeasure('nav_catalog_models_products', 'Request catalog models (products)'); - $products = Product::whereVariant($menu->getVariant())->get(); - Debugbar::stopMeasure('nav_catalog_models_products'); - Debugbar::stopMeasure('nav_catalog_models'); - - $menu->setType('mega'); - - foreach ($families as $key => $family) { - $item = new VirtualItem(); - $item->setId('products_' . $key); - $item->setTitle($family); - $menu->addChild($item); - foreach ($productTypes as $productType) { - if ($productType->type !== $key) { - continue; - } - - $category = new PageItem(); - $category->setVariant($menu->getVariant()); - $category->setLocale($menu->getLocale()); - $category->initFromEntity($productType); - $category->setTitle($productType->name); - $category->setHref($productType->getSlugOrTitleAttribute()); - $category->setId('product_type/' . $productType->id); - $category->setController(['controller' => 'ProductController', 'action' => 'productList', 'params' => ['id' => $productType->id]]); - $category->showInAllMenus(); - - $count = 0; - foreach ($products as $product) { - if ($product->product_type != $productType->id) { - continue; - } - if (!$product->online) { - continue; - } - $detail = new PageItem(); - $detail->setLocale($menu->getLocale()); - $detail->setVariant($menu->getVariant()); - $detail->initFromEntity($product); - $detail->setTitle($product->name); - $detail->setHref($product->getSlugOrTitleAttribute()); - $detail->setId('product/' . $product->id); - $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]); - $detail->hideInAllMenus(); - $category->addChild($detail); - $count++; - } - - if ($count) { - $item->addChild($category); - } - } - } - Debugbar::stopMeasure('nav_catalog'); - } - -} diff --git a/app/Templates/Category.php b/app/Templates/Category.php new file mode 100644 index 0000000..ee72dee --- /dev/null +++ b/app/Templates/Category.php @@ -0,0 +1,27 @@ +addField(['name' => 'category', + 'type' => 'SelectFromModel', + 'optionsmodel' => ProductType::class, + 'label' => 'Categorie', + 'tab' => 'Catégorie']); + } + +} diff --git a/app/Templates/CategoryGroup.php b/app/Templates/CategoryGroup.php new file mode 100644 index 0000000..ff56872 --- /dev/null +++ b/app/Templates/CategoryGroup.php @@ -0,0 +1,84 @@ +addField(['name' => 'categories', + 'type' => 'SelectFromModel', + 'optionsmodel' => ProductType::class, + 'label' => 'Categories', + 'tab' => 'Catégories', + 'allows_multiple' => true, + 'order' => true]); + } + + public function setMenuChildren($menu) + { + $menu->setType('mega'); + + $productTypes = ProductType::whereVariant($menu->getVariant())->get(); + $products = Product::whereVariant($menu->getVariant())->get(); + + $categories = $menu->getPageData()->get('categories'); + if (null === $categories || !$categories) { + return; + } + foreach ($productTypes as $productType) { + if (!in_array($productType->id, $categories)) { + continue; + } + $category = new PageItem(); + $category->setVariant($menu->getVariant()); + $category->setLocale($menu->getLocale()); + $category->initFromEntity($productType); + $category->setTitle($productType->name); + $category->setHref($productType->getSlugOrTitleAttribute()); + $category->setId('product_type/' . $productType->id); + $category->setController(['controller' => 'ProductController', 'action' => 'productList', 'params' => ['id' => $productType->id]]); + $category->showInAllMenus(); + + $count = 0; + foreach ($products as $product) { + if ($product->product_type != $productType->id) { + continue; + } + if (!$product->online) { + continue; + } + $detail = new PageItem(); + $detail->setLocale($menu->getLocale()); + $detail->setVariant($menu->getVariant()); + $detail->initFromEntity($product); + $detail->setTitle($product->name); + $detail->setHref($product->getSlugOrTitleAttribute()); + $detail->setId('product/' . $product->id); + $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]); + $detail->hideInAllMenus(); + $category->addChild($detail); + $count++; + } + + if ($count) { + $menu->addChild($category); + } + } + } + +} diff --git a/resources/views/pages/category_group.blade.php b/resources/views/pages/category_group.blade.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/resources/views/pages/category_group.blade.php @@ -0,0 +1 @@ +