Skip to content

Commit 0ed9f24

Browse files
committed
TASK: filter product list for enabled products and remove checks in twig templates
1 parent 7cd4ee5 commit 0ed9f24

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/Renderer/ContentElement/ProductsCarouselContentElementRenderer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public function render(ContentConfigurationInterface $contentConfiguration): str
4040
return '';
4141
}
4242

43+
$enabledProducts = array_filter($products, function (ProductInterface $product): bool {
44+
return $product->isEnabled();
45+
});
46+
4347
return $this->twig->render('@SyliusCmsPlugin/shop/content_element/index.html.twig', [
4448
'content_element' => $this->template,
45-
'products' => $products,
49+
'products' => $enabledProducts,
4650
]);
4751
}
4852
}

src/Renderer/ContentElement/ProductsGridContentElementRenderer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ public function render(ContentConfigurationInterface $contentConfiguration): str
3737
$productsCodes = $configuration['products_grid']['products'];
3838
$products = $this->productRepository->findBy(['code' => $productsCodes]);
3939

40+
$enabledProducts = array_filter($products, function (ProductInterface $product): bool {
41+
return $product->isEnabled();
42+
});
43+
4044
return $this->twig->render('@SyliusCmsPlugin/shop/content_element/index.html.twig', [
4145
'content_element' => $this->template,
42-
'products' => $products,
46+
'products' => $enabledProducts,
4347
]);
4448
}
4549
}

templates/shop/content_element/elements/products_carousel.html.twig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<div class="swiper {{ content_element_base_class }}__products-carousel products-carousel mb-3">
22
<div class="swiper-wrapper">
33
{% for product in products %}
4-
{% if product.enabled %}
5-
<div class="swiper-slide">
6-
<div>{{ component('sylius_shop:product:card', { product: product, template: '@SyliusShop/product/common/card.html.twig' }) }}</div>
7-
</div>
8-
{% endif %}
4+
<div class="swiper-slide">
5+
<div>{{ component('sylius_shop:product:card', { product: product, template: '@SyliusShop/product/common/card.html.twig' }) }}</div>
6+
</div>
97
{% endfor %}
108
</div>
119
<div class="btn btn-primary swiper-button-prev position-absolute top-50 start-0 z-1 translate-x-middle ms-2 opacity-75">
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<div class="{{ content_element_base_class }}__products-grid mb-3">
22
<div class="products-grid">
33
{% for product in products %}
4-
{% if product.enabled %}
5-
<div>{{ component('sylius_shop:product:card', { product: product, template: '@SyliusShop/product/common/card.html.twig' }) }}</div>
6-
{% endif %}
4+
<div>{{ component('sylius_shop:product:card', { product: product, template: '@SyliusShop/product/common/card.html.twig' }) }}</div>
75
{% endfor %}
86
</div>
97
</div>

0 commit comments

Comments
 (0)