Module: Plugins::Ecommerce::EcommerceEmailHelper
- Includes:
- CamaleonCms::EmailHelper
- Included in:
- EcommerceHelper
- Defined in:
- app/helpers/plugins/ecommerce/ecommerce_email_helper.rb
Instance Method Summary collapse
-
#commerce_coupon_error_message(error_code, coupon = nil) ⇒ Object
return translated message.
-
#commerce_mark_cart_received(cart, status = 'paid') ⇒ Object
mark current cart into order with specific status.
-
#commerce_order_send_mail(order, event = 'email_order_received') ⇒ Object
send the email to the user for specific events or status event: (String) email_order_received | email_order_shipped | email_order_cancelled | email_order_confirmed_bank | email_order_confirmed_on_delivery.
-
#ecommerce_verify_cart_errors(cart) ⇒ Object
verify all products and qty, coupons availability return an array of errors.
Instance Method Details
#commerce_coupon_error_message(error_code, coupon = nil) ⇒ Object
return translated message
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/plugins/ecommerce/ecommerce_email_helper.rb', line 16 def (error_code, coupon = nil) case error_code when 'coupon_not_found' t('plugins.ecommerce.messages.coupon_not_found', default: "Coupon not found") when 'coupon_expired' t('plugins.ecommerce.messages.coupon_expired', default: 'Coupon Expired') when 'inactive_coupon' t('plugins.ecommerce.messages.inactive_coupon', default: 'Coupon disabled') when 'times_exceeded' t('plugins.ecommerce.messages.times_exceeded', default: 'Number of times exceeded') when 'required_minimum_price' t('plugins.ecommerce.messages.required_minimum_price', min_amount: coupon.min_cart_total, default: 'Your amount should be great than %{min_amount}') else 'Unknown error' end end |
#commerce_mark_cart_received(cart, status = 'paid') ⇒ Object
mark current cart into order with specific status
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/plugins/ecommerce/ecommerce_email_helper.rb', line 5 def commerce_mark_cart_received(cart, status = 'paid') args = {cart: cart, status: status}; hooks_run('commerce_before_payment_completed', args) order = cart.convert_to_order(status) order.('locale', I18n.locale) commerce_order_send_mail(order) flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.payment_completed', default: "Payment completed successfully") args = {order: order, status: status}; hooks_run("commerce_after_payment_completed", args) order end |
#commerce_order_send_mail(order, event = 'email_order_received') ⇒ Object
send the email to the user for specific events or status event: (String) email_order_received | email_order_shipped | email_order_cancelled | email_order_confirmed_bank | email_order_confirmed_on_delivery
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/plugins/ecommerce/ecommerce_email_helper.rb', line 58 def commerce_order_send_mail(order, event = 'email_order_received') bk_l = I18n.locale I18n.locale = order.('locale', 'en').to_s subject, content_key = case event when 'email_order_received' [I18n.t('plugins.ecommerce.email.order_received_label', default: 'Order Received'), 'email_order_received'] when 'email_order_confirmed' [I18n.t('plugins.ecommerce.email.order_confirmed_label', default: 'Order Confirmed'), 'email_order_confirmed'] when 'email_order_confirmed_bank' [I18n.t('plugins.ecommerce.email.order_bank_confirmed_label', default: 'Order Bank Confirmed'), 'email_order_confirmed'] when 'email_order_confirmed_on_delivery' [I18n.t('plugins.ecommerce.email.order_on_delivery_confirmed_label', default: 'Order on Delivery Confirmed'), 'email_order_confirmed'] when 'email_order_shipped' [I18n.t('plugins.ecommerce.email.order_shipped_label', default: 'Order Shipped'), 'email_order_shipped'] when 'email_order_cancelled' [I18n.t('plugins.ecommerce.email.order_cancelled_label', default: 'Order Cancelled'), 'email_order_cancelled'] end data = {template_name: nil, content: current_site.e_email_for(content_key).to_s.translate, files: []} replaces = { order_table: render_to_string(partial: 'plugins/ecommerce/partials/email/product_table', locals: {order: order}), shipping_info: render_to_string(partial: 'plugins/ecommerce/partials/email/shipping_address', locals: {order: order}), billing_info: render_to_string(partial: 'plugins/ecommerce/partials/email/billing_address', locals: {order: order}), cancelled_description: order.('description').to_s, root_url: current_site.the_url, date: order.the_created_at, current_date: l(Date.today, format: :long), number: order.slug, name: order.user.first_name, full_name: order.user.fullname, tracking_url: order.the_url_tracking.to_s, shipping_name: order.the_shipping_method.to_s, invoice_number: order.invoice_number.to_s, status: order.the_status, url: order.the_url } args={order: order, replaces: replaces}; hooks_run('commerce_custom_email_replacements', args) # permit to add custom replacements if order.status == 'paid' order.products.each do |product| data[:files] += product.get_fields('ecommerce_files').map{|f| CamaleonCmsLocalUploader::private_file_path(f, current_site) } end data[:files] = data[:files].uniq pdf_path = order.the_invoice_path data[:ecommerce_invoice] = {pdf_path: pdf_path, html: current_site.e_email_for('email_order_invoice').to_s.translate.to_s.cama_replace_codes(replaces, format_code = '{')} data[:files] << pdf_path order.update_column(:invoice_path, pdf_path.split('/').last) end data[:content] = data[:content].to_s.cama_replace_codes(replaces, format_code = '{') cama_send_email(order.user.email, subject, data) I18n.locale = bk_l end |
#ecommerce_verify_cart_errors(cart) ⇒ Object
verify all products and qty, coupons availability return an array of errors
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/plugins/ecommerce/ecommerce_email_helper.rb', line 35 def ecommerce_verify_cart_errors(cart) errors = [] # products verification cart.product_items.decorate.each do |item| unless item.is_valid_qty? product = item.product.decorate errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(item.variation_id), qty: product.the_qty(item.variation_id), default: 'There is not enough products "%{product}" (Available %{qty})') end end # coupon verification res = cart.discount_for(cart.coupon) if res[:error].present? errors << (res[:error], res[:coupon]) cart.update_column(:coupon, '') end args = {cart: cart, errors: errors}; hooks_run("commerce_on_error_verifications", args) errors end |