Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Next] fix category controller #2340

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="price">
{{ product_price.display_product_price(product) }}
</div>
{% 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') %}
<div class="cart-button btn-group">
{% if coreshop_inventory_is_available(product) %}
{{ render(url('coreshop_partial_wishlist_add', {'product': product.id|coreshop_string})) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{{ product_price.display_product_price(product) }}
</div>

{% 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') %}
<div class="cart-button btn-group">
{% if coreshop_inventory_is_available(product) %}
{{ render(url('coreshop_partial_wishlist_add', {'product': product.id|coreshop_string})) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
<hr/>
{% 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) %}
<div class="options">
Expand Down