Module: Plugins::Ecommerce::EcommerceHelper

Includes:
EcommerceEmailHelper
Defined in:
app/helpers/plugins/ecommerce/ecommerce_helper.rb

Instance Method Summary collapse

Instance Method Details

#cama_ecommerce_post_typeObject

return ecommerce posttype



11
12
13
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 11

def cama_ecommerce_post_type
  @_cache_ecommerce_post_type ||= current_site.post_types.where(slug: 'commerce').first.try(:decorate)
end

#ecommerce_add_assets_in_frontObject



98
99
100
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 98

def ecommerce_add_assets_in_front
  append_asset_libraries({ecommerce_front: {css: [plugin_gem_asset('front')], js: [plugin_gem_asset('cart')]}})
end

#ecommerce_admin_before_email_send(args) ⇒ Object

permit to generate invoice PDF by background just before delivery email



52
53
54
55
56
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 52

def ecommerce_admin_before_email_send(args)
  if args[:ecommerce_invoice].present?
    File.open(args[:ecommerce_invoice][:pdf_path], 'wb'){|file| file << WickedPdf.new.pdf_from_string(args[:ecommerce_invoice][:html], encoding: 'utf8') }
  end
end

#ecommerce_admin_before_loadObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 20

def ecommerce_admin_before_load
  # add menu bar
  pt = current_site.post_types.hidden_menu.where(slug: "commerce").first
  if pt.present?
    items_i = []
    items_i << {icon: "list", title: t('plugins.ecommerce.all_products'), url: cama_admin_post_type_posts_path(pt.id)} if can? :posts, pt
    items_i << {icon: "plus", title: t('camaleon_cms.admin.post_type.add_new', default: 'Add new'), url: new_cama_admin_post_type_post_path(pt.id)} if can? :create_post, pt
    if pt.manage_categories?
      items_i << {icon: "folder-open", title: t('camaleon_cms.admin.post_type.categories', default: 'Categories'), url: cama_admin_post_type_categories_path(pt.id)} if can? :categories, pt
    end
    if pt.manage_tags?
      items_i << {icon: "tags", title: t('camaleon_cms.admin.post_type.tags', default: 'Tags'), url: (pt.id)} if can? :post_tags, pt
    end
    if can? :posts, pt
      items_i << {icon: "reorder", title: "<span>#{t('plugins.ecommerce.orders', default: 'Orders')} <small class='label label-primary'>#{current_site.orders.size}</small></span>", url: admin_plugins_ecommerce_orders_path}
      items_i << {icon: "money", title: t('plugins.ecommerce.tax_rates', default: 'Tax rates'), url: admin_plugins_ecommerce_tax_rates_path}
      items_i << {icon: "taxi", title: t('plugins.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path}
      items_i << {icon: "credit-card", title: t('plugins.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
      items_i << {icon: "tag", title: t('plugins.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
      items_i << {icon: "cubes", title: t('plugins.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path}
      items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
      hooks_run('plugin_ecommerce_after_menus', items_i) # permit to add menus for ecommerce plugin
    end

    admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugins.ecommerce.e_commerce', default: 'E-commerce'), url: "", items: items_i}) if items_i.present?
  end
end

#ecommerce_admin_product_form(args) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 3

def ecommerce_admin_product_form(args)
  if args[:post_type].slug == 'commerce'
    append_asset_libraries({ecommerce: {css: [], js: [plugin_asset_path('admin_product')]}})
    args[:html] << render(partial: plugin_view('admin/products/variations'), locals:{post_type: args[:post_type], product: args[:post] })
  end
end

#ecommerce_admin_product_saved(args) ⇒ Object

callback after create/update products



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 78

def ecommerce_admin_product_saved(args)
  if args[:post_type].slug == 'commerce'
    params[:product_variation] ||= {}

    # verify no deletable variances
    no_deletable_variances = false
    args[:post].product_variations.where.not(id: params[:product_variation].keys).each{|prod| no_deletable_variances = true unless prod.destroy }
    flash[:warning] += t('plugins.ecommerce.variations.not_deletable_product_variations', default: 'Some Product variations can not be deleted.') if no_deletable_variances

    params[:product_variation].each do |p_key, p_var|
      data = {amount: p_var[:price], photo: p_var[:photo], sku: p_var[:sku], weight: p_var[:weight], qty: p_var[:qty], attribute_ids: (p_var[:attributes] || []).map{|at| at[:value] }.join(',')}
      if p_key.include?('new_') # new variation
        args[:post].product_variations.create(data)
      else
        args[:post].product_variations.find(p_key).update(data)
      end
    end
  end
end

#ecommerce_app_before_loadObject



48
49
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 48

def ecommerce_app_before_load
end

#ecommerce_front_before_loadObject



15
16
17
18
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 15

def ecommerce_front_before_load
  e_current_visitor_currency(params[:cama_change_currency]) if params[:cama_change_currency].present?
  @ecommerce_breadcrumb = [].push([t('plugins.ecommerce.front.breadcrumb.home', default: 'Home'), cama_root_url])
end

#ecommerce_on_active(plugin) ⇒ Object

here all actions on going to active you can run sql commands like this: results = ActiveRecord::Base.connection.execute(query); plugin: plugin model



67
68
69
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 67

def ecommerce_on_active(plugin)
  generate_custom_field_products
end

#ecommerce_on_destroy(plugin) ⇒ Object

here all actions on plugin destroying plugin: plugin model



60
61
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 60

def ecommerce_on_destroy(plugin)
end

#ecommerce_on_inactive(plugin) ⇒ Object

here all actions on going to inactive plugin: plugin model



73
74
75
# File 'app/helpers/plugins/ecommerce/ecommerce_helper.rb', line 73

def ecommerce_on_inactive(plugin)
  current_site.post_types.hidden_menu.where(slug: "commerce").first.destroy
end