Class: Workarea::GlobalE::Product

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/global_e/product.rb

Defined Under Namespace

Modules: ProductImageUrl, ProductUrl

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, sku, order_item: nil, delivery_quantity: nil) ⇒ Product

Returns a new instance of Product.



32
33
34
35
36
37
# File 'app/services/workarea/global_e/product.rb', line 32

def initialize(product, sku, order_item: nil, delivery_quantity: nil)
  @product = product
  @sku = sku
  @order_item = order_item
  @delivery_quantity = delivery_quantity
end

Instance Attribute Details

#delivery_quantityInteger? (readonly)

Quantity actually set for delivery for the product (to be used in Order methods described below, as needed)

Returns:

  • (Integer, nil)


443
444
445
# File 'app/services/workarea/global_e/product.rb', line 443

def delivery_quantity
  @delivery_quantity
end

#order_itemObject (readonly)

Returns the value of attribute order_item.



21
22
23
# File 'app/services/workarea/global_e/product.rb', line 21

def order_item
  @order_item
end

#productObject (readonly)

Returns the value of attribute product.



21
22
23
# File 'app/services/workarea/global_e/product.rb', line 21

def product
  @product
end

#skuObject (readonly)

Returns the value of attribute sku.



21
22
23
# File 'app/services/workarea/global_e/product.rb', line 21

def sku
  @sku
end

Class Method Details

.from_order_item(order_item, delivery_quantity: nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'app/services/workarea/global_e/product.rb', line 23

def self.from_order_item(order_item, delivery_quantity: nil)
  product = if order_item.product_attributes.present?
                Mongoid::Factory.from_db(Catalog::Product, order_item.product_attributes)
              else
                Catalog::Product.find_by_sku(order_item.sku)
              end
  new(product, order_item.sku, order_item: order_item, delivery_quantity: delivery_quantity)
end

Instance Method Details

#as_json(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/services/workarea/global_e/product.rb', line 39

def as_json(*args)
  {
    ProductCode: product_code,
    ProductGroupCode: product_group_code,
    CartItemId: cart_item_id,
    Name: name,
    Description: description,
    URL: url,
    Weight: weight,
    Height: height,
    Width: width,
    Length: length,
    ImageURL: catalog_product_image_url,
    ImageHeight: image_height,
    ImageWidth: image_width,
    ListPrice: list_price,
    OriginalListPrice: original_list_price,
    IsFixedPrice: is_fixed_price,
    OrderedQuantity: ordered_quantity,
    DeliveryQuantity: delivery_quantity,
    IsVirtual: is_virtual,
    IsBlockedForGlobalE: is_blocked_for_global_e,
    Attributes: attributes,
    SalePrice: sale_price,
    OriginalSalePrice: original_sale_price
  }.compact
end

#attributesArray<Workarea::GlobalE::Attribute>

Product’s custom attributes (such as Color, Size, etc.)

Returns:



534
535
536
537
538
# File 'app/services/workarea/global_e/product.rb', line 534

def attributes
  variant.details.map do |key, values|
    GlobalE::Attribute.new(type_code: key, name: values.join(", "), code: key)
  end
end

#attributes_englishArray<Workarea::GlobalE::Attribute>

Product’s custom attributes (such as Color, Size, etc.) in English

Returns:



544
545
# File 'app/services/workarea/global_e/product.rb', line 544

def attributes_english
end

#back_order_dateString

Estimated date for the backordered item to be in stock

Returns:

  • (String)


558
559
# File 'app/services/workarea/global_e/product.rb', line 558

def back_order_date
end

#brandWorkarea::GlobalE::Brand

Product’s brand



520
521
# File 'app/services/workarea/global_e/product.rb', line 520

def brand
end

#cart_item_idnil, String

Identifier of the cart item on the Merchant’s site. This property may be optionally specified in SendCart method only, so that the same value could be posted back when creating the order on the Merchant’s site with SendOrderToMerchant method.

Returns:

  • (nil, String)


120
121
122
123
124
# File 'app/services/workarea/global_e/product.rb', line 120

def cart_item_id
  return unless order_item.present?

  order_item.id.to_s
end

#cart_item_option_idString

Identifier of the child cart item “option” on the Merchant’s site. This value must be specified if the current cart item is related to a parent item (CartItemId must not be specified for this item because this attribute is applicable only to the “parent” item itself). For example, this item might indicate a package for the parent item in the same cart. This property may be optionally specified in SendCart method only, so that the same value could be posted back when creating the order on the Merchant’s site with SendOrderToMerchant method.

Returns:

  • (String)


153
154
# File 'app/services/workarea/global_e/product.rb', line 153

def cart_item_option_id
end

#catalog_product_image_urlString

Product’s image URL

Returns:

  • (String)


294
295
296
297
# File 'app/services/workarea/global_e/product.rb', line 294

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

#categoriesArray<Workarea::GlobalE::Category>

Product’s categories

Returns:



527
528
# File 'app/services/workarea/global_e/product.rb', line 527

def categories
end

#descriptionString

Description of the Product

Returns:

  • (String)


175
176
177
# File 'app/services/workarea/global_e/product.rb', line 175

def description
  product.description
end

#description_englishString

Description of the Product in English

Returns:

  • (String)


183
184
# File 'app/services/workarea/global_e/product.rb', line 183

def description_english
end

#generic_hs_codeString

Product’s generic (not country-specific) HS Code. If specified this property may assist in mapping the product for duties and taxes calculation purposes.

Returns:

  • (String)


215
216
# File 'app/services/workarea/global_e/product.rb', line 215

def generic_hs_code
end

#gift_messageString

Optional “gift message” text defined by the end customer that should be printed on the product.

Returns:

  • (String)


206
207
# File 'app/services/workarea/global_e/product.rb', line 206

def gift_message
end

#handling_codeString

Code applicable to the product on the Merchant’s site. This code may be optionally used by the Merchant to trigger a certain business logic when this product is included in the order posted back to the Merchant’s site with SendOrderToMerchant method.

Returns:

  • (String)


487
488
# File 'app/services/workarea/global_e/product.rb', line 487

def handling_code
end

#heightFloat

Product’s height in Merchant’s default unit of length measure (will be converted to CM).

Returns:

  • (Float)


250
251
252
# File 'app/services/workarea/global_e/product.rb', line 250

def height
  shipping_sku&.height
end

#image_heightInteger

Product’s image height in pixels

Returns:

  • (Integer)


303
304
305
306
# File 'app/services/workarea/global_e/product.rb', line 303

def image_height
  return unless image = variant_image || product.images.first
  image.image_height
end

#image_widthInteger

Product’s image width in pixels

Returns:

  • (Integer)


312
313
314
315
# File 'app/services/workarea/global_e/product.rb', line 312

def image_width
  return unless image = variant_image || product.images.first
  image.image_width
end

#is_back_orderedBoolean[

Boolean specifying if the product was ordered as a backed ordered item

Returns:

  • (Boolean[)

    Boolean[



551
552
# File 'app/services/workarea/global_e/product.rb', line 551

def is_back_ordered
end

#is_blocked_for_global_eBoolean

Setting this to TRUE indicates that the product is not available for international shipping

Returns:

  • (Boolean)


474
475
476
477
478
# File 'app/services/workarea/global_e/product.rb', line 474

def is_blocked_for_global_e
  return true if product.try(:gift_card?)

  product.global_e_forbidden?
end

#is_bundleBoolean

Setting this to TRUE indicates that the product represents a set of other products. If a bundled product has non-zero prices specified (i.e. OriginalListPrice, ListPrice, etc.), then all the contained products must have zero prices, and vice versa, to avoid double charging for the same products.

Returns:

  • (Boolean)


456
457
# File 'app/services/workarea/global_e/product.rb', line 456

def is_bundle
end

#is_fixed_priceBoolean

Setting this to TRUE indicates that the product’s price is fixed by the Merchant, in the default currency for the country. In this case, all price modifications are disabled for this product. Setting fixed prices is only allowed for the Countries where SupportsFixedPrices flag is set to TRUE.

Returns:

  • (Boolean)


425
426
427
# File 'app/services/workarea/global_e/product.rb', line 425

def is_fixed_price
  order_item.order.fixed_pricing
end

#is_virtualBoolean

Setting this to TRUE indicates that the product represents a virtual product that does not have weight or volume and doesn’t affect shipping calculation in Global-e checkout.

Returns:

  • (Boolean)


465
466
467
# File 'app/services/workarea/global_e/product.rb', line 465

def is_virtual
  product.digital?
end

#keywordsString

Product’s keywords

Returns:

  • (String)


190
191
# File 'app/services/workarea/global_e/product.rb', line 190

def keywords
end

#lengthFloat[

Product’s length in Merchant’s default unit of length measure (will be converted to CM).

Returns:

  • (Float[)

    Float[



268
269
270
# File 'app/services/workarea/global_e/product.rb', line 268

def length
  shipping_sku&.length
end

#line_item_original_sale_priceFloat

Line item (product in ordered quantity) sale price in original Merchant’s currency including the local VAT, before applying any price modifications. This property always denotes the price in the default Merchant’s country, regardless of UseCountryVAT for the end customer’s current country. If not specified, will be deemed equal to “OriginalSalePrice * OrderedQuantity”. If specified, will take preference over OriginalSalePrice.

Returns:

  • (Float)


405
406
# File 'app/services/workarea/global_e/product.rb', line 405

def line_item_original_sale_price
end

#line_item_sale_priceFloat

Line item (product in ordered quantity) sale price as displayed to the customer, after applying country coefficient, FX conversion and IncludeVAT handling, before rounding rules have been applied. If not specified, will be deemed equal to “SalePrice * OrderedQuantity”. If specified, will take preference over SalePrice.

Returns:

  • (Float)


377
378
# File 'app/services/workarea/global_e/product.rb', line 377

def line_item_sale_price
end

#list_priceFloat

Product list price (before any discounts) as displayed to the customer, after applying country coefficient, FX conversion, rounding rule (if applicable) and IncludingVAT handling. (optional in SendCart, SaveProductsBulk)

Returns:

  • (Float)


324
325
326
327
328
# File 'app/services/workarea/global_e/product.rb', line 324

def list_price
  return 0 unless is_fixed_price

  order_item.international_price_adjustments.first.data['original_price'].to_f
end

#local_vat_rate_typeWorkarea::GlobalE::VATRateType

VAT rate type or class that would be applied to this product if the order was placed by the local customer. This value must be specified if UseCountryVAT for the current Country is TRUE, and therefore VATRateType property actually denotes the VAT for the target country.

Returns:

  • (Workarea::GlobalE::VATRateType)


504
505
# File 'app/services/workarea/global_e/product.rb', line 504

def local_vat_rate_type
end

#nameString

Name of the Product

Returns:

  • (String)


160
161
162
# File 'app/services/workarea/global_e/product.rb', line 160

def name
  product.name
end

#name_englishString

Name of the Product in English

Returns:

  • (String)


168
169
# File 'app/services/workarea/global_e/product.rb', line 168

def name_english
end

#net_volumeFloat

Product’s net volume in Merchant’s default unit of volume measure (will be converted to cubic CM). If specified, this property indicates net volume of the product, excluding any packaging.

Returns:

  • (Float)


287
288
# File 'app/services/workarea/global_e/product.rb', line 287

def net_volume
end

#net_weightFloat

Product’s net weight in Merchant’s default unit of weight measure (will be converted to grams). If specified, this property indicates net weight of the product, excluding any packaging.

Returns:

  • (Float)


242
243
# File 'app/services/workarea/global_e/product.rb', line 242

def net_weight
end

#ordered_quantityInteger

Ordered quantity for the product (to be used in Checkout / Order methods described below, as needed)

Returns:

  • (Integer)


434
435
436
# File 'app/services/workarea/global_e/product.rb', line 434

def ordered_quantity
  order_item.quantity
end

#origin_country_codeString

2-char ISO country code of the product’s country of Origin. The Merchant’s country will be assumed if not specified.

Returns:

  • (String)


223
224
# File 'app/services/workarea/global_e/product.rb', line 223

def origin_country_code
end

#original_list_priceFloat

Product list price (before any discounts) in original Merchant’s currency including the local VAT, before applying any price modifications. This property always denotes the product’s price in the default Merchant’s country, regardless of UseCountryVAT for the end customer’s current country. (optional in SendCart, SaveProductsBulk)

Returns:

  • (Float)


339
340
341
342
343
344
# File 'app/services/workarea/global_e/product.rb', line 339

def original_list_price
  return 0 if is_fixed_price

  order_item.price_adjustments&.first&.data['original_price']&.to_f ||
    pricing_sku.find_price(quantity: ordered_quantity).regular.to_f
end

#original_sale_priceFloat

Product sale price in original Merchant’s currency including the local VAT, before applying any price modifications. This property always denotes the product’s price in the default Merchant’s country, regardless of UseCountryVAT for the end customer’s current country. (optional in SaveProductsList, SaveProductsBulk)

Returns:

  • (Float)


389
390
391
392
393
# File 'app/services/workarea/global_e/product.rb', line 389

def original_sale_price
  return 0 if is_fixed_price

  order_item.price_adjustments.first.unit.to_f
end

#parent_cart_item_idString

Identifier of the current item’s parent cart item on the Merchant’s site. This value must be specified if the current cart item is related to a parent item (CartItemId must not be specified for this item because this attribute is applicable only to the “parent” item itself). For example, this item might indicate a custom option (such as product package) for the parent item in the same cart. This property may be optionally specified in SendCart method only, so that the same value could be posted back when creating the order on the Merchant’s site with SendOrderToMerchant method.

Returns:

  • (String)


138
139
# File 'app/services/workarea/global_e/product.rb', line 138

def parent_cart_item_id
end

#price_coefficient_rateFloat

Rate applicable to this Product’s ProductClassCode if returned from CountryCoefficients method.

Returns:

  • (Float)


574
575
# File 'app/services/workarea/global_e/product.rb', line 574

def price_coefficient_rate
end

#product_class_codeString

Product class code used by the merchant to classify products for using different country coefficient rates.

Returns:

  • (String)


566
567
# File 'app/services/workarea/global_e/product.rb', line 566

def product_class_code
end

#product_codeString

SKU code used to identify the product on the Merchant’s site (to be mapped on Global-e side)

Returns:

  • (String)


72
73
74
# File 'app/services/workarea/global_e/product.rb', line 72

def product_code
  sku
end

#product_code_secondaryString

Secondary code that may be used to refer to the product on the Merchant’s site. This code may be used in addition to the ProductCode and is not guaranteed to be unique (may be reused for other products as long as the old product is not available on the merchant’s site anymore).

Returns:

  • (String)


97
98
# File 'app/services/workarea/global_e/product.rb', line 97

def product_code_secondary
end

#product_group_codeString

Product’s group code on the Merchant’s site (to be mapped on Global-e side). Usually this value is a part of product SKU code denoting a group of similar products (such as “the same product in different colors”).

optional

Returns:

  • (String)


85
86
87
# File 'app/services/workarea/global_e/product.rb', line 85

def product_group_code
  product.id
end

#product_group_code_secondaryString

Secondary code that may be used to refer to the group of products on the Merchant’s site. This code may be used in addition to the ProductGroupCode and is not guaranteed to be unique (may be reused for other groups as long as the old group is not available on the merchant’s site anymore).

optional

Returns:

  • (String)


110
111
# File 'app/services/workarea/global_e/product.rb', line 110

def product_group_code_secondary
end

#product_meta_dataWorkarea::GlobalE::ProductMetaData

Used to hold additional product data such as customer-defined product attributes.



581
582
# File 'app/services/workarea/global_e/product.rb', line 581

def 
end

#sale_priceFloat

Product sale price as displayed to the customer, after applying country coefficient, FX conversion, rounding rule (if applicable) and IncludeVAT handling. (optionalinSaveProductsList,SaveProductsBulk,GetCheckoutCartInfo)

Returns:

  • (Float)


353
354
355
356
357
# File 'app/services/workarea/global_e/product.rb', line 353

def sale_price
  return 0 unless is_fixed_price

  order_item.international_price_adjustments.first.unit.to_f
end

#sale_price_before_roundingFloat

Product sale price as displayed to the customer, after applying country coefficient, FX conversion and IncludeVAT handling, before rounding rules have been applied. If not specified, will be deemed equal to SalePrice.

Returns:

  • (Float)


366
367
# File 'app/services/workarea/global_e/product.rb', line 366

def sale_price_before_rounding
end

#sale_price_reasonString

Reason for the sale price. This property may optionally contain the text definition of the promo that has resulted in the price deduction for this product (such as “10% discount on all shoes”).

Returns:

  • (String)


414
415
# File 'app/services/workarea/global_e/product.rb', line 414

def sale_price_reason
end

#urlString

Product’s information page URL

Returns:

  • (String)


197
198
199
# File 'app/services/workarea/global_e/product.rb', line 197

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

#vat_categoryWorkarea::GlobalE::VatCategory

Product’s VAT category. A product may be assigned to a single VAT category on the merchant’s site. If available, the respective product’s HS Code should be used as VAT category for a product.



513
514
# File 'app/services/workarea/global_e/product.rb', line 513

def vat_category
end

#vat_rate_typeWorkarea::GlobalE::VATRateType

Product’s VAT rate type or class

Returns:

  • (Workarea::GlobalE::VATRateType)


494
495
# File 'app/services/workarea/global_e/product.rb', line 494

def vat_rate_type
end

#volumeFloat

Product’s volume in Merchant’s default unit of volume measure (will be converted to cubic CM). (optional, and alternative for specifying all 3 dimensions above)

Returns:

  • (Float)


278
279
# File 'app/services/workarea/global_e/product.rb', line 278

def volume
end

#weightFloat

Product’s weight in Merchant’s default unit of weight measure (will be converted to grams). Merchant’s default product weight will be used if not specified.

Returns:

  • (Float)


232
233
234
# File 'app/services/workarea/global_e/product.rb', line 232

def weight
  shipping_sku&.weight
end

#widthFloat

Product’s width in Merchant’s default unit of length measure (will be converted to CM).

Returns:

  • (Float)


259
260
261
# File 'app/services/workarea/global_e/product.rb', line 259

def width
  shipping_sku&.width
end