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);
}
$this->data['title'] = $product->title;
- $this->data['product'] = $product->withFakes();
+ $this->data['product'] = $product->getPageData();
return view('pages.product-detail', $this->data);
}
'type' => 'Text',
'column' => true]);
+ $this->addField(['name' => 'slug',
+ 'label' => 'Slug',
+ 'type' => 'Slug']);
+
$this->addField([
'name' => 'type',
'label' => 'Famille de produits',
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);
+ }
+ }
+ }
+
}
<?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' => '.*']);
-