根据created_at对Spree中的产品列表进行排序
我正在使用 spree,我想根据产品的 created_at
对产品列表进行排序。
我试图找到覆盖 lib/scopes/product.rb 下的狂欢默认范围的方法,但找不到它。
我想在公共面板上列出最近创建的产品。我怎样才能用狂欢做到这一点?
I'm using spree and I want to sort product listing based on created_at
of the product.
I tried to find the way to override the spree default scope under lib/scopes/product.rb but couldn't find it.
I want to list recently created products on public panel. How can I do it with spree?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个答案将破坏管理面板产品版本,也许还会破坏 spree 1.1-stable 中的其他内容。
您可以通过使用以下命令指定表名来解决此问题:
但我认为最好的解决方案是修补公共产品控制器或视图,而不是模型本身,因为可能不会在任何地方都期望default_scope,并切换/删除在 default_scope 中定义的订单,您必须调用 .reorder()
可能正因为如此,SpreeCommerce 文档特别不建议您在产品范围中添加订单:
来源:http://guides.spreecommerce.com/scopes_and_groups.html#modifying-available-scopes
所以我认为在不破坏 Spree 核心产品模型的情况下执行此操作的正确方法是覆盖产品模板:
Overwrite views/spree/shared/_products.html.rb
替换
为
来源:https://groups.google.com/forum/#!topic /spree-user/lW5sGsbMTfM
为我工作™
First answer will break admin panel product edition and maybe other stuff in spree 1.1-stable.
You may fix this by specifying the table name with :
But I think best solution would be to patch the public products controller or view, not the model itself as the default_scope may not be expected everywhere and to switch/remove an order defined in a default_scope you must call .reorder()
Probably because of this, SpreeCommerce documentation specifically do not recommend you add order in product scopes :
Source : http://guides.spreecommerce.com/scopes_and_groups.html#modifying-available-scopes
So I think the proper way of doing this without screwing the Spree core product model is to overwrite the products template :
Overwrite views/spree/shared/_products.html.rb
replace
with
Source : https://groups.google.com/forum/#!topic/spree-user/lW5sGsbMTfM
Works for me™