Class: C2eCore::Drops::OrderDrop
- Defined in:
- /build/app/mailers/c2e_core/drops/order_drop.rb
Instance Method Summary collapse
-
#accepted_at ⇒ DateTime
-
Datetime object containing value when order was submitted by customer.
-
-
#admin_customer_detail_url ⇒ String
-
URL redirecting to current customer detail in staff admin application.
-
-
#admin_order_detail_url ⇒ String
-
URL redirecting to order detail in staff admin application.
-
-
#canceled? ⇒ Boolean
-
Returns true if the order is canceled, and false otherwise.
-
-
#cash_box ⇒ CashBoxDrop
-
Returns orders cash box as drop object if it is present.
-
-
#company_branch ⇒ CompanyBranchDrop
-
Company branch to which order belongs as drop object.
-
-
#credits_reward ⇒ CreditsRewardDrop?
-
The credits reward as a drop object, if it is present.
-
-
#credits_wallets ⇒ Array[CreditsWalletDrop]
-
An array of credit wallets as drop objects.
-
-
#currency ⇒ CurrencyDrop
-
Orders currency object.
-
-
#customer ⇒ CustomerDrop
-
Customer as drop object.
-
-
#customer_track_url ⇒ String
-
URL redirecting to finish screen of customers application.
-
-
#data_from_terminal ⇒ String?
-
Returns the data we received from the terminal after a successful transaction, if present.
-
-
#delayed_delivery_time ⇒ DateTime
-
Returns time which customer specifically chosen.
-
-
#deliver_at ⇒ Time
-
Returns current time of expected delivery.
-
-
#deliver_at_minutes ⇒ Integer
-
Returns number of minutes remaining to current
deliver_at
time.
-
-
#delivered_at ⇒ Time?
-
Returns current time of delivery.
-
-
#delivery_today? ⇒ Boolean
-
Returns true when deliver_at time is today.
-
-
#delivery_type_enum ⇒ String
-
DeliveryType.enum value.
-
-
#flat_items ⇒ Array[OrderRecipeFlatDrop]
-
Returns a flat array of main order recipes as drop objects.
-
-
#flat_ware_category_items ⇒ Array[OrderWareCategoryFlatDrop]
-
Returns a flat array of orders ware categories as drop objects ordered by recipes where this ware category was first.
-
-
#has_delivery? ⇒ Boolean
-
Returns true when order is supposed to be delivered by messenger.
-
-
#id ⇒ Integer
-
ID of order.
-
-
#initialize(order) ⇒ OrderDrop
constructor
A new instance of OrderDrop.
-
#invoice_promos ⇒ Array<InvoicePromoDrop>
-
An array of invoice promos as drop objects.
-
-
#main_items ⇒ Array[OrderRecipeDrop]
-
Returns an array of main orders’ recipes with name and price as drop objects.
-
-
#note ⇒ String
-
text of first info note.
-
-
#online? ⇒ Boolean
-
Returns true when order was paid by card in online gate.
-
-
#online_payment_id ⇒ Integer
-
Returns id from customer_json gopay hash.
-
-
#order_origin ⇒ OrderOriginDrop
-
Returns order origin as drop object with name.
-
-
#order_payment_methods ⇒ Array[OrderPaymentMethodDrop]
-
An array of order payment methods as drop objects.
-
-
#payment_method_enums ⇒ Array
-
An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods.
-
-
#payment_method_enums_without_wallet_credit ⇒ Array
-
An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods, excluding credit payments.
-
-
#price ⇒ OrderPriceDrop
-
Returns orders price as drop object.
-
-
#purchased_credits_wallet ⇒ CreditsWalletDrop?
-
A credit wallet that was purchased with the order as a drop object or nil.
-
-
#qr_with_id ⇒ String
-
QR code including
Order#id
as data-URL.
-
-
#ratings ⇒ Array[OrderRatingDrop]
-
Returns an array of order rating notes as drop objects with quality evaluation from customer and text message e.g.:
"Dobra, ale těsto bylo trochu tuhé."
.
-
-
#require_age_control? ⇒ Boolean
-
Returns true when order contains a recipe that requires age control, and false otherwise.
-
-
#resettable_id ⇒ Integer
-
Resettable ID of order.
-
-
#simplified_payment_method ⇒ String
deprecated
Deprecated.
This method is deprecated and will be removed in future versions. Use #payment_method_enums instead. Reason: This method may return incorrect values for orders paid using multiple payment methods.
-
#time_deliver_at ⇒ DateTime
-
Returns current date and time of expected delivery.
-
-
#user ⇒ UserDrop
-
Returns user who created order as drop object.
-
Constructor Details
#initialize(order) ⇒ OrderDrop
Returns a new instance of OrderDrop.
6 7 8 9 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 6 def initialize(order) super() @order = order end |
Instance Method Details
#accepted_at ⇒ DateTime
Returns - Datetime object containing value when order was submitted by customer. E.g.: "2020-11-16T11:38:56+01:00"
.
32 33 34 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 32 def accepted_at @order.accepted_at end |
#admin_customer_detail_url ⇒ String
Returns - URL redirecting to current customer detail in staff admin application.
133 134 135 136 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 133 def admin_customer_detail_url url = URI.join(URI(Rails.application.config..admin_app_url), "overview/customer") "#{url}?phone=#{CGI.escape(customer.phone)}" end |
#admin_order_detail_url ⇒ String
Returns - URL redirecting to order detail in staff admin application.
127 128 129 130 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 127 def admin_order_detail_url url = URI.join(URI(Rails.application.config..admin_app_url), "order/detail") "#{url}?orderId=#{@order.id}" end |
#canceled? ⇒ Boolean
Returns - Returns true if the order is canceled, and false otherwise.
233 234 235 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 233 def canceled? @order.canceled? end |
#cash_box ⇒ CashBoxDrop
Returns - Returns orders cash box as drop object if it is present.
218 219 220 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 218 def cash_box CashBoxDrop.new(@order.cash_box) if @order.cash_box_id.present? end |
#company_branch ⇒ CompanyBranchDrop
Returns - Company branch to which order belongs as drop object.
58 59 60 61 62 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 58 def company_branch stored_value __method__ do CompanyBranchDrop.new @order.company_branch end end |
#credits_reward ⇒ CreditsRewardDrop?
Returns - The credits reward as a drop object, if it is present. Otherwise, null
.
239 240 241 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 239 def credits_reward CreditsRewardDrop.new(@order.credits_reward) if @order.credits_reward.present? end |
#credits_wallets ⇒ Array[CreditsWalletDrop]
Returns - An array of credit wallets as drop objects.
262 263 264 265 266 267 268 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 262 def credits_wallets stored_value __method__ do @order.credits_wallets.map do |credit_wallet| CreditsWalletDrop.new(credit_wallet) end end end |
#currency ⇒ CurrencyDrop
Returns - Orders currency object. By default it is taken from company branch.
37 38 39 40 41 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 37 def currency stored_value __method__ do CurrencyDrop.new @order.currency end end |
#customer ⇒ CustomerDrop
Returns - Customer as drop object.
44 45 46 47 48 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 44 def customer stored_value __method__ do CustomerDrop.new @order end end |
#customer_track_url ⇒ String
Returns - URL redirecting to finish screen of customers application. URL format is https://some_customer.app.speedlo_service.domain/finish?orderId=[Integer]&userToken=[String]
.
117 118 119 120 121 122 123 124 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 117 def customer_track_url stored_value __method__ do finish_path = @order.legacy_application? ? "finish" : "order-tracking" url = URI.join(URI(@order.base_url), finish_path) token = Base64.urlsafe_encode64(@order.confirmation_token) "#{url}?orderId=#{@order.id}&userToken=#{token}" end end |
#data_from_terminal ⇒ String?
Returns - Returns the data we received from the terminal after a successful transaction, if present.
245 246 247 248 249 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 245 def data_from_terminal return @order.terminal_transaction_records.successful.last&.data unless @order.canceled? @order.terminal_transaction_records.successful.refund.last&.data end |
#delayed_delivery_time ⇒ DateTime
Returns - Returns time which customer specifically chosen. Can differ from #deliver_at
and always has same value.
106 107 108 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 106 def delayed_delivery_time @order.delayed_delivery_time end |
#deliver_at ⇒ Time
Returns - Returns current time of expected delivery. Can be changed by staff. E.g.: 2022-10-31 15:56:02 +0100
.
94 95 96 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 94 def deliver_at @order.deliver_at end |
#deliver_at_minutes ⇒ Integer
Returns - Returns number of minutes remaining to current deliver_at
time. Result is rounded to multiples of 5.
77 78 79 80 81 82 83 84 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 77 def deliver_at_minutes stored_value __method__ do minutes = (@order.deliver_at - DateTime.now) / 60 remainder = minutes % 5 minutes = minutes - remainder + 5 if remainder > 0 minutes.to_i end end |
#delivered_at ⇒ Time?
Returns - Returns current time of delivery. Can be changed by staff. E.g.: 2022-10-31 15:56:02 +0100
.
100 101 102 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 100 def delivered_at @order.delivered_at end |
#delivery_today? ⇒ Boolean
Returns - Returns true when deliver_at time is today.
111 112 113 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 111 def delivery_today? @order.deliver_at.today? end |
#delivery_type_enum ⇒ String
Returns - DeliveryType.enum value. E.g.: MESSENGER, PICKUP
. Returns nil for inhouse order.
71 72 73 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 71 def delivery_type_enum @order.delivery_type&.code&.upcase end |
#flat_items ⇒ Array[OrderRecipeFlatDrop]
Returns - Returns a flat array of main order recipes as drop objects. Doesn’t group the same recipes with side dishes.
183 184 185 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 183 def flat_items @order.flat_order_recipes.map { |flat_item| OrderRecipeFlatDrop.new flat_item, @order } end |
#flat_ware_category_items ⇒ Array[OrderWareCategoryFlatDrop]
Returns - Returns a flat array of orders ware categories as drop objects ordered by recipes where this ware category was first.
189 190 191 192 193 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 189 def flat_ware_category_items @order.flat_order_recipes .group_by { |flat_item| flat_item[:recipe].ware_categories_in.order(created_at: :asc).first } .map { |ware_category, flat_recipes| OrderWareCategoryFlatDrop.new ware_category, flat_recipes, @order } end |
#has_delivery? ⇒ Boolean
Returns - Returns true when order is supposed to be delivered by messenger.
65 66 67 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 65 def has_delivery? @order.delivery_type_id == DeliveryType.the_messenger.id end |
#id ⇒ Integer
Returns - ID of order.
15 16 17 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 15 def id @order.id end |
#invoice_promos ⇒ Array<InvoicePromoDrop>
Returns - An array of invoice promos as drop objects.
280 281 282 283 284 285 286 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 280 def invoice_promos stored_value __method__ do @order.invoice_promos.map do |invoice_promo| InvoicePromoDrop.new(invoice_promo) end end end |
#main_items ⇒ Array[OrderRecipeDrop]
Returns - Returns an array of main orders’ recipes with name and price as drop objects.
196 197 198 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 196 def main_items @order.order_recipes.mains.map { |main_item| OrderRecipeDrop.new main_item, @order } end |
#note ⇒ String
Returns - text of first info note. E.g.: "Pozor pes, počkat venku!"
.
51 52 53 54 55 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 51 def note stored_value __method__ do @order.notes.info.first&.text.to_s end end |
#online? ⇒ Boolean
Returns - Returns true when order was paid by card in online gate.
139 140 141 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 139 def online? @order.online? end |
#online_payment_id ⇒ Integer
Returns - Returns id from customer_json gopay hash.
223 224 225 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 223 def online_payment_id @order.online_payment_id end |
#order_origin ⇒ OrderOriginDrop
Returns - Returns order origin as drop object with name. E.g.: "Web", "Staff", "foodora".
.
208 209 210 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 208 def order_origin OrderOriginDrop.new(@order.order_origin) end |
#order_payment_methods ⇒ Array[OrderPaymentMethodDrop]
Returns - An array of order payment methods as drop objects.
252 253 254 255 256 257 258 259 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 252 def order_payment_methods stored_value __method__ do records = @order.order_payment_methods.includes(payment_method: [:payment_gate, :payment_type, :country]) records.map do |order_payment_method| OrderPaymentMethodDrop.new(order_payment_method) end end end |
#payment_method_enums ⇒ Array
Returns - An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods. E.g.: ["CREDIT_CSOB", "WALLET_CREDIT_WALLET_CREDIT"]
.
157 158 159 160 161 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 157 def payment_method_enums stored_value __method__ do @order.payment_methods.includes(:payment_gate, :payment_type).map(&:enum_description) end end |
#payment_method_enums_without_wallet_credit ⇒ Array
Returns - An array containing the concatenation of PaymentType.enum and PaymentGate.enum values for all orders’ payment methods, excluding credit payments. If an order is fully paid using credits, an empty array is returned. E.g.: ["CREDIT_CSOB", "CASH_CASH"]
.
167 168 169 170 171 172 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 167 def payment_method_enums_without_wallet_credit payment_methods = @order.payment_methods.without_payment_type(PaymentType.the_wallet_credit) .includes(:payment_gate, :payment_type) payment_methods.map(&:enum_description) end |
#price ⇒ OrderPriceDrop
Returns - Returns orders price as drop object.
175 176 177 178 179 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 175 def price stored_value __method__ do OrderPriceDrop.new @order end end |
#purchased_credits_wallet ⇒ CreditsWalletDrop?
Returns - A credit wallet that was purchased with the order as a drop object or nil.
271 272 273 274 275 276 277 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 271 def purchased_credits_wallet stored_value __method__ do next if @order.purchased_credits_wallet.nil? CreditsWalletDrop.new(@order.purchased_credits_wallet) end end |
#qr_with_id ⇒ String
Returns - QR code including Order#id
as data-URL. E.g.: "data:image/png;base64,iVBO....."
. Current width of image is 400px.
21 22 23 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 21 def qr_with_id RQRCode::QRCode.new(@order.id.to_s).as_png(size: 400, border_modules: 0).to_data_url end |
#ratings ⇒ Array[OrderRatingDrop]
Returns - Returns an array of order rating notes as drop objects with quality evaluation from customer and text message e.g.: "Dobra, ale těsto bylo trochu tuhé."
.
202 203 204 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 202 def @order..map { || OrderRatingDrop.new } end |
#require_age_control? ⇒ Boolean
Returns - Returns true when order contains a recipe that requires age control, and false otherwise.
228 229 230 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 228 def require_age_control? @order.require_age_control? end |
#resettable_id ⇒ Integer
Returns - Resettable ID of order. E.g.: 142.
26 27 28 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 26 def resettable_id @order.final&.dig("invoice", "resettable_sequence") end |
#simplified_payment_method ⇒ String
This method is deprecated and will be removed in future versions. Use #payment_method_enums instead. Reason: This method may return incorrect values for orders paid using multiple payment methods.
Returns - Cotains concatenation of PaymentType.enum and PaymentGate.enum E.g.: CREDIT_CREDIT, CREDIT_CSOB, CASH_CASH
, etc.
148 149 150 151 152 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 148 def simplified_payment_method stored_value __method__ do @order.payment_methods.first.enum_description end end |
#time_deliver_at ⇒ DateTime
Returns - Returns current date and time of expected delivery. Can be changed by staff. E.g.: 14:51
.
88 89 90 |
# File '/build/app/mailers/c2e_core/drops/order_drop.rb', line 88 def time_deliver_at I18n.l(@order.deliver_at, format: :just_time) if @order.deliver_at.present? end |