diff --git a/category.html.twig b/category.html.twig index 806efc3..1a0f9d8 100644 --- a/category.html.twig +++ b/category.html.twig @@ -5,10 +5,9 @@ {% block body %} {% set products = resources('/api/front/products', {'productCategories.category.id': attr('category', 'id'), itemsPerPage:9, page: page}) %} - {% set totalProducts = resources('/api/front/products', {'productCategories.category.id': attr('category', 'id'), itemsPerPage:9, page: page}) %} - {% include '@components/Layout/SimilarContent/SimilarContent.html.twig' with {title: attr('category', 'title'), description: attr('category', 'description'), nbProducts: products|length} %} - {% include '@components/Layout/CategoryProduct/CategoryProduct.html.twig' with {products: products, totalProducts:totalProducts} %} + {% include '@components/Layout/Subheader/Category/SubheaderCategory.html.twig' with {title: attr('category', 'title'), description: attr('category', 'description'), nbProducts: products|length} %} + {{ component('Flexy:Layout:CategoryProduct', {categoryId: attr('category', 'id'), page}) }} {% include '@components/Layout/Reinsurance/Reinsurance.html.twig' with { data: [ { diff --git a/components/Layout/CategoryProduct/CategoryProduct.html.twig b/components/Layout/CategoryProduct/CategoryProduct.html.twig index 69be4ae..9abb0db 100644 --- a/components/Layout/CategoryProduct/CategoryProduct.html.twig +++ b/components/Layout/CategoryProduct/CategoryProduct.html.twig @@ -1,5 +1,4 @@ {% set products = products|default([]) %} -{% set totalProducts = totalProducts|default("") %}
- {% set news = resources('/api/front/contents', {itemsPerPage:3}) %} - - {% set newsFiltered = news|map((n) => ({ - title: n.i18ns.title, - date: n.createdAt|date("d/m/Y"), - url: '#', - img: {url: '/images/placeholder.webp', alt: n.i18ns.title} - })) - %}
- {% include '@components/Layout/SimilarContent/SimilarContent.html.twig' with {title: 'Our news' | trans, similarContents: newsFiltered, button: {label: "See all news" | trans, href: "#"}} %} + {{ component('Flexy:Layout:SimilarContent', {title: 'Our news' | trans, button: {label: "See all news" | trans, href: "#"}}) }}
+ {% endblock %} {#
{{ format_money(number={$TOTAL_TAXED_AMOUNT}, currency_id=$CURRENCY) }}
#} diff --git a/src/Twig/Layout/CategoryProduct.php b/src/Twig/Layout/CategoryProduct.php new file mode 100644 index 0000000..ce0e444 --- /dev/null +++ b/src/Twig/Layout/CategoryProduct.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FlexyBundle\Twig\Layout; + +use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; +use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate; +use TwigEngine\Service\DataAccess\DataAccessService; + +#[AsTwigComponent(template: 'components/Layout/CategoryProduct/CategoryProduct.html.twig')] +class CategoryProduct +{ + private DataAccessService $dataAccessService; + public string $categoryId; + public string $page; + + #[ExposeInTemplate] + private array $products; + + public function __construct(DataAccessService $dataAccessService) + { + $this->dataAccessService = $dataAccessService; + } + + public function getProducts(): array + { + $this->products = $this->dataAccessService->resources('/api/front/products', [ + 'productCategories.category.id' => $this->categoryId, + 'itemsPerPage' => 9, + 'page' => $this->page, + ]); + + return $this->products; + } +} diff --git a/src/Twig/Layout/SimilarContent.php b/src/Twig/Layout/SimilarContent.php new file mode 100644 index 0000000..23e99af --- /dev/null +++ b/src/Twig/Layout/SimilarContent.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FlexyBundle\Twig\Layout; + +use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; +use TwigEngine\Service\DataAccess\DataAccessService; + +#[AsTwigComponent(template: '@components/Layout/SimilarContent/SimilarContent.html.twig')] +class SimilarContent +{ + public array $similarContents; + + public function __construct(private DataAccessService $dataAccessService) + { + } + + public function mount(array $similarContents = []): void + { + if (\count($similarContents) > 0) { + $this->similarContents = $similarContents; + } + } + + public function similarContents(): array + { + $contents = $this->dataAccessService->resources('/api/front/contents', [ + 'itemsPerPage' => 3, + ]); + + return array_map(function ($item) { + return [ + 'title' => $item['i18ns']['title'], + 'date' => $item['createdAt'], + 'url' => '#', + 'img' => [ + 'url' => '/images/placeholder.webp', + 'alt' => $item['i18ns']['title'], + ], + ]; + }, $contents); + } +}