<?php declare(strict_types=1);
namespace Mrpix\ShoppingCity\Storefront\Controller;
use Mrpix\ShoppingCity\Services\Filter;
use Mrpix\ShoppingCity\Services\Seller;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class SellerController extends StorefrontController
{
private Filter $filterService;
private Seller $sellerService;
private NavigationPageLoaderInterface $navigationPageLoader;
public function __construct(Filter $filterService, Seller $sellerService, NavigationPageLoaderInterface $navigationPageLoader)
{
$this->filterService = $filterService;
$this->sellerService = $sellerService;
$this->navigationPageLoader = $navigationPageLoader;
}
/**
* @Route("/marketplace", name="frontend.marketplace.sellers", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*/
public function listSellers(Request $request, SalesChannelContext $context): Response
{
$properties = $request->query->get('properties');
$properties = $this->getFilter($properties);
$page = $request->query->get('p');
$page = $page === null ? 1 : (int) $page;
$data = $this->navigationPageLoader->load($request, $context);
$sellers = $this->sellerService->getSellers($context->getContext(), $properties, $page);
return $this->renderStorefront('@MrpixShoppingCity/storefront/page/seller/list.html.twig', [
'sellers' => $sellers,
'limit' => $this->sellerService->getSellersLimit(),
'page' => $data,
'filters' => $this->filterService->getAvailableFilters($context->getContext()),
]);
}
/**
* @Route("/marketplace/{storeSlug}", name="frontend.marketplace.seller.profile.detail", methods={"GET"})
*/
public function sellerProfile(string $storeSlug, Request $request, SalesChannelContext $context): Response
{
$data = $this->navigationPageLoader->load($request, $context);
$seller = $this->sellerService->getSeller($storeSlug, $context->getContext());
$similarSellers = $this->sellerService->getSimilarSellers($seller, $context->getContext());
return $this->renderStorefront('@MrpixShoppingCity/storefront/page/seller/profile.html.twig', [
'page' => $data,
'profileDetails' => $seller,
'similarSellers' => $similarSellers,
'currency' => $context->getCurrency(),
/** @phpstan-ignore-next-line */
'environment' => $this->container->getParameter('kernel.environment'),
]);
}
private function getFilter(?string $filter): array
{
if ($filter === null) {
return [];
}
return explode('|', $filter);
}
}