Class: Workarea::Listrak::Models::ProductForm

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::AssetUrlHelper, ApplicationHelper, I18n::DefaultUrlOptions
Defined in:
app/services/workarea/listrak/models/product_form.rb

Instance Method Summary collapse

Constructor Details

#initialize(product, sku, pricing_sku: nil, inventory_sku: nil) ⇒ ProductForm

Returns a new instance of ProductForm.

Parameters:

  • product (Workarea::Catalog::Product)
  • sku (String)


13
14
15
16
17
18
# File 'app/services/workarea/listrak/models/product_form.rb', line 13

def initialize(product, sku, pricing_sku: nil, inventory_sku: nil)
  @product = product
  @sku = sku
  @pricing_sku = pricing_sku
  @inventory_sku = inventory_sku
end

Instance Method Details

#as_json(_options) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
55
# File 'app/services/workarea/listrak/models/product_form.rb', line 20

def as_json(_options)
  {
    brand: brand,
    category: category,
    color: color,
    description: description,
    discontinued: discontinued,
    gender: gender,
    imageUrl: image_url,
    inStock: in_stock,
    isClearance: is_clearence,
    isOutlet: is_outlet,
    isPurchasable: is_purchasable,
    isViewable: is_viewable,
    linkUrl: link_url,
    masterSku: master_sku,
    meta1: meta1,
    meta2: meta2,
    meta3: meta3,
    meta4: meta4,
    meta5: meta5,
    msrp: msrp,
    onSale: on_sale,
    price: price,
    qoh: quantity_on_hand,
    saleEndDate: sale_end_date,
    salePrice: sale_price,
    saleStartDate: sale_start_date,
    size: size,
    sku: sku,
    style: style,
    subCategory: sub_category,
    title: title,
    unitCost: unit_cost
  }.compact
end

#brandString

Brand name of product

limited to 50 characters

Returns:

  • (String)


63
64
65
# File 'app/services/workarea/listrak/models/product_form.rb', line 63

def brand
  product.try(:brand)
end

#categoryString

Category or department

limited to 50 characters

Returns:

  • (String)


73
74
75
# File 'app/services/workarea/listrak/models/product_form.rb', line 73

def category
  categorization.default_model.try(:name)
end

#colorString

Color of product (e.g. green, paisley, etc.)

limited to 100 characters

Returns:

  • (String)


83
84
85
# File 'app/services/workarea/listrak/models/product_form.rb', line 83

def color
  variant.fetch_detail('color')
end

#descriptionString

Description of product

limited to 4000 characters

Returns:

  • (String)


93
94
95
# File 'app/services/workarea/listrak/models/product_form.rb', line 93

def description
  product.description
end

#discontinuedBoolean

Explicit indicator that the item has been discontinued

Returns:

  • (Boolean)


101
102
# File 'app/services/workarea/listrak/models/product_form.rb', line 101

def discontinued
end

#genderString

Gender of product (if applicable)

limited to 50 characters

Returns:

  • (String)


110
111
# File 'app/services/workarea/listrak/models/product_form.rb', line 110

def gender
end

#image_urlString

URL for product image

limited to 500 characters

Returns:

  • (String)


119
120
121
122
# File 'app/services/workarea/listrak/models/product_form.rb', line 119

def image_url
  return unless image = variant_image || product.images.first
  @image_url ||= product_image_url(image, :detail)
end

#in_stockBoolean

Explicit indicator that the item is in stock

Returns:

  • (Boolean)


128
129
130
# File 'app/services/workarea/listrak/models/product_form.rb', line 128

def in_stock
  quantity_on_hand > 0
end

#is_clearenceBoolean

Explicit indicator that the item is a clearance item

Returns:

  • (Boolean)


136
137
# File 'app/services/workarea/listrak/models/product_form.rb', line 136

def is_clearence
end

#is_outletBoolean

Explicit indicator that the item is an outlet item

Returns:

  • (Boolean)


143
144
# File 'app/services/workarea/listrak/models/product_form.rb', line 143

def is_outlet
end

#is_purchasableBoolean

Explicit indicator that the item can be included in recommendations

Returns:

  • (Boolean)


150
151
152
# File 'app/services/workarea/listrak/models/product_form.rb', line 150

def is_purchasable
  product.purchasable? && inventory_sku.purchasable?
end

#is_viewableBoolean

Flag used in some systems to determine if the item should be included in recommendations

Returns:

  • (Boolean)


158
159
160
# File 'app/services/workarea/listrak/models/product_form.rb', line 158

def is_viewable
  product.purchasable? && inventory_sku.purchasable?
end

URL for product webpage

limited to 500 characters

Returns:

  • (String)


168
169
170
# File 'app/services/workarea/listrak/models/product_form.rb', line 168

def link_url
  product_url(product, host: Workarea.config.host)
end

#master_skuString

Unique stock number of the master product

limited to 100 characters

Returns:

  • (String)


178
179
180
# File 'app/services/workarea/listrak/models/product_form.rb', line 178

def master_sku
  product.id.to_s
end

#meta1String

Additional meta imformation

limted to 500 characters

Returns:

  • (String)


188
189
# File 'app/services/workarea/listrak/models/product_form.rb', line 188

def meta1
end

#meta2String

Additional meta imformation

limted to 500 characters

Returns:

  • (String)


197
198
# File 'app/services/workarea/listrak/models/product_form.rb', line 197

def meta2
end

#meta3String

Additional meta imformation

limted to 500 characters

Returns:

  • (String)


206
207
# File 'app/services/workarea/listrak/models/product_form.rb', line 206

def meta3
end

#meta4String

Additional meta imformation

limted to 500 characters

Returns:

  • (String)


215
216
# File 'app/services/workarea/listrak/models/product_form.rb', line 215

def meta4
end

#meta5String

Additional meta imformation

limted to 500 characters

Returns:

  • (String)


224
225
# File 'app/services/workarea/listrak/models/product_form.rb', line 224

def meta5
end

#msrpFloat

Retail price of the product

Returns:

  • (Float)


231
232
# File 'app/services/workarea/listrak/models/product_form.rb', line 231

def msrp
end

#on_saleBoolean

Explicit indicator that the item is on sale

Returns:

  • (Boolean)

    Boolean



238
239
240
# File 'app/services/workarea/listrak/models/product_form.rb', line 238

def on_sale
  pricing_sku.on_sale?
end

#priceFloat

List price of product

Returns:

  • (Float)


246
247
248
# File 'app/services/workarea/listrak/models/product_form.rb', line 246

def price
  pricing_sku.find_price.sell.to_f
end

#quantity_on_handObject

Quantity on hand

return [Integer]



254
255
256
# File 'app/services/workarea/listrak/models/product_form.rb', line 254

def quantity_on_hand
  inventory_sku.available
end

#sale_end_dateString

End date time of sale

Returns:

  • (String)

    sale_end_date DateTime in %FT%TZ



262
263
# File 'app/services/workarea/listrak/models/product_form.rb', line 262

def sale_end_date
end

#sale_priceFloat

Sale price of product

Returns:

  • (Float)

    Float



269
270
271
# File 'app/services/workarea/listrak/models/product_form.rb', line 269

def sale_price
  pricing_sku.find_price.sale.to_f
end

#sale_start_dateString

Start date time of sale

Returns:

  • (String)

    sale_start_date DateTime in %FT%TZ



277
278
# File 'app/services/workarea/listrak/models/product_form.rb', line 277

def sale_start_date
end

#sizeString

Size of product (e.g. small, M, 6 7/8”)

limited to 50 characters

Returns:

  • (String)


286
287
288
# File 'app/services/workarea/listrak/models/product_form.rb', line 286

def size
  variant.fetch_detail('size')
end

#skuString

Unique stock number of product

limited to 100 characters

Returns:

  • (String)


296
297
298
# File 'app/services/workarea/listrak/models/product_form.rb', line 296

def sku
  @sku
end

#styleString

Style of product

limited to 100 characters

Returns:

  • (String)


306
307
# File 'app/services/workarea/listrak/models/product_form.rb', line 306

def style
end

#sub_categoryString

Sub-category or sub-department

limited to 50 characters

Returns:

  • (String)


315
316
317
# File 'app/services/workarea/listrak/models/product_form.rb', line 315

def sub_category
  categorization.secondary_model.try(:name)
end

#titleString

Product name

limited to 500 characters

Returns:

  • (String)


325
326
327
# File 'app/services/workarea/listrak/models/product_form.rb', line 325

def title
  product.name
end

#unit_costFloat

Price per individual item

Returns:

  • (Float)


333
334
# File 'app/services/workarea/listrak/models/product_form.rb', line 333

def unit_cost
end