Sha256: 53eb90223044773f88866451be9cb65832ea02aa8dc981606073d538bee8d8c6

Contents?: true

Size: 438 Bytes

Versions: 2

Compression:

Stored size: 438 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_recently_sold_products-0.2 app/models/spree/product_decorator.rb
spree_recently_sold_products-0.1 app/models/spree/product_decorator.rb