Class: Workarea::GlobalE::Product
- Inherits:
-
Object
- Object
- Workarea::GlobalE::Product
- Defined in:
- app/services/workarea/global_e/product.rb
Defined Under Namespace
Modules: ProductImageUrl, ProductUrl
Instance Attribute Summary collapse
-
#delivery_quantity ⇒ Integer?
readonly
Quantity actually set for delivery for the product (to be used in Order methods described below, as needed).
-
#order_item ⇒ Object
readonly
Returns the value of attribute order_item.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#sku ⇒ Object
readonly
Returns the value of attribute sku.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
-
#attributes ⇒ Array<Workarea::GlobalE::Attribute>
Product’s custom attributes (such as Color, Size, etc.).
-
#attributes_english ⇒ Array<Workarea::GlobalE::Attribute>
Product’s custom attributes (such as Color, Size, etc.) in English.
-
#back_order_date ⇒ String
Estimated date for the backordered item to be in stock.
-
#brand ⇒ Workarea::GlobalE::Brand
Product’s brand.
-
#cart_item_id ⇒ nil, String
Identifier of the cart item on the Merchant’s site.
-
#cart_item_option_id ⇒ String
Identifier of the child cart item “option” on the Merchant’s site.
-
#catalog_product_image_url ⇒ String
Product’s image URL.
-
#categories ⇒ Array<Workarea::GlobalE::Category>
Product’s categories.
-
#description ⇒ String
Description of the Product.
-
#description_english ⇒ String
Description of the Product in English.
-
#generic_hs_code ⇒ String
Product’s generic (not country-specific) HS Code.
-
#gift_message ⇒ String
Optional “gift message” text defined by the end customer that should be printed on the product.
-
#handling_code ⇒ String
Code applicable to the product on the Merchant’s site.
-
#height ⇒ Float
Product’s height in Merchant’s default unit of length measure (will be converted to CM).
-
#image_height ⇒ Integer
Product’s image height in pixels.
-
#image_width ⇒ Integer
Product’s image width in pixels.
-
#initialize(product, sku, order_item: nil, delivery_quantity: nil) ⇒ Product
constructor
A new instance of Product.
-
#is_back_ordered ⇒ Boolean[
Boolean specifying if the product was ordered as a backed ordered item.
-
#is_blocked_for_global_e ⇒ Boolean
Setting this to TRUE indicates that the product is not available for international shipping.
-
#is_bundle ⇒ Boolean
Setting this to TRUE indicates that the product represents a set of other products.
-
#is_fixed_price ⇒ Boolean
Setting this to TRUE indicates that the product’s price is fixed by the Merchant, in the default currency for the country.
-
#is_virtual ⇒ Boolean
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.
-
#keywords ⇒ String
Product’s keywords.
-
#length ⇒ Float[
Product’s length in Merchant’s default unit of length measure (will be converted to CM).
-
#line_item_original_sale_price ⇒ Float
Line item (product in ordered quantity) sale price in original Merchant’s currency including the local VAT, before applying any price modifications.
-
#line_item_sale_price ⇒ Float
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.
-
#list_price ⇒ Float
Product list price (before any discounts) as displayed to the customer, after applying country coefficient, FX conversion, rounding rule (if applicable) and IncludingVAT handling.
-
#local_vat_rate_type ⇒ Workarea::GlobalE::VATRateType
VAT rate type or class that would be applied to this product if the order was placed by the local customer.
-
#name ⇒ String
Name of the Product.
-
#name_english ⇒ String
Name of the Product in English.
-
#net_volume ⇒ Float
Product’s net volume in Merchant’s default unit of volume measure (will be converted to cubic CM).
-
#net_weight ⇒ Float
Product’s net weight in Merchant’s default unit of weight measure (will be converted to grams).
-
#ordered_quantity ⇒ Integer
Ordered quantity for the product (to be used in Checkout / Order methods described below, as needed).
-
#origin_country_code ⇒ String
2-char ISO country code of the product’s country of Origin.
-
#original_list_price ⇒ Float
Product list price (before any discounts) in original Merchant’s currency including the local VAT, before applying any price modifications.
-
#original_sale_price ⇒ Float
Product sale price in original Merchant’s currency including the local VAT, before applying any price modifications.
-
#parent_cart_item_id ⇒ String
Identifier of the current item’s parent cart item on the Merchant’s site.
-
#price_coefficient_rate ⇒ Float
Rate applicable to this Product’s ProductClassCode if returned from CountryCoefficients method.
-
#product_class_code ⇒ String
Product class code used by the merchant to classify products for using different country coefficient rates.
-
#product_code ⇒ String
SKU code used to identify the product on the Merchant’s site (to be mapped on Global-e side).
-
#product_code_secondary ⇒ String
Secondary code that may be used to refer to the product on the Merchant’s site.
-
#product_group_code ⇒ String
Product’s group code on the Merchant’s site (to be mapped on Global-e side).
-
#product_group_code_secondary ⇒ String
Secondary code that may be used to refer to the group of products on the Merchant’s site.
-
#product_meta_data ⇒ Workarea::GlobalE::ProductMetaData
Used to hold additional product data such as customer-defined product attributes.
-
#sale_price ⇒ Float
Product sale price as displayed to the customer, after applying country coefficient, FX conversion, rounding rule (if applicable) and IncludeVAT handling.
-
#sale_price_before_rounding ⇒ Float
Product sale price as displayed to the customer, after applying country coefficient, FX conversion and IncludeVAT handling, before rounding rules have been applied.
-
#sale_price_reason ⇒ String
Reason for the sale price.
-
#url ⇒ String
Product’s information page URL.
-
#vat_category ⇒ Workarea::GlobalE::VatCategory
Product’s VAT category.
-
#vat_rate_type ⇒ Workarea::GlobalE::VATRateType
Product’s VAT rate type or class.
-
#volume ⇒ Float
Product’s volume in Merchant’s default unit of volume measure (will be converted to cubic CM).
-
#weight ⇒ Float
Product’s weight in Merchant’s default unit of weight measure (will be converted to grams).
-
#width ⇒ Float
Product’s width in Merchant’s default unit of length measure (will be converted to CM).
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_quantity ⇒ Integer? (readonly)
Quantity actually set for delivery for the product (to be used in Order methods described below, as needed)
443 444 445 |
# File 'app/services/workarea/global_e/product.rb', line 443 def delivery_quantity @delivery_quantity end |
#order_item ⇒ Object (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 |
#product ⇒ Object (readonly)
Returns the value of attribute product.
21 22 23 |
# File 'app/services/workarea/global_e/product.rb', line 21 def product @product end |
#sku ⇒ Object (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 |
#attributes ⇒ Array<Workarea::GlobalE::Attribute>
Product’s custom attributes (such as Color, Size, etc.)
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_english ⇒ Array<Workarea::GlobalE::Attribute>
Product’s custom attributes (such as Color, Size, etc.) in English
544 545 |
# File 'app/services/workarea/global_e/product.rb', line 544 def attributes_english end |
#back_order_date ⇒ String
Estimated date for the backordered item to be in stock
558 559 |
# File 'app/services/workarea/global_e/product.rb', line 558 def back_order_date end |
#brand ⇒ Workarea::GlobalE::Brand
Product’s brand
520 521 |
# File 'app/services/workarea/global_e/product.rb', line 520 def brand end |
#cart_item_id ⇒ nil, 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.
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_id ⇒ String
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.
153 154 |
# File 'app/services/workarea/global_e/product.rb', line 153 def cart_item_option_id end |
#catalog_product_image_url ⇒ String
Product’s image URL
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 |
#categories ⇒ Array<Workarea::GlobalE::Category>
Product’s categories
527 528 |
# File 'app/services/workarea/global_e/product.rb', line 527 def categories end |
#description ⇒ String
Description of the Product
175 176 177 |
# File 'app/services/workarea/global_e/product.rb', line 175 def description product.description end |
#description_english ⇒ String
Description of the Product in English
183 184 |
# File 'app/services/workarea/global_e/product.rb', line 183 def description_english end |
#generic_hs_code ⇒ String
Product’s generic (not country-specific) HS Code. If specified this property may assist in mapping the product for duties and taxes calculation purposes.
215 216 |
# File 'app/services/workarea/global_e/product.rb', line 215 def generic_hs_code end |
#gift_message ⇒ String
Optional “gift message” text defined by the end customer that should be printed on the product.
206 207 |
# File 'app/services/workarea/global_e/product.rb', line 206 def end |
#handling_code ⇒ String
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.
487 488 |
# File 'app/services/workarea/global_e/product.rb', line 487 def handling_code end |
#height ⇒ Float
Product’s height in Merchant’s default unit of length measure (will be converted to CM).
250 251 252 |
# File 'app/services/workarea/global_e/product.rb', line 250 def height shipping_sku&.height end |
#image_height ⇒ Integer
Product’s image height in pixels
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_width ⇒ Integer
Product’s image width in pixels
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_ordered ⇒ Boolean[
Boolean specifying if the product was ordered as a backed ordered item
551 552 |
# File 'app/services/workarea/global_e/product.rb', line 551 def is_back_ordered end |
#is_blocked_for_global_e ⇒ Boolean
Setting this to TRUE indicates that the product is not available for international shipping
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_bundle ⇒ Boolean
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.
456 457 |
# File 'app/services/workarea/global_e/product.rb', line 456 def is_bundle end |
#is_fixed_price ⇒ Boolean
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.
425 426 427 |
# File 'app/services/workarea/global_e/product.rb', line 425 def is_fixed_price order_item.order.fixed_pricing end |
#is_virtual ⇒ Boolean
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.
465 466 467 |
# File 'app/services/workarea/global_e/product.rb', line 465 def is_virtual product.digital? end |
#keywords ⇒ String
Product’s keywords
190 191 |
# File 'app/services/workarea/global_e/product.rb', line 190 def keywords end |
#length ⇒ Float[
Product’s length in Merchant’s default unit of length measure (will be converted to CM).
268 269 270 |
# File 'app/services/workarea/global_e/product.rb', line 268 def length shipping_sku&.length end |
#line_item_original_sale_price ⇒ Float
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.
405 406 |
# File 'app/services/workarea/global_e/product.rb', line 405 def line_item_original_sale_price end |
#line_item_sale_price ⇒ Float
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.
377 378 |
# File 'app/services/workarea/global_e/product.rb', line 377 def line_item_sale_price end |
#list_price ⇒ Float
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)
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_type ⇒ Workarea::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.
504 505 |
# File 'app/services/workarea/global_e/product.rb', line 504 def local_vat_rate_type end |
#name ⇒ String
Name of the Product
160 161 162 |
# File 'app/services/workarea/global_e/product.rb', line 160 def name product.name end |
#name_english ⇒ String
Name of the Product in English
168 169 |
# File 'app/services/workarea/global_e/product.rb', line 168 def name_english end |
#net_volume ⇒ Float
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.
287 288 |
# File 'app/services/workarea/global_e/product.rb', line 287 def net_volume end |
#net_weight ⇒ Float
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.
242 243 |
# File 'app/services/workarea/global_e/product.rb', line 242 def net_weight end |
#ordered_quantity ⇒ Integer
Ordered quantity for the product (to be used in Checkout / Order methods described below, as needed)
434 435 436 |
# File 'app/services/workarea/global_e/product.rb', line 434 def ordered_quantity order_item.quantity end |
#origin_country_code ⇒ String
2-char ISO country code of the product’s country of Origin. The Merchant’s country will be assumed if not specified.
223 224 |
# File 'app/services/workarea/global_e/product.rb', line 223 def origin_country_code end |
#original_list_price ⇒ Float
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)
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_price ⇒ Float
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)
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_id ⇒ String
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.
138 139 |
# File 'app/services/workarea/global_e/product.rb', line 138 def parent_cart_item_id end |
#price_coefficient_rate ⇒ Float
Rate applicable to this Product’s ProductClassCode if returned from CountryCoefficients method.
574 575 |
# File 'app/services/workarea/global_e/product.rb', line 574 def price_coefficient_rate end |
#product_class_code ⇒ String
Product class code used by the merchant to classify products for using different country coefficient rates.
566 567 |
# File 'app/services/workarea/global_e/product.rb', line 566 def product_class_code end |
#product_code ⇒ String
SKU code used to identify the product on the Merchant’s site (to be mapped on Global-e side)
72 73 74 |
# File 'app/services/workarea/global_e/product.rb', line 72 def product_code sku end |
#product_code_secondary ⇒ String
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).
97 98 |
# File 'app/services/workarea/global_e/product.rb', line 97 def product_code_secondary end |
#product_group_code ⇒ String
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
85 86 87 |
# File 'app/services/workarea/global_e/product.rb', line 85 def product_group_code product.id end |
#product_group_code_secondary ⇒ String
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
110 111 |
# File 'app/services/workarea/global_e/product.rb', line 110 def product_group_code_secondary end |
#product_meta_data ⇒ Workarea::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_price ⇒ Float
Product sale price as displayed to the customer, after applying country coefficient, FX conversion, rounding rule (if applicable) and IncludeVAT handling. (optionalinSaveProductsList,SaveProductsBulk,GetCheckoutCartInfo)
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_rounding ⇒ Float
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.
366 367 |
# File 'app/services/workarea/global_e/product.rb', line 366 def sale_price_before_rounding end |
#sale_price_reason ⇒ String
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”).
414 415 |
# File 'app/services/workarea/global_e/product.rb', line 414 def sale_price_reason end |
#url ⇒ String
Product’s information page URL
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_category ⇒ Workarea::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_type ⇒ Workarea::GlobalE::VATRateType
Product’s VAT rate type or class
494 495 |
# File 'app/services/workarea/global_e/product.rb', line 494 def vat_rate_type end |
#volume ⇒ Float
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)
278 279 |
# File 'app/services/workarea/global_e/product.rb', line 278 def volume end |
#weight ⇒ Float
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.
232 233 234 |
# File 'app/services/workarea/global_e/product.rb', line 232 def weight shipping_sku&.weight end |
#width ⇒ Float
Product’s width in Merchant’s default unit of length measure (will be converted to CM).
259 260 261 |
# File 'app/services/workarea/global_e/product.rb', line 259 def width shipping_sku&.width end |