first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace KupShop\ProductCompareBundle\Controller;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\KupShopBundle\Util\Functional\Mapping;
use KupShop\ProductCompareBundle\View\ProductCompareView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class ProductCompareController extends AbstractController
{
private const SESSION_PRODUCT_COMPARE = 'productCompare';
private $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
/**
* @TranslatedRoute("/#product_compare#/")
*/
public function productCompareAction(Request $request, ProductCompareView $view): Response
{
$ids = $request->query->all('id');
$ids = Mapping::mapKeys($ids, fn ($k, $v) => [$v, true]);
if (findModule(\Modules::JS_SHOP, \Modules::SUB_JS_SHOP_PRODUCTS_COMPARE)) {
$view->setProductIds(array_keys($ids));
return $view->getResponse();
}
if (!empty($ids)) {
// override session with ids from GET parameters
$this->session->set(self::SESSION_PRODUCT_COMPARE, (array) $ids);
return new RedirectResponse(path('kupshop_productcompare_productcompare_productcompare'));
}
$products = $this->session->get(self::SESSION_PRODUCT_COMPARE, []);
$view->setProductIds(array_keys($products));
return $view->getResponse();
}
/**
* @TranslatedRoute("/#product_compare#/add/{productId}/", requirements={"productId"="\d+"})
*/
public function addProductAction(Request $request, int $productId): Response
{
$products = $this->session->get(self::SESSION_PRODUCT_COMPARE, []);
$products[$productId] = true;
$this->session->set(self::SESSION_PRODUCT_COMPARE, $products);
if (isAjax()) {
return new Response('OK');
}
return new RedirectResponse($request->headers->get('referer', '/'));
}
/**
* @TranslatedRoute("/#product_compare#/remove/{productId}/", requirements={"productId"="\d+"})
*/
public function removeProductAction(Request $request, int $productId): Response
{
$products = $this->session->get(self::SESSION_PRODUCT_COMPARE, []);
unset($products[$productId]);
$this->session->set(self::SESSION_PRODUCT_COMPARE, $products);
if (isAjax()) {
return new Response('OK');
}
return new RedirectResponse($request->headers->get('referer', '/'));
}
}