camaleon_ecommerce 1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/plugins/ecommerce/admin_product.js.coffee +17 -1
  3. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +1 -1
  4. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +24 -21
  5. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +2 -34
  6. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +3 -6
  7. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +2 -1
  8. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +2 -2
  9. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +1 -1
  10. data/app/controllers/plugins/ecommerce/admin_controller.rb +2 -2
  11. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +34 -18
  12. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +3 -4
  13. data/app/controllers/plugins/ecommerce/front_controller.rb +26 -11
  14. data/app/decorators/plugins/ecommerce/cart_decorator.rb +5 -5
  15. data/app/decorators/plugins/ecommerce/coupon_decorator.rb +8 -27
  16. data/app/decorators/plugins/ecommerce/order_decorator.rb +1 -1
  17. data/app/decorators/plugins/ecommerce/product_decorator.rb +33 -20
  18. data/app/decorators/plugins/ecommerce/product_item_decorator.rb +8 -2
  19. data/app/decorators/plugins/ecommerce/product_variation_decorator.rb +1 -1
  20. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +7 -6
  21. data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +276 -33
  22. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +59 -56
  23. data/app/models/plugins/ecommerce/attribute.rb +3 -0
  24. data/app/models/plugins/ecommerce/cart.rb +31 -7
  25. data/app/models/plugins/ecommerce/legacy_order.rb +1 -30
  26. data/app/models/plugins/ecommerce/order.rb +11 -5
  27. data/app/models/plugins/ecommerce/order_detail.rb +1 -0
  28. data/app/models/plugins/ecommerce/payment_method.rb +9 -5
  29. data/app/models/plugins/ecommerce/product_variation.rb +6 -0
  30. data/app/services/plugins/ecommerce/cart_service.rb +4 -17
  31. data/app/views/camaleon_cms/html_mailer/order_canceled.html.erb +2 -2
  32. data/app/views/camaleon_cms/html_mailer/order_confirmed.html.erb +2 -2
  33. data/app/views/camaleon_cms/html_mailer/order_received.html.erb +5 -3
  34. data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +3 -3
  35. data/app/views/camaleon_cms/html_mailer/order_shipped.html.erb +2 -2
  36. data/app/views/camaleon_cms/html_mailer/recovery_cart.html.erb +3 -3
  37. data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +11 -11
  38. data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +11 -11
  39. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +2 -2
  40. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +53 -63
  41. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +30 -24
  42. data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +8 -8
  43. data/app/views/plugins/ecommerce/admin/payment_methods/show.html.erb +22 -22
  44. data/app/views/plugins/ecommerce/admin/prices/form.html.erb +6 -6
  45. data/app/views/plugins/ecommerce/admin/prices/index.html.erb +8 -8
  46. data/app/views/plugins/ecommerce/admin/product_attributes.html.erb +1 -1
  47. data/app/views/plugins/ecommerce/admin/products/_variations.html.erb +4 -4
  48. data/app/views/plugins/ecommerce/admin/products/index.html.erb +5 -5
  49. data/app/views/plugins/ecommerce/admin/settings/index.html.erb +20 -8
  50. data/app/views/plugins/ecommerce/admin/shipping_methods/form.html.erb +5 -5
  51. data/app/views/plugins/ecommerce/admin/shipping_methods/index.html.erb +8 -9
  52. data/app/views/plugins/ecommerce/admin/shipping_methods/show.html.erb +4 -4
  53. data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +3 -3
  54. data/app/views/plugins/ecommerce/admin/tax_rates/index.html.erb +7 -7
  55. data/app/views/plugins/ecommerce/front/checkout/index.html.erb +4 -4
  56. data/app/views/plugins/ecommerce/front/login.html.erb +3 -6
  57. data/app/views/plugins/ecommerce/front/orders/show.html.erb +7 -1
  58. data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +14 -29
  59. data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +1 -1
  60. data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +100 -99
  61. data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +2 -2
  62. data/app/views/post_types/commerce/{_product_widget.html.erb → _post_list_item.html.erb} +0 -0
  63. data/app/views/post_types/commerce/_product_info.html.erb +45 -0
  64. data/app/views/post_types/commerce/single.html.erb +63 -85
  65. data/config/camaleon_plugin.json +3 -8
  66. data/config/custom_models.rb +28 -4
  67. data/config/locales/en.yml +27 -12
  68. data/config/locales/es.yml +70 -57
  69. data/config/routes.rb +1 -0
  70. data/db/migrate/20161202182552_add_cookie_key_to_cart.rb +5 -0
  71. data/lib/ecommerce/version.rb +1 -1
  72. metadata +7 -14
  73. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +0 -6
  74. data/app/models/plugins/ecommerce/legacy_cart.rb +0 -50
  75. data/app/services/plugins/ecommerce/product_item_service.rb +0 -29
  76. data/app/services/plugins/ecommerce/product_service.rb +0 -17
  77. data/app/services/plugins/ecommerce/site_service.rb +0 -21
  78. data/app/services/plugins/ecommerce/user_cart_service.rb +0 -12
  79. data/app/services/plugins/ecommerce/user_product_service.rb +0 -29
  80. data/app/views/post_types/commerce.html.erb +0 -22
  81. data/app/views/post_types/commerce/category.html.erb +0 -23
@@ -1,19 +1,20 @@
1
1
  module Plugins::Ecommerce::EcommerceHelper
2
2
  include Plugins::Ecommerce::EcommerceEmailHelper
3
-
4
- def ecommerce_admin_list_post(d)
5
- end
6
-
7
3
  def ecommerce_admin_product_form(args)
8
4
  if args[:post_type].slug == 'commerce'
9
5
  append_asset_libraries({ecommerce: {css: [], js: [plugin_asset_path('admin_product')]}})
10
- args[:html] = render partial: plugin_view('admin/products/variations'), locals:{post_type: args[:post_type], product: args[:post] }
6
+ args[:html] << render(partial: plugin_view('admin/products/variations'), locals:{post_type: args[:post_type], product: args[:post] })
11
7
  end
12
8
  end
13
9
 
10
+ # return ecommerce posttype
11
+ def cama_ecommerce_post_type
12
+ @_cache_ecommerce_post_type ||= current_site.post_types.where(slug: 'commerce').first.try(:decorate)
13
+ end
14
+
14
15
  def ecommerce_front_before_load
15
- @ecommerce_post_type = current_site.post_types.where(slug: 'commerce').first.decorate
16
- @ecommerce_breadcrumb = [].push(["Home", cama_root_url])
16
+ e_current_visitor_currency(params[:cama_change_currency]) if params[:cama_change_currency].present?
17
+ @ecommerce_breadcrumb = [].push([t('plugins.ecommerce.front.breadcrumb.home', default: 'Home'), cama_root_url])
17
18
  end
18
19
 
19
20
  def ecommerce_admin_before_load
@@ -21,7 +22,7 @@ module Plugins::Ecommerce::EcommerceHelper
21
22
  pt = current_site.post_types.hidden_menu.where(slug: "commerce").first
22
23
  if pt.present?
23
24
  items_i = []
24
- items_i << {icon: "list", title: t('plugin.ecommerce.all_products'), url: cama_admin_post_type_posts_path(pt.id)} if can? :posts, pt
25
+ items_i << {icon: "list", title: t('plugins.ecommerce.all_products'), url: cama_admin_post_type_posts_path(pt.id)} if can? :posts, pt
25
26
  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
26
27
  if pt.manage_categories?
27
28
  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
@@ -30,16 +31,16 @@ module Plugins::Ecommerce::EcommerceHelper
30
31
  items_i << {icon: "tags", title: t('camaleon_cms.admin.post_type.tags', default: 'Tags'), url: cama_admin_post_type_post_tags_path(pt.id)} if can? :post_tags, pt
31
32
  end
32
33
  if can? :posts, pt
33
- items_i << {icon: "reorder", title: "<span>#{t('plugin.ecommerce.orders', default: 'Orders')} <small class='label label-primary'>#{current_site.orders.size}</small></span>", url: admin_plugins_ecommerce_orders_path}
34
- items_i << {icon: "money", title: t('plugin.ecommerce.tax_rates', default: 'Tax rates'), url: admin_plugins_ecommerce_tax_rates_path}
35
- items_i << {icon: "taxi", title: t('plugin.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path}
36
- items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
37
- items_i << {icon: "tag", title: t('plugin.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
34
+ 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}
35
+ items_i << {icon: "money", title: t('plugins.ecommerce.tax_rates', default: 'Tax rates'), url: admin_plugins_ecommerce_tax_rates_path}
36
+ items_i << {icon: "taxi", title: t('plugins.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path}
37
+ items_i << {icon: "credit-card", title: t('plugins.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
38
+ items_i << {icon: "tag", title: t('plugins.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
38
39
  items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
39
- items_i << {icon: "cubes", title: t('plugin.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path}
40
+ items_i << {icon: "cubes", title: t('plugins.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path}
40
41
  end
41
42
 
42
- admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugin.ecommerce.e_commerce', default: 'E-commerce'), url: "", items: items_i}) if items_i.present?
43
+ 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?
43
44
  end
44
45
  end
45
46
 
@@ -65,13 +66,18 @@ module Plugins::Ecommerce::EcommerceHelper
65
66
  current_site.post_types.hidden_menu.where(slug: "commerce").first.destroy
66
67
  end
67
68
 
68
- # callback after create/update
69
- def ecommerce_admin_product_created(args)
69
+ # callback after create/update products
70
+ def ecommerce_admin_product_saved(args)
70
71
  if args[:post_type].slug == 'commerce'
71
72
  params[:product_variation] ||= {}
72
- args[:post].product_variations.where.not(id: params[:product_variation].keys).delete_all
73
+
74
+ # verify no deletable variances
75
+ no_deletable_variances = false
76
+ args[:post].product_variations.where.not(id: params[:product_variation].keys).each{|prod| no_deletable_variances = true unless prod.destroy }
77
+ flash[:warning] += cama_t('plugins.ecommerce.variations.not_deletable_product_variations') if no_deletable_variances
78
+
73
79
  params[:product_variation].each do |p_key, p_var|
74
- 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(',')}
80
+ 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(',')}
75
81
  if p_key.include?('new_') # new variation
76
82
  args[:post].product_variations.create(data)
77
83
  else
@@ -81,49 +87,46 @@ module Plugins::Ecommerce::EcommerceHelper
81
87
  end
82
88
  end
83
89
 
84
- def get_commerce_post_type
85
- @ecommerce = current_site.post_types.hidden_menu.where(slug: "commerce").first
86
- unless @ecommerce.present?
87
- @ecommerce = current_site.post_types.hidden_menu.new(slug: "commerce", name: "Product")
88
- if @ecommerce.save
89
- @ecommerce.set_options({
90
- has_category: true,
91
- has_tags: true,
92
- not_deleted: true,
93
- has_summary: true,
94
- has_content: true,
95
- has_comments: true,
96
- has_picture: true,
97
- has_template: false,
98
- has_featured: true,
99
- cama_post_decorator_class: 'Plugins::Ecommerce::ProductDecorator'
100
- })
101
- @ecommerce.categories.create({name: 'Uncategorized', slug: 'Uncategorized'.parameterize})
102
- end
103
- @ecommerce.set_options({posts_feature_image_label: 'plugin.ecommerce.product.image_label',
104
- posts_feature_image_label_default: 'Product Image'})
105
- end
106
- end
107
-
108
90
  def ecommerce_add_assets_in_front
109
91
  append_asset_libraries({ecommerce_front: {css: [plugin_gem_asset('front')], js: [plugin_gem_asset('cart')]}})
110
92
  end
111
93
 
112
94
  private
113
95
  def generate_custom_field_products
114
- get_commerce_post_type
115
- unless @ecommerce.get_field_groups.where(slug: "plugin_ecommerce_product_data").present?
116
- @ecommerce.get_field_groups.destroy_all
117
- group = @ecommerce.add_custom_field_group({name: 'Products Details', slug: 'plugin_ecommerce_product_data'})
118
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.sku', default: 'Sku')", "slug" => "ecommerce_sku"}, {field_key: "text_box", required: true, label_eval: true})
119
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.attrs', default: 'Attributes')", "slug" => "ecommerce_attrs", description: "t('plugin.ecommerce.product.attrs_descr', default: 'Please enter your product attributes separated by commas, like: Color ==> Red, Blue, Green')"}, {field_key: "field_attrs", required: false, multiple: true, false: true, translate: true, label_eval: true})
120
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.photos', default: 'Photos')", "slug" => "ecommerce_photos"}, {field_key: "image", required: false, multiple: true, label_eval: true})
121
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.price', default: 'Price')", "slug" => "ecommerce_price", "description" => "t('plugin.ecommerce.product.current_unit', default: 'Current unit: %{unit}', unit: current_site.current_unit.to_s)"}, {field_key: "numeric", required: true, label_eval: true})
122
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.tax', default: 'Tax')", "slug" => "ecommerce_tax"}, {field_key: "select_eval", required: false, command: "options_from_collection_for_select(current_site.tax_rates.all, \"id\", \"the_name\")", label_eval: true})
123
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.weight', default: 'Weight')", "slug" => "ecommerce_weight", "description" => "t('plugin.ecommerce.product.current_weight', default: 'Current weight: %{weight}', weight: current_site.current_weight.to_s)"}, {field_key: "text_box", required: true, label_eval: true})
124
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true})
125
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.qty', default: 'Quantity')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true, label_eval: true})
126
- group.add_manual_field({"name" => "t('plugin.ecommerce.product.files', default: 'Product files')", "slug" => "ecommerce_files"}, {field_key: "private_file", multiple: true, required: false, label_eval: true})
96
+ ecommerce = current_site.post_types.hidden_menu.where(slug: "commerce").first
97
+ unless ecommerce.present?
98
+ ecommerce = current_site.post_types.hidden_menu.new(slug: "commerce", name: "Product")
99
+ if ecommerce.save
100
+ ecommerce.set_options({
101
+ has_category: true,
102
+ has_tags: true,
103
+ not_deleted: true,
104
+ has_summary: true,
105
+ has_content: true,
106
+ has_comments: true,
107
+ has_picture: true,
108
+ has_template: false,
109
+ has_featured: true,
110
+ cama_post_decorator_class: 'Plugins::Ecommerce::ProductDecorator'
111
+ })
112
+ ecommerce.categories.create({name: 'Uncategorized', slug: 'Uncategorized'.parameterize})
113
+ end
114
+ ecommerce.set_options({posts_feature_image_label: 'plugins.ecommerce.product.image_label',
115
+ posts_feature_image_label_default: 'Product Image'})
116
+ end
117
+
118
+ unless ecommerce.get_field_groups.where(slug: "plugin_ecommerce_product_data").present?
119
+ ecommerce.get_field_groups.destroy_all
120
+ group = ecommerce.add_custom_field_group({name: 'Products Details', slug: 'plugin_ecommerce_product_data'})
121
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.sku', default: 'Sku')", "slug" => "ecommerce_sku"}, {field_key: "text_box", required: true, label_eval: true})
122
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.attrs', default: 'Attributes')", "slug" => "ecommerce_attrs", description: "t('plugins.ecommerce.product.attrs_descr', default: 'Please enter your product attributes separated by commas, like: Color ==> Red, Blue, Green')"}, {field_key: "field_attrs", required: false, multiple: true, false: true, translate: true, label_eval: true})
123
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.photos', default: 'Photos')", "slug" => "ecommerce_photos"}, {field_key: "image", required: false, multiple: true, label_eval: true})
124
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.price', default: 'Price')", "slug" => "ecommerce_price", "description" => "t('plugins.ecommerce.product.current_unit', default: 'Current unit: %{unit}', unit: current_site.current_unit.to_s)"}, {field_key: "numeric", required: true, label_eval: true})
125
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.tax', default: 'Tax')", "slug" => "ecommerce_tax"}, {field_key: "select_eval", required: false, command: "options_from_collection_for_select(current_site.tax_rates.all, \"id\", \"the_name\")", label_eval: true})
126
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.weight', default: 'Weight')", "slug" => "ecommerce_weight", "description" => "t('plugins.ecommerce.product.current_weight', default: 'Current weight: %{weight}', weight: current_site.current_weight.to_s)"}, {field_key: "text_box", required: true, label_eval: true})
127
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true})
128
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.qty', default: 'Quantity')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true, label_eval: true})
129
+ group.add_manual_field({"name" => "t('plugins.ecommerce.product.files', default: 'Product files')", "slug" => "ecommerce_files"}, {field_key: "private_file", multiple: true, required: false, label_eval: true})
127
130
  end
128
131
  end
129
132
  end
@@ -6,4 +6,7 @@ class Plugins::Ecommerce::Attribute < ActiveRecord::Base
6
6
  scope :only_group, ->{ where(parent_id: nil) }
7
7
  scope :only_value, ->{ where.not(parent_id: nil) }
8
8
  default_scope ->{ order(position: :ASC) }
9
+ def translated_values
10
+ values.select(:id, :label, :key).map{|item| item.label = item.label.to_s.translate; item }
11
+ end
9
12
  end
@@ -12,6 +12,16 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
12
12
 
13
13
  after_create :generate_slug
14
14
 
15
+ # status: bank_pending => pending of verification for bank transfer orders
16
+ # paid => paid by some method
17
+ # canceled => canceled order
18
+ # shipped => shipped status
19
+ # accepted => received status
20
+
21
+ def payment_method
22
+ @_cama_cache_payment_method ||= Plugins::Ecommerce::PaymentMethod.find_by_id(get_meta('payment_method_id', self.payment_method_id))
23
+ end
24
+
15
25
  def add_product(product, qty = 1, variation_id = nil)
16
26
  pi = product_items.where(product_id: product.id, variation_id: variation_id).first
17
27
  if pi.present?
@@ -61,9 +71,7 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
61
71
  res[:error] = 'required_minimum_price'
62
72
  else
63
73
  case opts[:discount_type]
64
- when 'free'
65
- res[:discount] = price || sub_total
66
- when 'free_ship'
74
+ when 'free_ship', 'free'
67
75
  res[:discount] = total_shipping
68
76
  when 'percent'
69
77
  res[:discount] = sub_total * opts[:amount].to_f / 100
@@ -126,10 +134,15 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
126
134
  shipping_method.present? ? shipping_method.get_price_from_weight(weight_total) : 0
127
135
  end
128
136
 
129
- # set user in filter
137
+ # set user in filter (filter carts by user_id or cookie_id)
138
+ # cookie_id is used for public users who are buying without login
130
139
  def self.set_user(user)
131
- user_id = defined?(user.id) ? user.id : user.to_i
132
- self.where(user_id: user_id)
140
+ defined?(user.id) ? self.where(user_id: user.id) : self.where(visitor_key: user)
141
+ end
142
+
143
+ # move current cart from public user into existent user
144
+ def change_user(user)
145
+ update_columns(user_id: user.id, visitor_key: nil)
133
146
  end
134
147
 
135
148
  # check if the price of the cart is 0, including prices for products, discounts, shipping
@@ -166,7 +179,7 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
166
179
  cache_the_shipping: c.the_total_shipping,
167
180
  )
168
181
  end
169
-
182
+
170
183
  def mark_paid(status = 'paid')
171
184
  self.update_columns(
172
185
  status: status,
@@ -174,6 +187,17 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
174
187
  )
175
188
  end
176
189
 
190
+ # return the gateway for paypal transactions
191
+ def paypal_gateway
192
+ ActiveMerchant::Billing::Base.mode = payment_method.options[:paypal_sandbox].to_s.to_bool ? :test : :production
193
+ paypal_options = {
194
+ login: payment_method.options[:paypal_login],
195
+ password: payment_method.options[:paypal_password],
196
+ signature: payment_method.options[:paypal_signature]
197
+ }
198
+ ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
199
+ end
200
+
177
201
 
178
202
  private
179
203
  def generate_slug
@@ -1,17 +1,8 @@
1
+ ## not used anymore (DEPRECATED)
1
2
  class Plugins::Ecommerce::LegacyOrder < CamaleonCms::TermTaxonomy
2
3
  default_scope { where(taxonomy: :ecommerce_order) }
3
4
  has_one :details, class_name: "Plugins::Ecommerce::OrderDetail", foreign_key: :order_id, dependent: :destroy
4
5
  has_many :products, foreign_key: :objectid, through: :term_relationships, :source => :objects
5
- belongs_to :customer, class_name: "CamaleonCms::User", foreign_key: :user_id
6
-
7
- def add_product(object)
8
- post_id = defined?(object.id) ? object.id : object.to_i
9
- term_relationships.where(objectid: post_id).first_or_create if post_id > 0
10
- end
11
- def remove_product(object)
12
- post_id = defined?(object.id) ? object.id : object.to_i
13
- term_relationships.where(objectid: post_id).destroy_all if post_id > 0
14
- end
15
6
 
16
7
  def payment_method
17
8
  Plugins::Ecommerce::PaymentMethod.find_by_id get_meta("payment")[:payment_id]
@@ -25,24 +16,4 @@ class Plugins::Ecommerce::LegacyOrder < CamaleonCms::TermTaxonomy
25
16
  def shipping_method
26
17
  Plugins::Ecommerce::ShippingMethod.find_by_id get_meta("payment", {})[:shipping_method]
27
18
  end
28
-
29
- def canceled?
30
- status == 'canceled'
31
- end
32
- def unpaid?
33
- status == 'unpaid'
34
- end
35
-
36
- def paid?
37
- payment.present?
38
- end
39
-
40
-
41
- # set user in filter
42
- def self.set_user(user)
43
- user_id = defined?(user.id) ? user.id : user.to_i
44
- self.where(user_id: user_id)
45
- end
46
-
47
-
48
19
  end
@@ -2,16 +2,14 @@ class Plugins::Ecommerce::Order < Plugins::Ecommerce::Cart
2
2
  self.table_name = 'plugins_ecommerce_orders'
3
3
  has_many :metas, ->{ where(object_class: 'Plugins::Ecommerce::Cart')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
4
4
  default_scope { where(kind: 'order') }
5
- # status: bank_pending => pending of verification for bank transfer orders
5
+ # status:
6
+ # bank_pending => pending of verification for bank transfer orders
7
+ # on_delivery => pending to mark as paid after after delivery
6
8
  # paid => paid by some method
7
9
  # canceled => canceled order
8
10
  # shipped => shipped status
9
11
  # accepted => received status
10
12
 
11
- def payment_method
12
- Plugins::Ecommerce::PaymentMethod.find_by_id(get_meta('payment_method_id', self.payment_method_id))
13
- end
14
-
15
13
  def paid?
16
14
  status == 'paid'
17
15
  end
@@ -49,10 +47,18 @@ class Plugins::Ecommerce::Order < Plugins::Ecommerce::Cart
49
47
  status == 'bank_pending'
50
48
  end
51
49
 
50
+ def on_delivery_pending?
51
+ status == 'on_delivery'
52
+ end
53
+
52
54
  def bank_confirmed!
53
55
  update_columns({status: 'paid', updated_at: Time.current})
54
56
  end
55
57
 
58
+ def on_delivery_confirmed!
59
+ update_columns({status: 'paid', updated_at: Time.current})
60
+ end
61
+
56
62
  def payment_data
57
63
  get_meta('payment_data', {})
58
64
  end
@@ -1,3 +1,4 @@
1
+ ## not used anymore (DEPRECATED)
1
2
  class Plugins::Ecommerce::OrderDetail < ActiveRecord::Base
2
3
  self.table_name = "plugins_order_details"
3
4
  belongs_to :order, class_name: "Plugins::Ecommerce::Order", foreign_key: :order_id
@@ -6,13 +6,17 @@ class Plugins::Ecommerce::PaymentMethod < CamaleonCms::TermTaxonomy
6
6
 
7
7
  def method_text
8
8
  if options[:type] == 'paypal'
9
- I18n.t 'plugin.ecommerce.method_paypal'
9
+ I18n.t 'plugins.ecommerce.by_paypal', default: 'Paypal'
10
10
  elsif options[:type] == 'credit_card'
11
- I18n.t 'plugin.ecommerce.method_credit_card'
12
- elsif options[:type] == 'bank_transfer'
13
- I18n.t 'plugin.ecommerce.method_bank_transfer'
11
+ I18n.t 'plugins.ecommerce.method_credit_card'
14
12
  elsif options[:type] == 'authorize_net'
15
- I18n.t 'plugin.ecommerce.method_authorize_net'
13
+ I18n.t 'plugins.ecommerce.by_authorize_net', default: 'By credit card (Authorize.net)'
14
+ elsif options[:type] == 'on_delivery'
15
+ I18n.t 'plugins.ecommerce.by_on_delivery'
16
+ elsif options[:type] == 'stripe'
17
+ I18n.t 'plugins.ecommerce.by_stripe', default: 'By Stripe'
18
+ elsif options[:type] == 'bank_transfer'
19
+ I18n.t 'plugins.ecommerce.by_bank_transfer', default: 'Payment on Delivery'
16
20
  else
17
21
  'None'
18
22
  end
@@ -1,9 +1,15 @@
1
1
  class Plugins::Ecommerce::ProductVariation < ActiveRecord::Base
2
2
  self.table_name='plugins_ecommerce_product_variations'
3
3
  belongs_to :product, class_name: "CamaleonCms::Post"
4
+ before_destroy :verify_related_orders
4
5
 
5
6
  # return all attribute values assigned to this product
6
7
  def attribute_values
7
8
  Plugins::Ecommerce::Attribute.only_value.where(id: self.attribute_ids.to_s.split(','))
8
9
  end
10
+
11
+ private
12
+ def verify_related_orders
13
+ errors.add(:base, t('plugins.ecommerce.message.not_deletable_product_variations')) if Plugins::Ecommerce::ProductItem.where(variation_id: id).any?
14
+ end
9
15
  end
@@ -7,7 +7,7 @@ class Plugins::Ecommerce::CartService
7
7
  attr_reader :site, :cart
8
8
 
9
9
  def pay_with_authorize_net(options={})
10
- payment_method = options[:payment_method] || site_service.payment_method('authorize_net')
10
+ payment_method = options[:payment_method] || site.payment_method('authorize_net')
11
11
  billing_address = cart.get_meta("billing_address")
12
12
  details = cart.get_meta("details")
13
13
  amount = Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(cart.total_amount)
@@ -61,15 +61,8 @@ class Plugins::Ecommerce::CartService
61
61
  end
62
62
 
63
63
  def pay_with_paypal(options={})
64
- payment_method = options[:payment_method] || site_service.payment_method('paypal')
65
64
  billing_address = cart.get_meta("billing_address")
66
- ActiveMerchant::Billing::Base.mode = payment_method.options[:paypal_sandbox].to_s.to_bool ? :test : :production
67
- paypal_options = {
68
- login: payment_method.options[:paypal_login],
69
- password: payment_method.options[:paypal_password],
70
- signature: payment_method.options[:paypal_signature]
71
- }
72
- gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
65
+ gateway = cart.paypal_gateway
73
66
  amount_in_cents = Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(cart.total_amount)
74
67
  gateway_request = {
75
68
  brand_name: site.name,
@@ -106,7 +99,7 @@ class Plugins::Ecommerce::CartService
106
99
 
107
100
  def pay_with_stripe(options)
108
101
  require 'stripe'
109
- payment_method = options[:payment_method] || site_service.payment_method('stripe')
102
+ payment_method = options[:payment_method] || site.payment_method('stripe')
110
103
  Stripe.api_key = payment_method.options[:stripe_id]
111
104
  customer = Stripe::Customer.create(
112
105
  email: options[:email], source: options[:stripe_token])
@@ -116,7 +109,7 @@ class Plugins::Ecommerce::CartService
116
109
  customer: customer.id,
117
110
  amount: amount_in_cents,
118
111
  description: "Payment Products: #{cart.products_title}",
119
- currency: site_service.currency,
112
+ currency: site.currency_code,
120
113
  )
121
114
  payment_data = {
122
115
  email: options[:email],
@@ -140,10 +133,4 @@ class Plugins::Ecommerce::CartService
140
133
  cart.convert_to_order
141
134
  end
142
135
  end
143
-
144
- private
145
-
146
- def site_service
147
- @site_service ||= Plugins::Ecommerce::SiteService.new(site)
148
- end
149
136
  end
@@ -1,2 +1,2 @@
1
- <p><%= t('plugin.ecommerce.mail.dear', default: 'Dear %{name}: ', name: @extra_data[:order].user.fullname) %></p>
2
- <p><%= t('plugin.ecommerce.mail.order_canceled.message', default: 'Your order %{order} has been canceled: %{message}', order: @extra_data[:order].slug, message: @extra_data[:message]) %></p>
1
+ <p><%= t('plugins.ecommerce.mail.dear', default: 'Dear %{name}: ', name: @extra_data[:order].user.fullname) %></p>
2
+ <p><%= t('plugins.ecommerce.mail.order_canceled.message', default: 'Your order %{order} has been canceled: %{message}', order: @extra_data[:order].slug, message: @extra_data[:message]) %></p>
@@ -1,2 +1,2 @@
1
- <p><%= t('plugin.ecommerce.mail.dear', default: 'Dear %{name}: ', name: @extra_data[:fullname]) %></p>
2
- <p><%= t('plugin.ecommerce.mail.order_confirmed.message', default: 'We have confirmed your payment by bank transfer for the order #%{order}.\n\n Thanks for your preference.', order: @extra_data[:order_slug]).gsub(/\n/, '<br>').gsub('\n', '<br>') %></p>
1
+ <p><%= t('plugins.ecommerce.mail.dear', default: 'Dear %{name}: ', name: @extra_data[:fullname]) %></p>
2
+ <p><%= t('plugins.ecommerce.mail.order_confirmed.message', default: 'We have confirmed your payment by bank transfer for the order #%{order}.\n\n Thanks for your preference.', order: @extra_data[:order_slug]).gsub(/\n/, '<br>').gsub('\n', '<br>') %></p>
@@ -1,3 +1,5 @@
1
- <p><%= t('plugin.ecommerce.mail.order_received.welcome') %><%= @extra_data[:fullname] %></p>
2
- <p><%= t('plugin.ecommerce.mail.order_received.thanks') %></p>
3
- <p><%= t('plugin.ecommerce.mail.order_received.reference') %> <a href="<%= @extra_data[:order_url] %>"><%= @extra_data[:order_slug] %></a>
1
+ <p><%= t('plugins.ecommerce.mail.order_received.welcome') %> <%= @extra_data[:fullname] %></p>
2
+ <p><%= t('plugins.ecommerce.mail.order_received.thanks') %></p>
3
+ <%= raw @extra_data[:order_details_html] %>
4
+ <p><%= t('plugins.ecommerce.mail.order_received.reference') %> <a href="<%= @extra_data[:order_url] %>"><%= @extra_data[:order_slug] %></a>
5
+