[英]Spree Commerce Number of Products in a Taxon | Ruby on Rails
I'm new to spree commerce and doing come customizations. 我是狂热的商业新手,并进行定制。
I have some category Taxons displaying on the homepage (ie T-Shirts). 我在首页上显示了一些分类单元(即T恤)。 I want to be able to display the count for the number of products in this category (ie T-Shirts, 20 products).
我希望能够显示该类别产品的数量(即T恤,20种产品)。
From the documentation, I believe this should work: 从文档中,我认为这应该可行:
<%= Spree::Product.taxons_name_eq("t-shirts").all.count %> PRODUCTS
But I just get {} Products as an output. 但是我只是得到{}个产品作为输出。
Can anyone help with this? 有人能帮忙吗?
The following should work for you: 以下应该为您工作:
Spree::Taxon.where(name: 't-shirts').products.count
and let me know if you have problem with it. 并告诉我您是否有问题。
You can first find the Taxon
with the name "t-shirts" then count the number of products associated with that taxon. 你可以先找到
Taxon
的名称为“T恤”再算上与分类群相关的产品数量。 This code, or something similar should do it: 此代码或类似的代码应该做到:
Spree::Taxon.where(name: 't-shirts').first.products.count
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.