]> _ Git - pmi.git/commitdiff
#2878
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 Jul 2019 19:25:37 +0000 (21:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 Jul 2019 19:25:37 +0000 (21:25 +0200)
app/Http/Controllers/ProductController.php
app/Models/Producttype.php
app/Templates/Catalog.php
routes/web.php

index 70045d086fa5060167d765a88c700db24fb19f66..1efe0b0b73b1a8553669986d0b5b7801b6cf4ed0 100644 (file)
@@ -4,10 +4,29 @@
 namespace App\Http\Controllers;
 
 use App\Models\Product;
+use App\Models\ProductType;
 use Cubist\Backpack\app\Http\Controllers\CubistFrontController;
 
 class ProductController extends CubistFrontController
 {
+    public function productList($id)
+    {
+        $productType = ProductType::find($id);
+        if (!$productType) {
+            $this->_404();
+        }
+
+        $this->data['title'] = $productType->name;
+        $this->data['product_type'] = $productType->getPageData();
+        $this->data['products'] = [];
+        $products = Product::where('product_type', $id)->get();
+        foreach ($products as $item) {
+            $this->data['products'][$item->id] = $item->getPageData();
+        }
+
+        return view('pages.products', $this->data);
+    }
+
     public function productDetails($id)
     {
         $product = Product::find($id);
@@ -17,7 +36,7 @@ class ProductController extends CubistFrontController
         }
 
         $this->data['title'] = $product->title;
-        $this->data['product'] = $product->withFakes();
+        $this->data['product'] = $product->getPageData();
 
         return view('pages.product-detail', $this->data);
     }
index f7b2793be46a70ab808ae0ad939e42656e01782a..d0f68d9a84fb8b4c42e75cf01637d6985abf82e5 100644 (file)
@@ -21,6 +21,10 @@ class ProductType extends CubistMagicModel
             'type' => 'Text',
             'column' => true]);
 
+        $this->addField(['name' => 'slug',
+            'label' => 'Slug',
+            'type' => 'Slug']);
+
         $this->addField([
                 'name' => 'type',
                 'label' => 'Famille de produits',
index 61aa406f03c0bd70bf52799430387d0d4d864ec1..02bc6bf60913ead62bf4325269f73c51a19a5f05 100644 (file)
@@ -3,11 +3,46 @@
 
 namespace App\Templates;
 
+use App\Models\ProductType;
+use Cubist\Backpack\app\Magic\Menu\Item;
+use Cubist\Backpack\app\Magic\Menu\VirtualItem;
+use Cubist\Backpack\app\Template\TemplateAbstract;
 
-class Catalog extends Base
+class Catalog extends TemplateAbstract
 {
+    protected $_virtual = true;
+
     public function getName()
     {
         return 'Catalogue de produits';
     }
+
+    public function setMenuChildren($menu)
+    {
+        parent::setMenuChildren($menu);
+
+        $families = ['captor' => __('Capteurs'), 'system' => __('Systèmes de mesure')];
+
+        $productTypes = ProductType::all();
+        $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 Item();
+                $category->setTitle($productType->name);
+                $category->setHref($productType->slug);
+                $category->setId('product_type_' . $productType->id);
+                $category->setController(['controller' => 'ProductController', 'action' => 'productList', 'params' => ['id' => $productType->id]]);
+                $item->addChild($category);
+            }
+        }
+    }
+
 }
index 25e01e823f1527902e5fd74ad03cd4da961f8855..b8d6836ca2a3cc3091f290fd7c2066721715de36 100644 (file)
@@ -1,32 +1,8 @@
 <?php
 
-/*
-|--------------------------------------------------------------------------
-| Web Routes
-|--------------------------------------------------------------------------
-|
-| Here is where you can register web routes for your application. These
-| routes are loaded by the RouteServiceProvider within a group which
-| contains the "web" middleware group. Now create something great!
-|
-*/
+Route::get('cubist/product/{id}', ['uses' => 'ProductController@productDetails']);
+Route::get('cubist/producttype/{id}', ['uses' => 'ProductController@productList']);
+Route::get('cubist/page/{slug}', ['uses' => 'PageController@index']);
 
-Route::get('/products/{category}/{id}', function ($category, $id = null) {
-    return view('pages.product-detail', compact('category', 'id'));
-})->where(['category' => '.*']);
-
-Route::get('/products/{category}', function ($category) {
-    return view('pages.products', compact('category'));
-})->where(['name' => '.*']);
-
-// Temporary catch all for testing nav and breadcrumbs
-//Route::get('/{name}', function ($name) {
-//    return view('pages.test', compact('name'));
-//})->where(['name' => '.*']);
-
-Route::get('product/{id}', ['uses' => 'ProductController@productDetails']);
-
-/** CATCH-ALL ROUTE for CMS Pages - needs to be at the end of your web.php file  **/
-Route::get('{page}/{subs?}', ['uses' => 'PageController@index'])
+Route::get('{page}/{subs?}', ['uses' => 'PageController@catchall'])
     ->where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*']);
-