cart display works but it's far from finished
This commit is contained in:
@@ -31,3 +31,15 @@ update_cart_item = ->() {
|
||||
}
|
||||
put '/cart/item', &update_cart_item
|
||||
post '/cart/item', &update_cart_item
|
||||
|
||||
|
||||
# gets list of items in cart without count
|
||||
get '/cart/item/display' do
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
item_ids = cart.item_in_carts.map do |x|
|
||||
x.item_id
|
||||
end
|
||||
items = []
|
||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
@@ -71,9 +71,12 @@ get '/item/sub_category/:sub_category_id/offset/:offset/limit/:limit' do |sub_ca
|
||||
end
|
||||
|
||||
# gets list of items in cart without count
|
||||
get '/item/cart' do |cart|
|
||||
cart = Cart.find_or_create(anonymous_id, -1).to_json
|
||||
item_ids = cart.item_in_carts.map ->(x) { x.item_id }
|
||||
items = Item.find(item_ids)
|
||||
get '/cart/item_details' do
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
item_ids = cart.item_in_carts.map do |x|
|
||||
x.item_id
|
||||
end
|
||||
items = []
|
||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
|
||||
@@ -3,10 +3,14 @@ class Item < ActiveRecord::Base
|
||||
has_many :multi_media_descriptions
|
||||
belongs_to :sub_category
|
||||
|
||||
attr_accessor :count # used for cart
|
||||
def attributes
|
||||
super.merge('count' => self.count)
|
||||
end
|
||||
|
||||
# TODO: change "best selling" algorithm when get some data - currently it's only sorted by earnings
|
||||
scope :best_selling, -> (offset, limit) { where(:on_display => true).order("(list_price - current_input_price) DESC").limit(limit).offset(offset) }
|
||||
scope :best_selling_in_sub_category, -> (sub_category_id, offset, limit) { best_selling(offset, limit).where(sub_category_id: sub_category_id) }
|
||||
scope :best_selling_in_category, -> (category_id, offset, limit) { best_selling(offset, limit).joins( sub_category: [:category] ).where(["category_id = ?", category_id]) }
|
||||
scope :best_selling_in_section, -> (section_id, offset, limit) { best_selling(offset, limit).joins( sub_category: [category: [ :section ]] ).where( ["section_id = ?", section_id] ) }
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user