@gameroom/cli
Version:
A command line tool for Gameroom
90 lines (87 loc) • 2.67 kB
JavaScript
const { google_product_categories } = require('../../refs'),
{ componentString, extractHTMLText, onlinePrice } = require('../../helpers')
module.exports = class Product {
constructor(data) {
if (!data) data = {}
const {
age_group,
availability,
brand,
color,
condition,
description,
gender,
google_product_category,
gtin,
id,
image_link,
item_group_id,
link,
mpn,
price,
product_type,
sale_price,
sale_price_effective,
shipping,
shipping_label,
shipping_weight,
size,
title
} = data
this.age_group = age_group
this.availability = availability
this.brand = brand
this.color = color
this.condition = condition
this.description = description
this.gender = gender
this.google_product_category = google_product_category
this.gtin = gtin
this.id = id
this.image_link = image_link
this.item_group_id = item_group_id
this.link = link
this.mpn = mpn
this.price = price
this.product_type = product_type
this.sale_price = sale_price
this.sale_price_effective = sale_price_effective
this.shipping = shipping
this.shipping_label = shipping_label
this.shipping_weight = shipping_weight
this.size = size
this.title = title
}
static fromUnitExtended(unit) {
const info = unit.info ? extractHTMLText(unit.info) : ''
const options_string = unit.options_string || ''
const description = info && options_string ? `${info}\n\n${options_string}` :
info ? info : options_string ? options_string : ''
const price = `${(unit.amount * .01).toFixed(2)} USD`
return new Product({
age_group: unit.properties['age group'] || null,
availability: 'in stock',
brand: unit.properties.brand || null,
color: unit.properties.color || null,
condition: 'used',
description,
gender: null,
google_product_category: google_product_categories[unit.properties.google_category],
gtin: unit.properties.gtin || unit.identifier,
id: unit.id,
image_link: unit.image,
item_group_id: unit.identifier ? unit.identifier : unit.product_id,
link: `https://thisisgameroom.com/products/${unit.id}`,
mpn: unit.properties.mpn || null,
price,
product_type: null,
sale_price: null,
sale_price_effective: null,
shipping: null,
shipping_label: null,
shipping_weight: `${unit.weight * 0.0625} lbs`,
size: null,
title: componentString(unit.name, '-', unit.subname, unit.price ? '|' : null, unit.price)
})
}
}