有没有办法在一个视图中显示所有 Sylius 产品?
Is there a way to show all Sylius products in one view?
我知道可以按分类显示产品,但如果我想在一个视图中显示所有产品,而不管产品属于哪个类别,该怎么办?
在 Sylius 中是否可行,或者我是否必须编写自己的控制器来使用查询生成器输出所有这些控制器?如果是,那又如何呢?迭代所有分类单元并向 ORM 抛出大量查询?
您可以使用 Sylius 包执行此操作。首先,创建一条新路线,例如 config/routes/sylius_shop.yaml
:
sylius_shop_product_all:
path: /all
methods: [GET]
defaults:
_controller: sylius.controller.product:indexAction
_sylius:
template: "@SyliusShop/Product/index.html.twig"
grid: sylius_shop_custom_filter
然后定义一个sylius_shop_custom_filter
网格。如果您不知道该怎么做,请查看 documentation。
像这样禁用存储库方法的 taxon
参数:
sylius_shop_custom_filter:
driver:
name: doctrine/orm
options:
class: "%sylius.model.product.class%"
repository:
method: findAllByChannel
arguments:
channel: "expr:service('sylius.context.channel').getChannel()"
# taxon: "expr:notFoundOnNull(service('sylius.repository.taxon').findAll)"
locale: "expr:service('sylius.context.locale').getLocaleCode()"
sorting: "expr:service('request_stack').getCurrentRequest().get('sorting', [])"
然后像 documentation 一样扩展 ProductRepository,从父存储库复制 createShopListQueryBuilder
方法并将其命名为 findAllByChannel
。 querybuilder 禁用未使用的 $taxon
参数。
我知道可以按分类显示产品,但如果我想在一个视图中显示所有产品,而不管产品属于哪个类别,该怎么办?
在 Sylius 中是否可行,或者我是否必须编写自己的控制器来使用查询生成器输出所有这些控制器?如果是,那又如何呢?迭代所有分类单元并向 ORM 抛出大量查询?
您可以使用 Sylius 包执行此操作。首先,创建一条新路线,例如 config/routes/sylius_shop.yaml
:
sylius_shop_product_all:
path: /all
methods: [GET]
defaults:
_controller: sylius.controller.product:indexAction
_sylius:
template: "@SyliusShop/Product/index.html.twig"
grid: sylius_shop_custom_filter
然后定义一个sylius_shop_custom_filter
网格。如果您不知道该怎么做,请查看 documentation。
像这样禁用存储库方法的 taxon
参数:
sylius_shop_custom_filter:
driver:
name: doctrine/orm
options:
class: "%sylius.model.product.class%"
repository:
method: findAllByChannel
arguments:
channel: "expr:service('sylius.context.channel').getChannel()"
# taxon: "expr:notFoundOnNull(service('sylius.repository.taxon').findAll)"
locale: "expr:service('sylius.context.locale').getLocaleCode()"
sorting: "expr:service('request_stack').getCurrentRequest().get('sorting', [])"
然后像 documentation 一样扩展 ProductRepository,从父存储库复制 createShopListQueryBuilder
方法并将其命名为 findAllByChannel
。 querybuilder 禁用未使用的 $taxon
参数。