From: Stephen Cameron Date: Mon, 7 Feb 2022 18:31:06 +0000 (+0100) Subject: Fix #4893 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1ec6dc1e7336b15a72afe668673186157a955645;p=pmi.git Fix #4893 @4 --- diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index 005c9e9..7dd38d4 100644 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -18,7 +18,7 @@ class ApplicationController extends CubistFrontController $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); } } diff --git a/app/Templates/Category.php b/app/Templates/Category.php index 1e28c42..a867097 100644 --- a/app/Templates/Category.php +++ b/app/Templates/Category.php @@ -5,7 +5,7 @@ namespace App\Templates; 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 { @@ -67,77 +67,11 @@ 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]; - } } diff --git a/app/Templates/Products.php b/app/Templates/Products.php new file mode 100644 index 0000000..3de3ebe --- /dev/null +++ b/app/Templates/Products.php @@ -0,0 +1,79 @@ +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]; + } +}