<?php declare(strict_types=1);
/**
* @copyright 2020 Crehler Sp. z o. o.
* @link https://crehler.com/
* @support support@crehler.com
*
* @author Mateusz FlasiĆski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Crehler\AdvancedMenu\Controller\Storefront;
use Crehler\AdvancedMenu\Service\ProductsNavigationLoader;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
class ProductNavigationController extends AbstractController
{
protected ProductsNavigationLoader $navigationLoader;
/***** ***
* ProductNavigationController constructor.
* @param ProductsNavigationLoader $navigationLoader
*/
public function __construct(ProductsNavigationLoader $navigationLoader)
{
$this->navigationLoader = $navigationLoader;
}
/**
* @Route("/store-api/mojebambino/productTree", name="frontend.mojebambino.productTree", options={"seo"="false"}, methods={"GET"}, defaults={"XmlHttpRequest": true})
*/
public function productTree(SalesChannelContext $context)
{
$tree = $this->navigationLoader->loadNavigationTree($context);
if (empty($tree)) {
return $this->json([]);
}
return $this->json($tree->jsonSerialize());
}
}