From 16d8c6729bcc91a707eb26832e810983fc3067cf Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Fri, 30 Jun 2023 10:18:36 +0200 Subject: [PATCH] [Next] fix category controller --- .../Pimcore/Repository/CategoryRepository.php | 2 +- .../FrontendBundle/Controller/CategoryController.php | 12 ++++++++---- .../Resources/views/Category/_grid.html.twig | 2 +- .../Resources/views/Category/_list.html.twig | 2 +- .../Resources/views/Product/detail.html.twig | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/CoreShop/Bundle/CoreBundle/Pimcore/Repository/CategoryRepository.php b/src/CoreShop/Bundle/CoreBundle/Pimcore/Repository/CategoryRepository.php index f817c11e7a..f942749ff0 100644 --- a/src/CoreShop/Bundle/CoreBundle/Pimcore/Repository/CategoryRepository.php +++ b/src/CoreShop/Bundle/CoreBundle/Pimcore/Repository/CategoryRepository.php @@ -102,7 +102,7 @@ private function setSortingForListing(Listing $list, CategoryInterface $category { if (method_exists($category, 'getChildrenSortBy')) { $list->setOrderKey( - sprintf('%s ASC', $category->getChildrenSortBy()), + sprintf('`%s` ASC', $category->getChildrenSortBy()), false, ); } else { diff --git a/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php b/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php index 723f4ad868..4b588b73db 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php +++ b/src/CoreShop/Bundle/FrontendBundle/Controller/CategoryController.php @@ -134,7 +134,7 @@ public function detail(Request $request, CategoryInterface $category): Response $orderDirection = $category->getFilter()->getOrderDirection(); $orderKey = $category->getFilter()->getOrderKey(); - $sortKey = (empty($orderKey) ? $this->getParameter('defaultSortName') : $orderKey) . '_' . (empty($orderDirection) ? $this->getParameter('defaultSortDirection') : $orderDirection); + $sortKey = (empty($orderKey) ? $this->getParameter('coreshop.frontend.category.default_sort_name') : $orderKey) . '_' . (empty($orderDirection) ? $this->getParameter('coreshop.frontend.category.default_sort_direction') : $orderDirection); $sort = $this->getParameterFromRequest($request, 'sort', $sortKey); $sortParsed = $this->parseSorting($sort); @@ -157,7 +157,7 @@ public function detail(Request $request, CategoryInterface $category): Response $viewParameters['conditions'] = $preparedConditions; } else { //Classic Listing Mode - $sort = $this->getParameterFromRequest($request, 'sort', $this->getParameter('defaultSortName') . '_' . $this->getParameter('defaultSortDirection')); + $sort = $this->getParameterFromRequest($request, 'sort', $this->getParameter('coreshop.frontend.category.default_sort_name') . '_' . $this->getParameter('coreshop.frontend.category.default_sort_direction')); $sortParsed = $this->parseSorting($sort); $categories = [$category]; @@ -196,7 +196,7 @@ public function detail(Request $request, CategoryInterface $category): Response $viewParameters['type'] = $type; $viewParameters['perPageAllowed'] = $allowedPerPage; $viewParameters['sort'] = $sort; - $viewParameters['validSortElements'] = $this->getParameter('validSortProperties'); + $viewParameters['validSortElements'] = $this->getParameter('coreshop.frontend.category.valid_sort_options'); foreach ($paginator as $product) { $this->container->get(TrackerInterface::class)->trackProductImpression($product); @@ -240,7 +240,7 @@ protected function parseSorting(string $sortString): array $name = $sortString[0]; $direction = $sortString[1]; - if (in_array($name, $this->getParameter('validSortProperties')) && in_array($direction, ['desc', 'asc'])) { + if (in_array($name, $this->getParameter('coreshop.frontend.category.valid_sort_options')) && in_array($direction, ['desc', 'asc'])) { return [ 'name' => $name, 'direction' => $direction, @@ -257,6 +257,10 @@ public static function getSubscribedServices(): array new SubscribedService('defaultSortName', 'string', attributes: new Autowire('%coreshop.frontend.category.default_sort_name%')), new SubscribedService('defaultSortDirection', 'string', attributes: new Autowire('%coreshop.frontend.category.default_sort_direction%')), 'coreshop.repository.category' => CategoryRepositoryInterface::class, + ConfigurationServiceInterface::class, + PaginatorInterface::class, + TrackerInterface::class, + new SubscribedService('coreshop.repository.product', ProductRepositoryInterface::class), ]; } diff --git a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_grid.html.twig b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_grid.html.twig index a8c20a87ac..cfb31ca8e4 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_grid.html.twig +++ b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_grid.html.twig @@ -30,7 +30,7 @@
{{ product_price.display_product_price(product) }}
- {% if coreshop_add_to_cart_available(product) and is_granted('CORESHOP_CART_ADD_ITEM') %} + {% if coreshop_add_to_cart_available(product) and is_granted('CORESHOP_CART') and is_granted('CORESHOP_CART_ADD_ITEM') %}
{% if coreshop_inventory_is_available(product) %} {{ render(url('coreshop_partial_wishlist_add', {'product': product.id|coreshop_string})) }} diff --git a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_list.html.twig b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_list.html.twig index 83dbcbc5ab..242f6d45ee 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_list.html.twig +++ b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Category/_list.html.twig @@ -34,7 +34,7 @@ {{ product_price.display_product_price(product) }}
- {% if coreshop_add_to_cart_available(product) and is_granted('CORESHOP_CART_ADD_ITEM') %} + {% if coreshop_add_to_cart_available(product) and is_granted('CORESHOP_CART') and is_granted('CORESHOP_CART_ADD_ITEM') %}
{% if coreshop_inventory_is_available(product) %} {{ render(url('coreshop_partial_wishlist_add', {'product': product.id|coreshop_string})) }} diff --git a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Product/detail.html.twig b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Product/detail.html.twig index 267f3ff2a4..f5fdf312e9 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Resources/views/Product/detail.html.twig +++ b/src/CoreShop/Bundle/FrontendBundle/Resources/views/Product/detail.html.twig @@ -102,8 +102,8 @@
{% endif %} - {% set cart_allowed = is_granted('CORESHOP_CART_ADD_ITEM') %} - {% set wishlist_allowed = is_granted('CORESHOP_WISHLIST_ADD_ITEM') %} + {% set cart_allowed = is_granted('CORESHOP_CART') and is_granted('CORESHOP_CART_ADD_ITEM') %} + {% set wishlist_allowed = is_granted('CORESHOP_WISHLIST') and is_granted('CORESHOP_WISHLIST_ADD_ITEM') %} {% if coreshop_add_to_cart_available(product) and (cart_allowed or wishlist_allowed) %}