Class: Workarea::GlobalE::Discount
- Inherits:
-
Object
- Object
- Workarea::GlobalE::Discount
- Defined in:
- app/services/workarea/global_e/discount.rb
Instance Attribute Summary collapse
-
#discount ⇒ Object
readonly
Returns the value of attribute discount.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#price_adjustment ⇒ Object
readonly
Returns the value of attribute price_adjustment.
Instance Method Summary collapse
- #as_json(*_args) ⇒ Object
-
#calculation_mode ⇒ Object
One of the following possible values of CalculationModeOptions enumeration denoting the calculation mode of a discount to be implemented by GEM:.
-
#coupon_code ⇒ String
Merchant’s coupon code used for this discount (applicable to coupon-based discounts only).
-
#description ⇒ String
Discount textual description.
-
#discount_code ⇒ String
Discount code used to identify the discount on the Merchant’s site.
-
#discount_type ⇒ Integer
One of the following possible values of DiscountTypeOptions enumeration denoting a type of a discount:.
-
#discount_value ⇒ Float
Discount value as displayed to the customer, after applying country coefficient, FX conversion and IncludeVAT handling.
-
#initialize(discount, order:, price_adjustment:) ⇒ Discount
constructor
A new instance of Discount.
-
#local_vat_rate ⇒ Float
VAT rate that would be applied to this discount if the order was placed by the local customer.
-
#loyalty_voucher_code ⇒ String
Code used on the Merchant’s site to identify the Loyalty Voucher that this discount is based on.
-
#name ⇒ String
Discount name.
-
#original_discount_value ⇒ Float
Discount value in original Merchant’s currency including the local VAT, before applying any price modifications.
-
#product_cart_item_id ⇒ String
Identifier of the product cart item related to this discount on the Merchant’s site.
-
#vat_rate ⇒ Float
VAT rate applied to this discount.
Constructor Details
#initialize(discount, order:, price_adjustment:) ⇒ Discount
Returns a new instance of Discount.
6 7 8 9 10 |
# File 'app/services/workarea/global_e/discount.rb', line 6 def initialize(discount, order:, price_adjustment:) @discount = discount @order = order @price_adjustment = price_adjustment end |
Instance Attribute Details
#discount ⇒ Object (readonly)
Returns the value of attribute discount.
4 5 6 |
# File 'app/services/workarea/global_e/discount.rb', line 4 def discount @discount end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/services/workarea/global_e/discount.rb', line 4 def order @order end |
#price_adjustment ⇒ Object (readonly)
Returns the value of attribute price_adjustment.
4 5 6 |
# File 'app/services/workarea/global_e/discount.rb', line 4 def price_adjustment @price_adjustment end |
Instance Method Details
#as_json(*_args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/workarea/global_e/discount.rb', line 12 def as_json(*_args) { OriginalDiscountValue: original_discount_value, VATRate: vat_rate, LocalVATRate: local_vat_rate, DiscountValue: discount_value, Name: name, Description: description, CouponCode: coupon_code, ProductCartItemId: product_cart_item_id, DiscountCode: discount_code, LoyaltyVoucherCode: loyalty_voucher_code, DiscountType: discount_type, CalculationMode: calculation_mode }.compact end |
#calculation_mode ⇒ Object
One of the following possible values of CalculationModeOptions enumeration denoting the calculation mode of a discount to be implemented by GEM:
| CalculationMode Option Value | Name | Description | | 1 (default) | Percentage discount | Discount value specified in OriginalDiscountValue should be used for calculating the discount’s
DiscountValue as percentage of the full product’s price (specified in Product.OriginalSalePrice
for line item level discounts) or cart price (sum of all Product.OriginalSalePrice values) for cart level discounts. |
| 2 | Fixed in original currency | Discount value specified in OriginalDiscountValue denotes the fixed value in the merchant’s
currency. When calculating the discount’s DiscountValue, only the respective FX rate should be
applied to OriginalDiscountValue. No other price modifications (such as country coefficient) should be performed. |
| 3 | Fixed in customer currency | Discount value specified in DiscountValue denotes the fixed value nominated in the end
customer’s currency that shouldn’t be affected by any price modifications (such as country coefficient). |
return [Integer]
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/services/workarea/global_e/discount.rb', line 172 def calculation_mode return 3 if order.fixed_pricing? return 1 if free_gift? amount_type = discount.try(:amount_type) case amount_type when :percent 1 when :flat 2 end end |
#coupon_code ⇒ String
Merchant’s coupon code used for this discount (applicable to coupon-based discounts only)
99 100 101 |
# File 'app/services/workarea/global_e/discount.rb', line 99 def coupon_code (discount_promo_codes & order_promo_codes).first end |
#description ⇒ String
Discount textual description
90 91 92 |
# File 'app/services/workarea/global_e/discount.rb', line 90 def description "#{discount.class.name.demodulize.underscore.titleize} - #{name}" end |
#discount_code ⇒ String
Discount code used to identify the discount 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.
123 124 125 |
# File 'app/services/workarea/global_e/discount.rb', line 123 def discount_code price_adjustment.global_e_discount_code end |
#discount_type ⇒ Integer
One of the following possible values of DiscountTypeOptions enumeration denoting a type of a discount:
| DiscountType Option Value | Name | Description | | 1 | Cart Discount | Discount related to volume, amount, coupon or another promotion value. | | 2 | Shipping Discount | Discount aimed to sponsor international shipping. | | 3 | Loyalty points discount | Discount applied against the Merchant’s loyalty points to be spent for this purchase. | | 4 | Duties discount | Discount aimed to sponsor taxes & duties pre- paid by the end customer in Global-e checkout. | | 5 | Checkout Loyalty Points Discount | Discount applied against the Merchant’s loyalty points in Global-e checkout. | | 6 | Payment Charge | Discount aimed to sponsor “Cash on Delivery” fee. |
148 149 150 151 152 153 154 |
# File 'app/services/workarea/global_e/discount.rb', line 148 def discount_type if GlobalE.shipping_discount_types.include? discount.class.name 2 else 1 end end |
#discount_value ⇒ Float
Discount value as displayed to the customer, after applying country coefficient, FX conversion and IncludeVAT handling.
68 69 70 71 72 73 74 75 76 |
# File 'app/services/workarea/global_e/discount.rb', line 68 def discount_value return 0 unless order.fixed_pricing? if free_gift? && pricing_sku.present? pricing_sku.find_price(quantity: 1).regular.to_f else price_adjustment.amount.abs.to_f end end |
#local_vat_rate ⇒ Float
VAT rate that would be applied to this discount if the order was placed by the local customer. This value must be specified if UseCountryVAT for the current Country is TRUE and therefore VATRate property actually denotes the VAT for the target country.
60 61 |
# File 'app/services/workarea/global_e/discount.rb', line 60 def local_vat_rate end |
#loyalty_voucher_code ⇒ String
Code used on the Merchant’s site to identify the Loyalty Voucher that this discount is based on
132 133 |
# File 'app/services/workarea/global_e/discount.rb', line 132 def loyalty_voucher_code end |
#name ⇒ String
Discount name
82 83 84 |
# File 'app/services/workarea/global_e/discount.rb', line 82 def name discount.name end |
#original_discount_value ⇒ Float
Discount value in original Merchant’s currency including the local VAT, before applying any price modifications. This property always denotes the discount value in the default Merchant’s country, regardless of UseCountryVAT for the end customer’s current country.
36 37 38 39 40 41 42 43 44 |
# File 'app/services/workarea/global_e/discount.rb', line 36 def original_discount_value return 0 if order.fixed_pricing? if free_gift? && pricing_sku.present? pricing_sku.find_price(quantity: 1).regular.to_f else price_adjustment.amount.abs.to_f end end |
#product_cart_item_id ⇒ String
Identifier of the product cart item related to this discount 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.
110 111 112 113 114 |
# File 'app/services/workarea/global_e/discount.rb', line 110 def product_cart_item_id if price_adjustment.price == "item" price_adjustment&._parent&.id&.to_s end end |
#vat_rate ⇒ Float
VAT rate applied to this discount
50 51 |
# File 'app/services/workarea/global_e/discount.rb', line 50 def vat_rate end |