Class: C2eCore::Drops::OrderPriceDrop

Inherits:
BaseDrop
  • Object
show all
Includes:
Helpers::OrderConversions
Defined in:
/build/app/mailers/c2e_core/drops/order_price_drop.rb

Instance Method Summary collapse

Methods included from Helpers::OrderConversions

#converted_price, #format_price

Constructor Details

#initialize(order) ⇒ OrderPriceDrop

Returns a new instance of OrderPriceDrop.



8
9
10
11
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 8

def initialize(order)
  super()
  @order = order
end

Instance Method Details

#collect_from_customerFloat

Returns - The amount that should be collected from customer.

Returns:

  • (Float)
    • The amount that should be collected from customer



82
83
84
85
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 82

def collect_from_customer
  converted_amount = converted_price @order.price.collect_from_customer
  converted_amount.zero? ? converted_amount.abs : converted_amount
end

#discountsArray[OrderDiscountDrop]

Returns - Array of all order discounts.

Returns:



56
57
58
59
60
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 56

def discounts
  stored_value __method__ do
    @order.apply_rules.discount.map { |discount_hash| OrderDiscountDrop.new discount_hash, @order }
  end
end

#extra_chargeFloat

Returns - Price for extra charge (only used by DameJidlo now) converted into order’s currency. E.g.: 28.

Returns:

  • (Float)
    • Price for extra charge (only used by DameJidlo now) converted into order’s currency. E.g.: 28



36
37
38
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 36

def extra_charge
  converted_price @order.extra_charge
end

#extra_feesArray[OrderExternalFeeDrop]

Returns - Array of all extra fees.

Returns:



88
89
90
91
92
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 88

def extra_fees
  stored_value __method__ do
    @order.price.external_fees.map { |name, value| OrderExternalFeeDrop.new name, value, @order }
  end
end

#roundingFloat

Returns - Rounding of total_raw to cash rounding unit. E.g.: SK(EUR) -> 0.05, CZ(CZK) -> 1.00.

Returns:

  • (Float)
    • Rounding of total_raw to cash rounding unit. E.g.: SK(EUR) -> 0.05, CZ(CZK) -> 1.00



26
27
28
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 26

def rounding
  converted_price(@order.price.rounding)
end

#tipFloat

Returns - Value of tip given by customer converted into order’s currency. E.g.: 34.8.

Returns:

  • (Float)
    • Value of tip given by customer converted into order’s currency. E.g.: 34.8



41
42
43
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 41

def tip
  converted_price @order.price.tip
end

#tip_percentageInteger

Returns - Percentage value of tip given by customer. E.g.: 25.

Returns:

  • (Integer)
    • Percentage value of tip given by customer. E.g.: 25



46
47
48
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 46

def tip_percentage
  @order.price.tip_percentage
end

#totalFloat

Returns - Total price of order converted into order’s currency. E.g.: 378.

Returns:

  • (Float)
    • Total price of order converted into order’s currency. E.g.: 378



21
22
23
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 21

def total
  total_raw + rounding
end

#total_discountFloat

Returns - Sum of all discounts converted into order’s currency. E.g.: 78.

Returns:

  • (Float)
    • Sum of all discounts converted into order’s currency. E.g.: 78



51
52
53
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 51

def total_discount
  converted_price @order.price.total_discount
end

#total_rawFloat

Returns - Total price of order converted into order’s currency. E.g.: 378.

Returns:

  • (Float)
    • Total price of order converted into order’s currency. E.g.: 378



14
15
16
17
18
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 14

def total_raw
  stored_value __method__ do
    converted_price(@order.price.total)
  end
end

#total_vouchersFloat

Returns - Sum of all vouchers converted into order’s currency. E.g.: 78.

Returns:

  • (Float)
    • Sum of all vouchers converted into order’s currency. E.g.: 78



63
64
65
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 63

def total_vouchers
  converted_price @order.price.total_vouchers
end

#transportationFloat

Returns - Price for delivery converted into order’s currency. E.g.: 50.

Returns:

  • (Float)
    • Price for delivery converted into order’s currency. E.g.: 50



31
32
33
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 31

def transportation
  converted_price @order.price.transportation_fee
end

#vatsArray[OrderVatDrop]

Returns - Array of all order discounts.

Returns:



75
76
77
78
79
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 75

def vats
  stored_value __method__ do
    @order.vats.map { |vat_record| OrderVatDrop.new vat_record, @order }.sort_by(&:percentage)
  end
end

#vouchersArray[OrderDiscountDrop]

Returns - Array of all order vouchers.

Returns:



68
69
70
71
72
# File '/build/app/mailers/c2e_core/drops/order_price_drop.rb', line 68

def vouchers
  stored_value __method__ do
    @order.apply_rules.vouchers.map { |discount_hash| OrderDiscountDrop.new discount_hash, @order }
  end
end