Sha256: afb46e79732a5f8c91e400d22385dd71072adf860c97e406d5c006eaa7a39df0

Contents?: true

Size: 467 Bytes

Versions: 2

Compression:

Stored size: 467 Bytes

Contents

Spree::Product.class_eval do
  def self.recently_sold
    @sold_products = []
    @orders =
      Spree::Order.where('state = ?', 'complete').order('created_at DESC')
    @orders.each do |order|
      order.products.each do |product|
        if @sold_products.count < Spree::Config[:recently_sold_product_limit]
          @sold_products << product
          @sold_products.uniq!
        else
          break
        end
      end
    end
    @sold_products
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_recently_sold_products-0.4 app/models/spree/product_decorator.rb
spree_recently_sold_products-0.3 app/models/spree/product_decorator.rb