【问题标题】:Is there a way to get count of units of a specific product present in the cart?(Spree rails)有没有办法计算购物车中特定产品的数量?(Spree rails)
【发布时间】:2023-10-06 17:52:01
【问题描述】:

我似乎无法找到一种方法来计算添加到购物车中的特定产品的数量。

我试过simple_current_order.item_count,但它提供了整个购物车物品的数量。

我希望它是某种方法count_quantity_in_cart(@product),结果返回integer

【问题讨论】:

    标签: ruby-on-rails spree


    【解决方案1】:

    获取购物车中特定产品的单位数。

    simple_current_order.where(product: @product).to_a.sum(&:quantity)
    

    【讨论】:

      最近更新 更多