So in in home page we have FEATURED CATEGORIES section which show some categories with
images and product count inside every category .
The bundle responsible of this section is OroCatalogBundle , Yes and start point layout is vendor/oro/commerce/src/Oro/Bundle/CatalogBundle/Resources/views/layouts/blank/oro_frontend_root/default.yml
But the very important lines inside this .yml:
layout: actions: - '@setBlockTheme': themes: 'OroCatalogBundle:layouts:blank/oro_frontend_root/default.html.twig' - '@appendOption': id: page_main optionName: attr.class optionValue: ' offset-none' - '@addTree': items: featured_categories_container: blockType: container siblingId: featured_menu_container options: attr: itemprop: 'hasOfferCatalog' itemscope: ~ itemtype: 'http://schema.org/OfferCatalog' featured_categories: blockType: embedded_list options: label: 'oro.catalog.featured_categories.label' item_key: 'category' items: '=data["featured_categories"].getAll([2,3,4,6,7,8,9,10])' items_data: categoryProductsCount: '=data["categories_products"].getCountByCategories([2,3,4,6,7,8,9,10])' item_extra_class: 'embedded-list__item—hide-same'
Which defined the twig renderer file :
- '@setBlockTheme': themes: 'OroCatalogBundle:layouts:blank/oro_frontend_root/default.html.twig'
and container :
featured_categories_container: blockType: container siblingId: featured_menu_container options: attr: itemprop: 'hasOfferCatalog' itemscope: ~ itemtype: 'http://schema.org/OfferCatalog'
After that the block responsible of getting data and render it :
featured_categories: blockType: embedded_list options: label: 'oro.catalog.featured_categories.label' item_key: 'category' items: '=data["featured_categories"].getAll([2,3,4,6,7,8,9,10])' items_data: categoryProductsCount: '=data["categories_products"].getCountByCategories([2,3,4,6,7,8,9,10])' item_extra_class: 'embedded-list__item—hide-same'
As you see :
items: '=data["featured_categories"].getAll([2,3,4,6,7,8,9,10])'
using layout data provider -featured_categories- to call function getAll with array argument of all featured categories , you can find the declaration of 2 data providers for featured categories and product count inside : vendor/oro/commerce/src/Oro/Bundle/CatalogBundle/Resources/config/layout.yml :
oro_catalog.layout.data_provider.featured_categories: class: 'Oro\Bundle\CatalogBundle\Layout\DataProvider\FeaturedCategoriesProvider' public: true arguments: - "@oro_catalog.provider.category_tree_provider" - "@security.token_storage" - '@oro_locale.helper.localization' calls: - [setCache, ['@oro_catalog.layout.data_provider.category.cache', 3600]] tags: - { name: layout.data_provider, alias: featured_categories } oro_catalog.layout.data_provider.featured_categories_products: class: 'Oro\Bundle\CatalogBundle\Layout\DataProvider\CategoriesProductsProvider' public: true arguments: - "@oro_catalog.repository.category" - "@oro_catalog.website_search.repository.product" calls: - [setCache, ['@oro_catalog.layout.data_provider.category.cache', 3600]] tags: - { name: layout.data_provider, alias: categories_products }
the 1 functions getAll([2,3,4,6,7,8,9,10]) and getCountByCategories([2,3,4,6,7,8,9,10]) is inside
FeaturedCategoriesProvider , CategoriesProductsProvider .
Use Case
1 - Remove Featured Categories from Home Page :
inside you bundle of customization for example :
src/Ibnab/Bundle/CustomhomeBundle/Resources/views/layouts/blank/oro_frontend_root/default.yml
create default.yml and push :
layout: actions: - '@remove': id: featured_categories_container
2 - Override the array of categories :
inside the default.yml for example show just 4 categories and 4 count products push :
layout:
actions: - '@setOption': id: featured_categories optionName: items optionValue: '=data["featured_categories"].getAll([5,4,3,1])' - '@setOption': id: featured_categories optionName: items_data optionValue: categoryProductsCount: '=data["categories_products"].getCountByCategories([5,4,3,1])'
3 - Other things :
You can create dynamic categories by adding field in configuration section , and using inside your custom data layout provider Instead data["featured_categories"].getAll([5,4,3,1]) use your data["my-featured_categories"].getAll([5,4,3,1]) , plz see how to create data layout provider .
You can customize the by adding src/Ibnab/Bundle/CustomhomeBundle/Resources/views/layouts/blank/oro_frontend_root/default.html.twig and fill with content of OroCatalogBundle:layouts:blank/oro_frontend_root/default.html.twig and start customization .
Comments