<?php
/**
* @author <akartis-dev>
*/
namespace App\Controller\App;
use App\Controller\AppAbstractController;
use App\Entity\Pharmacists;
use App\Repository\Application\SlidersRepository;
use App\Repository\PharmacyNotificationRepository;
use App\Repository\Products\Categories\ProductsCategoriesRepository;
use App\Repository\Products\ProductBrandRepository;
use App\Service\Cart\CartService;
use App\Service\Gift\GiftService;
use App\Service\Notifications\NotificationService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class WidgetController extends AppAbstractController
{
public function sliders(SlidersRepository $slidersRepository): Response
{
$sliders = $slidersRepository->findBy(['isActive' => true], ['id' => 'ASC']);
return $this->render('elements/component/sliders.html.twig', [
'sliders' => $sliders
]);
}
/**
* Online shop filter
*
* @param ProductsCategoriesRepository $productsCategoriesRepository
* @param ProductBrandRepository $brandRepository
* @param $linkMode
* @return Response
* @throws \JsonException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function onlineShopFilter(
ProductsCategoriesRepository $productsCategoriesRepository,
ProductBrandRepository $brandRepository,
$linkMode = false
): Response
{
$request = $this->container->get("request_stack")->getMainRequest();
$categories = $productsCategoriesRepository->findByTree('fr');
$brands = $brandRepository->findAll();
$q_categories = json_decode(
$request->get("categories", "[]"),
true,
512,
JSON_THROW_ON_ERROR
);
$q_brands = json_decode(
$request->get('brands', "[]"),
true,
512,
JSON_THROW_ON_ERROR
);
$q_min = $request->get("min", 1);
$q_max = $request->get("max", 100);
$q_order = $request->get("order", 0);
$q_search = $request->get("q", null);
return $this->render('elements/pagesElements/_online_shop_filter.html.twig', [
'categories' => $categories,
'brands' => $brands,
'q_categories' => $q_categories,
"q_brands" => $q_brands,
"q_min" => $q_min,
"q_max" => $q_max,
"q_order" => $q_order,
'linkMode' => $linkMode,
'q_search' => $q_search
]);
}
public function headerCart(CartService $cartService): Response
{
$cart = $cartService->getHydratedCart();
$count = 0;
foreach ($cart as $cartItem) {
$count += $cartItem['quantity'];
}
return $this->render('elements/pagesElements/_header_cart.html.twig', [
'sum' => $cartService->getTotalBrut(),
"count" => $count
]);
}
public function adminHeaderNotification(
PharmacyNotificationRepository $pharmacyNotificationRepository,
NotificationService $notificationService
): Response
{
/** @var Pharmacists $user */
$user = $this->getUser();
$unreadCount = $notificationService->getUnreadNotification($user->getPharmacyId());
$notifications = $pharmacyNotificationRepository
->findBy(['pharmacyId' => $user->getPharmacyId()], ['id' => 'DESC'], 15);
return $this->render('elements/pagesElements/_headerNotification.html.twig', [
'notifications' => $notifications,
'unreadCount' => $unreadCount
]);
}
public function categoriesSideBar(
ProductsCategoriesRepository $productsCategoriesRepository
)
{
$categories = $productsCategoriesRepository->findByTree("fr");
// dump($categories);
return $this->render('elements/pagesElements/_sidebar.html.twig', [
'categories' => $categories
]);
}
public function giftsProduct(Request $request, GiftService $giftService)
{
$productId = $request->get('product');
$cartGift = $request->get('cartGift', false);
$items = $giftService->handleViewInProduct($productId, $cartGift);
// dd($items);
return $this->render('elements/products/_product_gift.html.twig', ['gifts' => $items, 'cardGift' => $cartGift]);
}
}