Class: Plugins::Ecommerce::OrderDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Plugins::Ecommerce::OrderDecorator
- Defined in:
- app/decorators/plugins/ecommerce/order_decorator.rb
Instance Method Summary collapse
- #accepted! ⇒ Object
- #bank_confirmed! ⇒ Object
- #canceled! ⇒ Object
- #on_delivery_confirmed! ⇒ Object
-
#paid! ⇒ Object
mark current order as paid and set a invoice number.
- #shipped!(code) ⇒ Object
-
#the_created_at(format = :long) ⇒ Object
return created at date formatted.
-
#the_invoice_path ⇒ Object
return the invoice pdf path.
- #the_paid_at(format = :long) ⇒ Object
- #the_received_at(format = :long) ⇒ Object
- #the_shipped_at(format = :long) ⇒ Object
-
#the_shipping_method ⇒ Object
return shipping method title.
- #the_status(include_date_action = false) ⇒ Object
-
#the_url ⇒ Object
return the url of the current order.
- #the_url_tracking ⇒ Object
Instance Method Details
#accepted! ⇒ Object
55 56 57 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 55 def accepted! update_columns({status: 'accepted', accepted_at: Time.current}) end |
#bank_confirmed! ⇒ Object
68 69 70 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 68 def bank_confirmed! paid! end |
#canceled! ⇒ Object
64 65 66 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 64 def canceled! update_columns({status: 'canceled', closed_at: Time.current}) end |
#on_delivery_confirmed! ⇒ Object
72 73 74 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 72 def on_delivery_confirmed! paid! end |
#paid! ⇒ Object
mark current order as paid and set a invoice number
51 52 53 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 51 def paid! update_columns(invoice_number: get_invoice_number, status: 'paid', paid_at: Time.current) end |
#shipped!(code) ⇒ Object
59 60 61 62 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 59 def shipped!(code) update_columns({status: 'shipped', shipped_at: Time.current}) ('consignment_number', code) end |
#the_created_at(format = :long) ⇒ Object
return created at date formatted
24 25 26 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 24 def the_created_at(format = :long) h.l(object.created_at, format: format.to_sym) end |
#the_invoice_path ⇒ Object
return the invoice pdf path
77 78 79 80 81 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 77 def the_invoice_path folder = CamaleonCmsLocalUploader::private_file_path('invoices', h.current_site).to_s FileUtils.mkdir_p(folder) unless Dir.exist?(folder) File.join(folder, "#{object.invoice_number.presence || object.slug}.pdf").to_s end |
#the_paid_at(format = :long) ⇒ Object
28 29 30 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 28 def the_paid_at(format = :long) h.l(object.paid_at, format: format.to_sym) rescue '' end |
#the_received_at(format = :long) ⇒ Object
32 33 34 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 32 def the_received_at(format = :long) h.l(object.received_at, format: format.to_sym) rescue '' end |
#the_shipped_at(format = :long) ⇒ Object
36 37 38 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 36 def the_shipped_at(format = :long) h.l(object.shipped_at, format: format.to_sym) rescue '' end |
#the_shipping_method ⇒ Object
return shipping method title
41 42 43 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 41 def the_shipping_method object.shipping_method.try(:decorate).try(:the_title) end |
#the_status(include_date_action = false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 4 def the_status(include_date_action = false) res = if object.bank_pending? || object.on_delivery_pending? "<span class='label label-warning'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>" elsif object.canceled? "<span class='label label-danger'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>" else "<span class='label label-success'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>" end res = "#{res} #{object.action_date}" if include_date_action res end |
#the_url ⇒ Object
return the url of the current order
46 47 48 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 46 def the_url h.plugins_ecommerce_order_show_path(order: object.slug) end |
#the_url_tracking ⇒ Object
16 17 18 19 20 21 |
# File 'app/decorators/plugins/ecommerce/order_decorator.rb', line 16 def the_url_tracking if object.shipped? consignment_number = object.("consignment_number") _url = object.shipping_method.[:url_tracking].gsub("{{consignment_number}}", consignment_number) rescue '' end end |