$this->_404();
}
$this->data['page'] = $application->getPageData();
- $this->data['related'] = PageData::fromEntities(Product::with('media')->whereIn('id', $application->related)->get());
+ $this->data['related'] = PageData::fromEntities(Product::with('media')->whereVariant()->whereIn('id', $application->related)->get());
return view('pages.application', $this->data);
}
}
use App\Models\Product;
use App\Models\ProductType;
-use Cubist\Backpack\app\Magic\Menu\PageItem;
+use Cubist\Backpack\app\Magic\PageData;
class Category extends Base
{
->orderBy('reference')
->get();
- $data['products'] = [];
- foreach ($products as $item) {
- $data['products'][$item->id] = $item->getPageData();
- }
+ $data['products'] = PageData::fromEntities($products);
// Get available filters
$filters = Product::getFilteredProducts($cat);
$data['filters'] = $filters ? $filters['filters'] : []; // To be used by Vue component
$data['filter_results'] = $filters ? $filters['results'] : [];
}
-
- /**
- * @param \Cubist\Backpack\app\Magic\Menu\Item $menu
- */
- public function setMenuChildren($menu)
- {
- $filter = $menu->getPageData()->get('filter', '');
- if($filter!==''){
- return;
- }
-
- $products = self::_getProducts($menu->getVariant(), $menu->getLocale());
- $data = $menu->getPageData();
- $cat = $data->get('category');
- $root = $menu->getRoot();
-
- foreach ($products as $product) {
- if ($product->product_type != $cat) {
- continue;
- }
- if (!$product->online) {
- continue;
- }
-
- $product->setLocale('fr');
- $slug_fr=$product->getPageData()->get('slug');
- $product->setLocale($menu->getLocale());
-
- $canonical = $href = $product->getSlugOrTitleAttribute();
- if ($root->findOneByHref($canonical) !== null) {
- continue;
- }
-
- $detail = new PageItem();
- $detail->setLocale($menu->getLocale());
- $detail->initFromEntity($product);
- $detail->setTitle($product->name);
- $detail->setCanonical($canonical);
- $detail->setHref($href);
- $detail->setId('product/' . $product->id);
- $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]);
- $detail->hideInAllMenus();
- $detail->addUrlAliases([$slug_fr]);
- $menu->addChild($detail);
- }
- }
-
- /**
- * @param $variant
- * @param $locale
- * @return Product[]
- */
- public static function _getProducts($variant, $locale)
- {
-
- if (!isset(self::$_products[$variant])) {
- self::$_products[$variant] = [];
- }
- if (!isset(self::$_products[$variant][$locale])) {
- self::$_products[$variant][$locale] = Product::whereVariant($variant)->get();
- }
- return self::$_products[$variant][$locale];
- }
}
--- /dev/null
+<?php
+
+
+namespace App\Templates;
+
+use App\Models\Product;
+use Cubist\Backpack\app\Magic\Menu\PageItem;
+
+/*
+ * This template serves as a top level placeholder for the product pages.
+ * It is mainly responsible for generating all the product URLs (previously
+ * the Category template did this, but it was very inefficient and hard to
+ * debug with some products being missed...)
+*/
+class Products extends Base
+{
+ protected $_virtual = true;
+ protected $_navigable = false;
+ protected static $_products = [];
+
+ public function getName()
+ {
+ return 'Produits (Master Placeholder)';
+ }
+
+ /**
+ * @param \Cubist\Backpack\app\Magic\Menu\Item $menu
+ */
+ public function setMenuChildren($menu)
+ {
+ $products = self::_getProducts($menu->getVariant(), $menu->getLocale());
+
+ $root = $menu->getRoot();
+
+ foreach ($products as $product) {
+
+ $product->setLocale('fr');
+ $slug_fr = $product->getPageData()->get('slug');
+ $product->setLocale($menu->getLocale());
+
+ $canonical = $href = $product->getSlugOrTitleAttribute();
+ if ($root->findOneByHref($canonical) !== null) {
+ continue;
+ }
+
+ $detail = new PageItem();
+ $detail->setLocale($menu->getLocale());
+ $detail->initFromEntity($product);
+ $detail->setTitle($product->name);
+ $detail->setCanonical($canonical);
+ $detail->setHref($href);
+ $detail->setId('product/' . $product->id);
+ $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]);
+ $detail->hideInAllMenus();
+ $detail->addUrlAliases([$slug_fr]);
+ $menu->addChild($detail);
+ }
+ }
+
+ /**
+ * @param $variant
+ * @param $locale
+ * @return Product[]
+ */
+ public static function _getProducts($variant, $locale)
+ {
+
+ if (!isset(self::$_products[$variant])) {
+ self::$_products[$variant] = [];
+ }
+ if (!isset(self::$_products[$variant][$locale])) {
+ self::$_products[$variant][$locale] = Product::whereVariant($variant)
+ ->where('online', 1)
+ ->where('public', 1)
+ ->get();
+ }
+ return self::$_products[$variant][$locale];
+ }
+}