<?php declare(strict_types=1);
namespace Nd\Fashion\Storefront\Controller;
use Nd\Fashion\Page\Manufacturer\ProductManufacturerPageLoader;
use Shopware\Core\Content\Product\SalesChannel\Detail\ProductConfiguratorLoader;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Shopware\Storefront\Page\GenericPageLoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Component\Routing\Annotation\Route;
/**
* @RouteScope(scopes={"storefront"})
*/
class ManufacturerController extends StorefrontController
{
private SalesChannelRepositoryInterface $productRepository;
private EntityRepositoryInterface $productManufacturerRepository;
private ProductManufacturerPageLoader $productManufacturerPageLoader;
private ProductConfiguratorLoader $configuratorLoader;
public function __construct( ProductManufacturerPageLoader $productManufacturerPageLoader, EntityRepositoryInterface $productManufacturerRepository,
SalesChannelRepositoryInterface $productRepository, ProductConfiguratorLoader $configuratorLoader)
{
$this->productManufacturerPageLoader = $productManufacturerPageLoader;
$this->productRepository = $productRepository;
$this->productManufacturerRepository = $productManufacturerRepository;
$this->configuratorLoader = $configuratorLoader;
}
/**
* @Route("/productManufacturer/{productManufacturerId}", name="frontend.productManufacturer.detail", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*/
public function productManufacturerDetail(Request $request, SalesChannelContext $context): Response
{
$productManufacturerId = $request->attributes->get('productManufacturerId');
// if (!$productManufacturerId) {
// return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/not-found.html.twig', []);
// }
$page = $this->productManufacturerPageLoader->load($request, $context);
// dump($page);
//
// die();
//
$criteria = new Criteria([$productManufacturerId]);
// $criteria->getAssociation("cmsPage");
// $criteria->addAssociation("media");
// $criteria->addAssociation("products");
//// $criteria->addAssociation("products.product.cover");
//// $criteria->getAssociation("products.product.configuratorSettings.option");
// $criteria->getAssociation("cover");
try {
$productManufacturer = $this->productManufacturerRepository->search($criteria, $context->getContext())->first();
} catch (InvalidUuidException $exception) {
return $this->renderStorefront('@NdFashion/storefront/page/manufacturer/detail/not-found.html.twig', ['page' => $page]);
}
// foreach($productManufacturer->products as $productManufacturerProduct) {
// $struct = new ArrayStruct();
// $criteria = new Criteria([$productManufacturerProduct->productId]);
// $criteria->addAssociation("configuratorSettings.option");
// $product = $this->productRepository->search($criteria, $context)->first();
// $productManufacturerProduct->setProduct($product);
// $struct->set("configuratorSettings", [$this->configuratorLoader->load($product, $context)]);
// $product->addExtension("configuratorSettings", $struct);
// }
if($page->getHeader() && $page->getHeader()->getNavigation()) {
$activeNavigation = $page->getHeader()->getNavigation()->getActive();
$activeNavigation->setName($productManufacturer->getName());
$metaInformation = $page->getMetaInformation();
$metaInformation->setMetaTitle($productManufacturer->getName() . " online kopen | Voorwinden");
$metaInformation->setMetaDescription($productManufacturer->getName() . " ✔️Meer dan 200 merken online✔️Ontvang spaarpunten ✔️Gratis verzending v.a. €50✔️Gratis Personal Shopper ✔️Shop voor het hele gezin");
}
//page.header.navigation.active.name
return $this->renderStorefront('@NdFashion/storefront/page/content/category-detail.html.twig', ['page' => $page]);
// if (!$productManufacturer) {
// return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/not-found.html.twig', ['page' => $page]);
// }
// return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/index.html.twig', [
// 'productManufacturer' => $productManufacturer,
// 'page' => $page
// ]);
}
}