Module: StoresHelper

Defined in:
app/helpers/stores_helper.rb

Instance Method Summary collapse

Instance Method Details

#category_item_grouped(items) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/stores_helper.rb', line 19

def category_item_grouped(items)
  h = {}
  items.each do |i|
    # First layer is product category
    h[i.product_category] ||= {}

    # Build the item
    h[i.product_category][i] ||= { Store::WARMLYYOURS_US_ID => {}, Store::WARMLYYOURS_CA_ID => {} }
    # Build the store item
    i.store_items.available.with_back_order_quantities.select('store_items.*, (select amount from catalog_items ci where ci.store_item_id = store_items.id order by catalog_id limit 1) as msrp, (select currency_symbol from catalogs c inner join catalog_items ci on ci.catalog_id = c.id where ci.store_item_id = store_items.id order by catalog_id limit 1) as msrp_currency_symbol').each do |si|
      h[i.product_category][i][si.store_id] = {
        on_hand: si.qty_on_hand,
        available: si.qty_available,
        backordered: si.qty_backordered,
        stock_class: stock_class(si),
        non_stock: si.permanent_qty_available.present?,
        store_item_id: si.id,
        store_id: si.store_id,
        item_id: i.id,
        msrp: si.msrp,
        msrp_currency_symbol: si.msrp_currency_symbol
      }
    end
  end
  h
end

#setup_store(store) ⇒ Object



2
3
4
5
6
7
# File 'app/helpers/stores_helper.rb', line 2

def setup_store(store)
  store.tap do |s|
    s.build_warehouse_address unless s.warehouse_address
    s.build_mailing_address unless s.mailing_address
  end
end

#stock_class(store_item) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/helpers/stores_helper.rb', line 9

def stock_class(store_item)
  if store_item.qty_available.zero?
    'out_of_stock'
  elsif store_item.qty_available <= store_item.item.qty_warn_on_stock
    'stock_warning'
  else
    'stocked'
  end
end