camaleon_ecommerce 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/plugins/ecommerce/admin.js +33 -0
  6. data/app/assets/javascripts/plugins/ecommerce/cart.js +207 -0
  7. data/app/assets/javascripts/plugins/ecommerce/fix_form.js +10 -0
  8. data/app/assets/javascripts/plugins/ecommerce/jquery.creditCardValidator.js +208 -0
  9. data/app/assets/stylesheets/plugins/ecommerce/admin.scss +122 -0
  10. data/app/assets/stylesheets/plugins/ecommerce/front.scss +36 -0
  11. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +61 -0
  12. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +96 -0
  13. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +90 -0
  14. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +70 -0
  15. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +22 -0
  16. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +62 -0
  17. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +61 -0
  18. data/app/controllers/plugins/ecommerce/admin_controller.rb +20 -0
  19. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +166 -0
  20. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +255 -0
  21. data/app/controllers/plugins/ecommerce/front_controller.rb +18 -0
  22. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +46 -0
  23. data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +49 -0
  24. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +240 -0
  25. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +67 -0
  26. data/app/models/plugins/ecommerce/cart.rb +40 -0
  27. data/app/models/plugins/ecommerce/coupon.rb +25 -0
  28. data/app/models/plugins/ecommerce/coupon_decorator.rb +60 -0
  29. data/app/models/plugins/ecommerce/order.rb +65 -0
  30. data/app/models/plugins/ecommerce/order_decorator.rb +54 -0
  31. data/app/models/plugins/ecommerce/order_detail.rb +13 -0
  32. data/app/models/plugins/ecommerce/payment_method.rb +29 -0
  33. data/app/models/plugins/ecommerce/product.rb +14 -0
  34. data/app/models/plugins/ecommerce/shipping_method.rb +26 -0
  35. data/app/models/plugins/ecommerce/tax_rate.rb +18 -0
  36. data/app/views/camaleon_cms/html_mailer/order_received.html.erb +3 -0
  37. data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +3 -0
  38. data/app/views/camaleon_cms/html_mailer/recovery_cart.html.erb +4 -0
  39. data/app/views/layouts/plugins/ecommerce/mailer.html.erb +22 -0
  40. data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +73 -0
  41. data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +50 -0
  42. data/app/views/plugins/ecommerce/admin/index.html.erb +2 -0
  43. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +64 -0
  44. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +90 -0
  45. data/app/views/plugins/ecommerce/admin/orders/show.html.erb +173 -0
  46. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +115 -0
  47. data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +43 -0
  48. data/app/views/plugins/ecommerce/admin/payment_methods/show.html.erb +70 -0
  49. data/app/views/plugins/ecommerce/admin/prices/form.html.erb +49 -0
  50. data/app/views/plugins/ecommerce/admin/prices/index.html.erb +39 -0
  51. data/app/views/plugins/ecommerce/admin/prices/show.html.erb +19 -0
  52. data/app/views/plugins/ecommerce/admin/products/index.html.erb +114 -0
  53. data/app/views/plugins/ecommerce/admin/settings/index.html.erb +25 -0
  54. data/app/views/plugins/ecommerce/admin/shipping_methods/form.html.erb +39 -0
  55. data/app/views/plugins/ecommerce/admin/shipping_methods/index.html.erb +41 -0
  56. data/app/views/plugins/ecommerce/admin/shipping_methods/show.html.erb +22 -0
  57. data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +36 -0
  58. data/app/views/plugins/ecommerce/admin/tax_rates/index.html.erb +41 -0
  59. data/app/views/plugins/ecommerce/front/_post_list_item.html.erb +18 -0
  60. data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +59 -0
  61. data/app/views/plugins/ecommerce/front/checkout/index.html.erb +166 -0
  62. data/app/views/plugins/ecommerce/front/index.html.erb +2 -0
  63. data/app/views/plugins/ecommerce/front/list_products.html.erb +34 -0
  64. data/app/views/plugins/ecommerce/front/orders/index.html.erb +46 -0
  65. data/app/views/plugins/ecommerce/front/orders/pay_by_bank_transfer.html.erb +67 -0
  66. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card.html.erb +131 -0
  67. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card_authorize_net.erb +150 -0
  68. data/app/views/plugins/ecommerce/front/orders/select_payment.html.erb +70 -0
  69. data/app/views/plugins/ecommerce/front/orders/show.html.erb +76 -0
  70. data/app/views/plugins/ecommerce/front/product.html.erb +105 -0
  71. data/app/views/plugins/ecommerce/layouts/_ecommerce.html.erb +41 -0
  72. data/app/views/plugins/ecommerce/partials/_form_address.html.erb +84 -0
  73. data/app/views/plugins/ecommerce/partials/_table_order_products.html.erb +85 -0
  74. data/config/camaleon_plugin.json +48 -0
  75. data/config/currency.json +154 -0
  76. data/config/currency_en.json +154 -0
  77. data/config/currency_es.json +154 -0
  78. data/config/custom_models.rb +64 -0
  79. data/config/locales/readme.txt +1 -0
  80. data/config/locales/translation.yml +371 -0
  81. data/config/routes.rb +57 -0
  82. data/lib/camaleon_ecommerce.rb +4 -0
  83. data/lib/ecommerce.rb +4 -0
  84. data/lib/ecommerce/engine.rb +6 -0
  85. data/lib/ecommerce/version.rb +3 -0
  86. data/lib/tasks/ecommerce_tasks.rake +4 -0
  87. metadata +185 -0
@@ -0,0 +1,18 @@
1
+ =begin
2
+ Camaleon CMS is a content management system
3
+ Copyright (C) 2015 by Owen Peredo Diaz
4
+ Email: owenperedo@gmail.com
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
+ See the GNU Affero General Public License (GPLv3) for more details.
8
+ =end
9
+ class Plugins::Ecommerce::FrontController < CamaleonCms::Apps::PluginsFrontController
10
+ before_action :ecommerce_add_assets_in_front
11
+ def index
12
+ # here your actions for frontend module
13
+ end
14
+
15
+ def product
16
+
17
+ end
18
+ end
@@ -0,0 +1,46 @@
1
+ module Plugins::Ecommerce::EcommerceEmailHelper
2
+ include CamaleonCms::EmailHelper
3
+
4
+ def send_order_received_email(order)
5
+ extra_data = {
6
+ :fullname => order.customer.fullname,
7
+ :order_slug => order.slug,
8
+ :order_url => plugins_ecommerce_order_show_url(order: order.slug),
9
+ :billing_information => order.get_meta('billing_address'),
10
+ :shipping_address => order.get_meta('shipping_address'),
11
+ :subtotal => order.get_meta("payment")[:total],
12
+ :total_cost => order.get_meta("payment")[:amount],
13
+ :order => order
14
+ }
15
+ send_email(order.customer.email, t('plugin.ecommerce.email.order_received.subject'), '', nil, [], 'order_received', 'plugins/ecommerce/mailer', extra_data)
16
+ end
17
+
18
+ def send_order_received_admin_notice(order)
19
+ extra_data = {
20
+ :fullname => order.customer.fullname,
21
+ :order_slug => order.slug,
22
+ :order_url => plugins_ecommerce_order_show_url(order: order.slug),
23
+ :billing_information => order.get_meta('billing_address'),
24
+ :shipping_address => order.get_meta('shipping_address'),
25
+ :subtotal => order.get_meta("payment")[:total],
26
+ :total_cost => order.get_meta("payment")[:amount],
27
+ :order => order
28
+ }
29
+
30
+ users = current_site.users.where(:role => :admin)
31
+ users.each do |user|
32
+ extra_data[:admin] = user
33
+ send_email(user.email, t('plugin.ecommerce.email.order_received_admin.subject'), '', nil, [], 'order_received_admin', 'plugins/ecommerce/mailer', extra_data)
34
+ end
35
+ end
36
+
37
+ def send_recovery_cart_email(order)
38
+ extra_data = {
39
+ :fullname => order.customer.fullname,
40
+ :order => order
41
+ }
42
+ send_email(order.customer.email, t('plugin.ecommerce.email.recovery_cart.subject'), '', nil, [], 'recovery_cart', 'plugins/ecommerce/mailer', extra_data)
43
+ Rails.logger.info "Send recovery to #{order.customer.email} with order #{order.slug}"
44
+ end
45
+
46
+ end
@@ -0,0 +1,49 @@
1
+ =begin
2
+ Camaleon CMS is a content management system
3
+ Copyright (C) 2015 by Owen Peredo Diaz
4
+ Email: owenperedo@gmail.com
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
+ See the GNU Affero General Public License (GPLv3) for more details.
8
+ =end
9
+ #encoding: utf-8
10
+ module Plugins::Ecommerce::EcommerceFunctionsHelper
11
+ def self.included(klass)
12
+ klass.helper_method [:e_get_currency_units, :e_get_currency_weight, :e_symbol_by_code] rescue ""
13
+ end
14
+ def e_get_currency_weight
15
+ r = {}
16
+ JSON.parse('[{"code":"kg","name":'+"#{t('plugin.ecommerce.select.kilogram').to_json}"'},{"code":"lb","name":'+"#{t('plugin.ecommerce.select.pound').to_json}"'},{"code":"dr","name":'+"#{t('plugin.ecommerce.select.dram').to_json}"'},{"code":"gr","name":'+"#{t('plugin.ecommerce.select.grain').to_json}"'},{"code":"g","name":'+"#{t('plugin.ecommerce.select.gram').to_json}"'},{"code":"UK","name":'+"#{t('plugin.ecommerce.select.hundredweight').to_json}"'},{"code":"mg","name":'+"#{t('plugin.ecommerce.select.milligram').to_json}"'},{"code":"oz","name":'+"#{t('plugin.ecommerce.select.ounce').to_json}"'},{"code":"t","name":'+"#{t('plugin.ecommerce.select.tonne').to_json}"'}]').collect do |item|
17
+ item['name'] = item['name'].to_s.titleize
18
+ r[item['code']] = item
19
+ end
20
+ @e_get_currency_weight ||= r
21
+ end
22
+
23
+ def e_get_currency_units
24
+ file = File.read("#{File.dirname(__FILE__)}/../../../../config/currency_#{I18n.locale.to_s}.json")
25
+ @e_get_currency_units ||= JSON.parse(file)
26
+ end
27
+
28
+ def e_symbol_by_code(unit)
29
+ e_get_currency_units[unit]['symbol'] rescue '$xx'
30
+ end
31
+
32
+ # use in add cart
33
+ def e_add_data_product(data, product_id)
34
+ post = CamaleonCms::Post.find(product_id).decorate
35
+ attributes = post.attributes
36
+ attributes[:content] = ''
37
+ data[:product_title] = post.the_title
38
+ data[:price] = post.get_field_value(:ecommerce_price)
39
+ data[:weight] = post.get_field_value(:ecommerce_weight)
40
+ data[:tax_rate_id] = post.get_field_value(:ecommerce_tax)
41
+ tax_product = current_site.tax_rates.find(data[:tax_rate_id]).options[:rate].to_f rescue 0
42
+ data[:tax_percent] = tax_product
43
+ data[:tax] = data[:price].to_f * data[:tax_percent] / 100 rescue 0
44
+ data[:currency_code] = current_site.currency_code
45
+ metas = {}
46
+ post.metas.map{|m| metas[m.key] = m.value }
47
+ data.merge(post: attributes, fields: post.get_field_values_hash, meta: metas)
48
+ end
49
+ end
@@ -0,0 +1,240 @@
1
+ =begin
2
+ Camaleon CMS is a content management system
3
+ Copyright (C) 2015 by Owen Peredo Diaz
4
+ Email: owenperedo@gmail.com
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
+ See the GNU Affero General Public License (GPLv3) for more details.
8
+ =end
9
+ module Plugins::Ecommerce::EcommerceHelper
10
+ include Plugins::Ecommerce::EcommerceEmailHelper
11
+
12
+ def ecommerce_on_render_post(d)
13
+ if d[:post_type].slug == 'commerce'
14
+ ecommerce_add_assets_in_front
15
+ d[:render] = 'plugins/ecommerce/front/product'
16
+ end
17
+ d
18
+ end
19
+
20
+ def ecommerce_on_render_post_type(d)
21
+ # d = {post_type: @post_type, layout: (self.send :_layout), render: verify_template("post_type")}
22
+ if d[:post_type].slug == 'commerce'
23
+ ecommerce_add_assets_in_front
24
+ @ecommerce_bredcrumb << [d[:post_type].the_title]
25
+ d[:render] = 'plugins/ecommerce/front/list_products'
26
+ end
27
+ d
28
+ end
29
+
30
+ def ecommerce_admin_list_post(d)
31
+ if d[:post_type].slug == 'commerce'
32
+ ecommerce_add_assets_in_front
33
+ d[:render] = 'plugins/ecommerce/admin/products/index'
34
+ end
35
+ d
36
+ end
37
+
38
+ def ecommerce_form_post(d)
39
+ if d[:post_type].slug == 'commerce'
40
+ append_asset_libraries({ecommerce: {css: [], js: [plugin_gem_asset('fix_form')]}})
41
+ end
42
+ d
43
+ end
44
+
45
+ def ecommerce_front_before_load
46
+ @ecommerce_post_type = current_site.post_types.where(slug: 'commerce').first.decorate
47
+ @ecommerce_bredcrumb = [].push(["Home", cama_root_url])
48
+ end
49
+
50
+ def ecommerce_admin_before_load
51
+ # add menu bar
52
+ pt = current_site.post_types.hidden_menu.where(slug: "commerce").first
53
+ if pt.present?
54
+ items_i = []
55
+ items_i << {icon: "list", title: t('plugin.ecommerce.all_products'), url: cama_admin_post_type_posts_path(pt.id)} if can? :posts, pt
56
+ items_i << {icon: "plus", title: t('camaleon_cms.admin.post_type.add_new'), url: new_cama_admin_post_type_post_path(pt.id)} if can? :create_post, pt
57
+ if pt.manage_categories?
58
+ items_i << {icon: "folder-open", title: t('camaleon_cms.admin.post_type.categories'), url: cama_admin_post_type_categories_path(pt.id)} if can? :categories, pt
59
+ end
60
+ if pt.manage_tags?
61
+ items_i << {icon: "tags", title: t('camaleon_cms.admin.post_type.tags'), url: cama_admin_post_type_post_tags_path(pt.id)} if can? :post_tags, pt
62
+ end
63
+ if can? :posts, pt
64
+ items_i << {icon: "reorder", title: "<span>#{t('plugin.ecommerce.orders')} <small class='label label-primary'>#{current_site.orders.not_closed.size}</small></span>", url: admin_plugins_ecommerce_orders_path}
65
+ items_i << {icon: "money", title: t('plugin.ecommerce.tax_rates'), url: admin_plugins_ecommerce_tax_rates_path}
66
+ items_i << {icon: "taxi", title: t('plugin.ecommerce.shipping_methods'), url: admin_plugins_ecommerce_shipping_methods_path}
67
+ items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods'), url: admin_plugins_ecommerce_payment_methods_path}
68
+ items_i << {icon: "tag", title: t('plugin.ecommerce.coupons'), url: admin_plugins_ecommerce_coupons_path}
69
+ items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings'), url: admin_plugins_ecommerce_settings_path}
70
+ end
71
+
72
+ admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugin.ecommerce.e_commerce'), url: "", items: items_i}) if items_i.present?
73
+ end
74
+
75
+ # add assets admin
76
+ append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: [plugin_gem_asset('admin')]}})
77
+
78
+ end
79
+
80
+ def ecommerce_app_before_load
81
+ CamaleonCms::Site.class_eval do
82
+ #attr_accessible :my_id
83
+ has_many :carts, :class_name => 'Plugins::Ecommerce::Cart', foreign_key: :parent_id, dependent: :destroy
84
+ has_many :orders, :class_name => 'Plugins::Ecommerce::Order', foreign_key: :parent_id, dependent: :destroy
85
+ has_many :payment_methods, :class_name => 'Plugins::Ecommerce::PaymentMethod', foreign_key: :parent_id, dependent: :destroy
86
+ has_many :shipping_methods, :class_name => 'Plugins::Ecommerce::ShippingMethod', foreign_key: :parent_id, dependent: :destroy
87
+ has_many :coupons, :class_name => 'Plugins::Ecommerce::Coupon', foreign_key: :parent_id, dependent: :destroy
88
+ has_many :tax_rates, :class_name => 'Plugins::Ecommerce::TaxRate', foreign_key: :parent_id, dependent: :destroy
89
+ end
90
+
91
+ CamaleonCms::SiteDecorator.class_eval do
92
+ def current_unit
93
+ @current_unit ||= h.e_get_currency_units[object.get_meta("_setting_ecommerce", {})[:current_unit]]['symbol'] rescue '$'
94
+ end
95
+
96
+ def currency_code
97
+ @currency_code ||= h.e_get_currency_units[object.get_meta("_setting_ecommerce", {})[:current_unit]]['code'] rescue 'USD'
98
+ end
99
+
100
+ def current_weight
101
+ @current_weight ||= h.e_get_currency_weight[object.get_meta("_setting_ecommerce", {})[:current_weight]]['code'] rescue 'kg'
102
+ end
103
+ end
104
+
105
+ CamaleonCms::PostDecorator.class_eval do
106
+ def the_sku
107
+ object.get_field_value('ecommerce_sku').to_s
108
+ end
109
+
110
+ def the_price
111
+ "#{h.current_site.current_unit} #{object.get_field_value('ecommerce_price').to_f}"
112
+ end
113
+
114
+ def the_weight
115
+ "#{h.current_site.current_weight} #{object.get_field_value('ecommerce_weight').to_f}"
116
+ end
117
+
118
+ def the_qty
119
+ object.get_field_value('ecommerce_qty') || 0
120
+ end
121
+
122
+ def the_photos
123
+ object.get_field_values('ecommerce_photos') || []
124
+ end
125
+
126
+ def in_stock?
127
+ object.get_field_value('ecommerce_stock').to_s.to_bool
128
+ end
129
+
130
+ def the_stock_status
131
+ if in_stock? && the_qty_real.to_i > 0
132
+ "<span class='label label-success'>#{I18n.t('plugin.ecommerce.product.in_stock')}</span>"
133
+ else
134
+ "<span class='label label-danger'>#{I18n.t('plugin.ecommerce.product.not_in_tock')}</span>"
135
+ end
136
+ end
137
+
138
+ def featured?
139
+ object.get_field_value('ecommerce_featured').to_s.to_bool
140
+ end
141
+
142
+ def the_featured_status
143
+ if featured?
144
+ "<span class='label label-primary'>#{I18n.t('plugin.ecommerce.product.featured')}</span>"
145
+ else
146
+ ""
147
+ end
148
+ end
149
+
150
+ def the_qty_real
151
+ object.get_field_value('ecommerce_qty') || 0
152
+ end
153
+ end
154
+
155
+
156
+ end
157
+
158
+ # here all actions on plugin destroying
159
+ # plugin: plugin model
160
+ def ecommerce_on_destroy(plugin)
161
+
162
+ end
163
+
164
+ # here all actions on going to active
165
+ # you can run sql commands like this:
166
+ # results = ActiveRecord::Base.connection.execute(query);
167
+ # plugin: plugin model
168
+ def ecommerce_on_active(plugin)
169
+ generate_custom_field_products
170
+
171
+ unless ActiveRecord::Base.connection.table_exists? 'plugins_order_details'
172
+ Plugins::Ecommerce::Order.where("1 = 1").delete_all
173
+ ActiveRecord::Base.connection.create_table :plugins_order_details do |t|
174
+ t.integer :order_id
175
+ t.string :customer, :email, :phone
176
+ t.datetime :received_at, :accepted_at, :shipped_at, :closed_at
177
+ t.timestamps
178
+ end
179
+ end
180
+ end
181
+
182
+ # here all actions on going to inactive
183
+ # plugin: plugin model
184
+ def ecommerce_on_inactive(plugin)
185
+
186
+ end
187
+
188
+ def get_commerce_post_type
189
+ @ecommerce = current_site.post_types.hidden_menu.where(slug: "commerce").first
190
+ unless @ecommerce.present?
191
+ @ecommerce = current_site.post_types.hidden_menu.new(slug: "commerce", name: "Product")
192
+ if @ecommerce.save
193
+ @ecommerce.set_meta('_default', {
194
+ has_category: true,
195
+ has_tags: true,
196
+ not_deleted: true,
197
+ has_summary: true,
198
+ has_content: true,
199
+ has_comments: false,
200
+ has_picture: true,
201
+ has_template: false,
202
+ })
203
+ @ecommerce.categories.create({name: 'Uncategorized', slug: 'Uncategorized'.parameterize})
204
+ end
205
+
206
+ end
207
+
208
+ end
209
+
210
+ def ecommerce_add_assets_in_front
211
+ append_asset_libraries({ecommerce_front: {css: [plugin_gem_asset('front')], js: [plugin_gem_asset('cart')]}})
212
+ end
213
+
214
+ def mark_order_like_received(order)
215
+ order.update({status: 'received'})
216
+ order.details.update({received_at: Time.now})
217
+ send_order_received_email(order)
218
+ # Send email to admins
219
+ send_order_received_admin_notice(order)
220
+ end
221
+
222
+ private
223
+ def generate_custom_field_products
224
+ get_commerce_post_type
225
+ unless @ecommerce.get_field_groups.where(slug: "plugin_ecommerce_product_data").present?
226
+ @ecommerce.get_field_groups.destroy_all
227
+ group = @ecommerce.add_custom_field_group({name: 'Products Details', slug: 'plugin_ecommerce_product_data'})
228
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.sku')", "slug" => "ecommerce_sku"}, {field_key: "text_box", required: true})
229
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.attrs')", "slug" => "ecommerce_attrs"}, {field_key: "field_attrs", required: false, multiple: true, false: true})
230
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.photos')", "slug" => "ecommerce_photos"}, {field_key: "image", required: false, multiple: true})
231
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.price')", "slug" => "ecommerce_price", "description" => "eval('\"Current unit: \" + h.current_site.current_unit.to_s')"}, {field_key: "numeric", required: true})
232
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.tax')", "slug" => "ecommerce_tax"}, {field_key: "select_eval", required: false, command: "options_from_collection_for_select(current_site.tax_rates.all, \"id\", \"the_name\")"})
233
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.weight')", "slug" => "ecommerce_weight", "description" => "eval('\"Current weight: \" + h.current_site.current_weight.to_s')"}, {field_key: "text_box", required: true})
234
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true})
235
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.qty')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true})
236
+ group.add_manual_field({"name" => "t('plugin.ecommerce.product.featured')", "slug" => "ecommerce_featured"}, {field_key: "checkbox", default: true})
237
+ end
238
+ end
239
+
240
+ end
@@ -0,0 +1,67 @@
1
+ module Plugins::Ecommerce::EcommercePaymentHelper
2
+ include Plugins::Ecommerce::EcommerceHelper
3
+
4
+ def payment_pay_by_credit_card_authorize_net(order)
5
+ payment = order.get_meta("payment")
6
+ billing_address = order.get_meta("billing_address")
7
+ details = order.get_meta("details")
8
+ if payment[:payment_id].nil?
9
+ payment_method = current_site.payment_methods.find_by_slug('authorizenet')
10
+ else
11
+ payment_method = current_site.payment_methods.find(payment[:payment_id])
12
+ end
13
+ amount = to_cents(payment[:amount].to_f)
14
+
15
+ @payment_params = {
16
+ :order_id => order.slug,
17
+ :currency => current_site.currency_code,
18
+ :email => details[:email],
19
+ :billing_address => {:name => "#{billing_address[:first_name]} #{billing_address[:last_name]}",
20
+ :address1 => billing_address[:address1],
21
+ :address2 => billing_address[:address2],
22
+ :city => billing_address[:city],
23
+ :state => billing_address[:state],
24
+ :country => billing_address[:country],
25
+ :zip => billing_address[:zip]
26
+ },
27
+ :description => 'Buy Products',
28
+ :ip => request.remote_ip
29
+ }
30
+
31
+ authorize_net_options = {
32
+ :login => payment_method.options[:authorize_net_login_id],
33
+ :password => payment_method.options[:authorize_net_transaction_key]
34
+ }
35
+
36
+ ActiveMerchant::Billing::Base.mode = payment_method.options[:authorize_net_sandbox].to_s.to_bool ? :test : :production
37
+
38
+ credit_card = ActiveMerchant::Billing::CreditCard.new(
39
+ :first_name => params[:firstName],
40
+ :last_name => params[:lastName],
41
+ :number => params[:cardNumber],
42
+ :month => params[:expMonth],
43
+ :year => "20#{params[:expYear]}",
44
+ :verification_value => params[:cvCode]
45
+ )
46
+
47
+ if credit_card.validate.empty?
48
+ gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(authorize_net_options)
49
+ response = gateway.purchase(amount, credit_card, @payment_params)
50
+ if response.success?
51
+ order.set_meta('pay_authorize_net', @payment_params)
52
+ mark_order_like_received(order)
53
+ return {success: 'Paid Correct'}
54
+ else
55
+ return {error: response.message}
56
+ end
57
+ else
58
+ return {error: 'Credit Card Invalid'}
59
+ end
60
+
61
+ end
62
+
63
+ def to_cents(money)
64
+ (money*100).round
65
+ end
66
+
67
+ end
@@ -0,0 +1,40 @@
1
+ =begin
2
+ Camaleon CMS is a content management system
3
+ Copyright (C) 2015 by Owen Peredo Diaz
4
+ Email: owenperedo@gmail.com
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
+ See the GNU Affero General Public License (GPLv3) for more details.
8
+ =end
9
+ class Plugins::Ecommerce::Cart < CamaleonCms::TermTaxonomy
10
+ default_scope { where(taxonomy: :ecommerce_cart) }
11
+ has_many :products, foreign_key: :objectid, through: :term_relationships, :source => :objects
12
+ belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
13
+
14
+ def add_product(object)
15
+ post_id = defined?(object.id) ? object.id : object.to_i
16
+ term_relationships.where(objectid: post_id).first_or_create if post_id > 0
17
+ end
18
+ def remove_product(object)
19
+ post_id = defined?(object.id) ? object.id : object.to_i
20
+ term_relationships.where(objectid: post_id).destroy_all if post_id > 0
21
+ end
22
+
23
+ def the_items_count
24
+ options.map{|k, p| p[:qty].to_i}.inject{|sum,x| sum + x } || 0
25
+ end
26
+
27
+ def the_amount_total
28
+ options.map{|k, p| (p[:price].to_f + p[:tax])* p[:qty].to_f}.inject{|sum,x| sum + x } || 0
29
+ end
30
+
31
+
32
+ # set user in filter
33
+ def self.set_user(user)
34
+ user_id = defined?(user.id) ? user.id : user.to_i
35
+ self.where(user_id: user_id)
36
+ end
37
+
38
+
39
+ end
40
+ #Cart = Plugins::Ecommerce::Cart