【问题标题】:Where in Spree is the prices table joined to the products for lists?在 Spree 中,价格表在哪里加入到产品列表中?
【发布时间】:2018-05-14 10:16:03
【问题描述】:

我修改了 Spree,使产品/变体可以有多个价格。这意味着产品具有one_time 价格、recurring_priceconsumption_price。为此,我在 Price 模型中添加了一个 price_type 字段。现在我的列表有问题。该产品被列出 3 次,因为某处价格是内部连接的,导致列表中有 3 个条目用于三种不同的价格类型。我在哪里解决这个问题,这意味着只对列表进行内部连接 ​​price_type = one_time(或一般情况下,除非另有说明)?

【问题讨论】:

  • 您能否提供模型关联以使您的问题更清楚?如何清楚地显示模型关联的示例可以在:Active Record Associations - 2.4 has_many :through 关联中找到。 guides.rubyonrails.org/…

标签: ruby-on-rails spree


【解决方案1】:

我想出了一些办法,到目前为止它对我有用:

Spree::Product.class_eval do

  class << self
    alias_method :orig_available, :available

    def available(available_on = nil, _currency = nil)
      orig_available(available_on, _currency).where("#{Spree::Price.quoted_table_name}.price_type = ?", Spree::Price.price_types[:one_time])
    end

  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-29
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 2019-08-06
    相关资源
    最近更新 更多