camaleon_ecommerce 0.0.4 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/plugins/ecommerce/admin.js +0 -33
- data/app/assets/javascripts/plugins/ecommerce/cart.js +83 -200
- data/app/assets/javascripts/plugins/ecommerce/fix_form.js +1 -4
- data/app/assets/stylesheets/plugins/ecommerce/checkout.css.scss +46 -0
- data/app/assets/stylesheets/plugins/ecommerce/front.scss +2 -30
- data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +2 -2
- data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +45 -34
- data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +4 -3
- data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +5 -5
- data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +0 -2
- data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +3 -3
- data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +2 -2
- data/app/controllers/plugins/ecommerce/admin_controller.rb +1 -1
- data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +162 -110
- data/app/controllers/plugins/ecommerce/front/orders_controller.rb +7 -234
- data/app/controllers/plugins/ecommerce/front_controller.rb +42 -3
- data/app/decorators/plugins/ecommerce/cart_decorator.rb +27 -0
- data/app/{models → decorators}/plugins/ecommerce/coupon_decorator.rb +1 -1
- data/app/decorators/plugins/ecommerce/order_decorator.rb +22 -0
- data/app/decorators/plugins/ecommerce/product_decorator.rb +88 -0
- data/app/decorators/plugins/ecommerce/product_item_decorator.rb +18 -0
- data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +91 -28
- data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +30 -136
- data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +14 -20
- data/app/models/plugins/ecommerce/cart.rb +139 -15
- data/app/models/plugins/ecommerce/coupon.rb +33 -7
- data/app/models/plugins/ecommerce/order.rb +47 -31
- data/app/models/plugins/ecommerce/{product.rb → product_item.rb} +11 -5
- data/app/views/camaleon_cms/html_mailer/order_canceled.html.erb +2 -0
- data/app/views/camaleon_cms/html_mailer/order_confirmed.html.erb +2 -0
- data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +1 -1
- data/app/views/camaleon_cms/html_mailer/order_shipped.html.erb +2 -0
- data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +10 -10
- data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +1 -1
- data/app/views/plugins/ecommerce/admin/orders/form.html.erb +5 -49
- data/app/views/plugins/ecommerce/admin/orders/index.html.erb +140 -80
- data/app/views/plugins/ecommerce/admin/orders/show.html.erb +7 -169
- data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +30 -3
- data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +1 -3
- data/app/views/plugins/ecommerce/admin/prices/index.html.erb +0 -2
- data/app/views/plugins/ecommerce/admin/prices/show.html.erb +0 -2
- data/app/views/plugins/ecommerce/admin/products/index.html.erb +1 -1
- data/app/views/plugins/ecommerce/admin/settings/index.html.erb +0 -1
- data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +1 -1
- data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +46 -57
- data/app/views/plugins/ecommerce/front/checkout/index.html.erb +34 -158
- data/app/views/plugins/ecommerce/front/login.html.erb +67 -0
- data/app/views/plugins/ecommerce/front/orders/index.html.erb +36 -44
- data/app/views/plugins/ecommerce/front/orders/show.html.erb +121 -67
- data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +38 -0
- data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +35 -0
- data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +123 -0
- data/app/views/plugins/ecommerce/partials/checkout/_products_detail.html.erb +49 -0
- data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +93 -0
- data/app/views/post_types/commerce.html.erb +22 -0
- data/app/views/post_types/commerce/_product_widget.html.erb +13 -0
- data/app/views/post_types/commerce/category.html.erb +23 -0
- data/app/views/post_types/commerce/single.html.erb +91 -0
- data/config/custom_models.rb +24 -57
- data/config/locales/en.yml +192 -0
- data/config/locales/es.yml +405 -0
- data/config/routes.rb +26 -16
- data/db/migrate/20160502221327_add_cama_ecommerce_structure_plugin.rb +12 -0
- data/db/migrate/20160504162311_move_featured_attribute_of_products.rb +15 -0
- data/db/migrate/20160527184747_add_new_cart_structure.rb +21 -0
- data/lib/ecommerce/version.rb +1 -1
- metadata +42 -19
- data/app/models/plugins/ecommerce/order_decorator.rb +0 -54
- data/app/views/layouts/plugins/ecommerce/mailer.html.erb +0 -22
- data/app/views/plugins/ecommerce/admin/index.html.erb +0 -2
- data/app/views/plugins/ecommerce/front/_post_list_item.html.erb +0 -18
- data/app/views/plugins/ecommerce/front/index.html.erb +0 -2
- data/app/views/plugins/ecommerce/front/list_products.html.erb +0 -34
- data/app/views/plugins/ecommerce/front/orders/pay_by_bank_transfer.html.erb +0 -67
- data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card.html.erb +0 -131
- data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card_authorize_net.erb +0 -150
- data/app/views/plugins/ecommerce/front/orders/select_payment.html.erb +0 -70
- data/app/views/plugins/ecommerce/front/product.html.erb +0 -105
- data/app/views/plugins/ecommerce/layouts/_ecommerce.html.erb +0 -41
- data/app/views/plugins/ecommerce/partials/_form_address.html.erb +0 -84
- data/app/views/plugins/ecommerce/partials/_table_order_products.html.erb +0 -85
- data/config/locales/translation.yml +0 -371
@@ -0,0 +1,18 @@
|
|
1
|
+
class Plugins::Ecommerce::ProductItemDecorator < Draper::Decorator
|
2
|
+
delegate_all
|
3
|
+
def the_sub_total
|
4
|
+
"#{h.current_site.current_unit}#{sprintf('%.2f', object.sub_total)}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def the_price
|
8
|
+
product.decorate.the_price
|
9
|
+
end
|
10
|
+
|
11
|
+
def the_tax
|
12
|
+
product.decorate.the_tax
|
13
|
+
end
|
14
|
+
|
15
|
+
def price
|
16
|
+
product.decorate.price
|
17
|
+
end
|
18
|
+
end
|
@@ -1,46 +1,109 @@
|
|
1
1
|
module Plugins::Ecommerce::EcommerceEmailHelper
|
2
2
|
include CamaleonCms::EmailHelper
|
3
3
|
|
4
|
-
def
|
4
|
+
def mark_order_like_received(cart, status = 'paid')
|
5
|
+
order = cart.make_paid!(status)
|
6
|
+
|
7
|
+
# send email to buyer
|
8
|
+
commerce_send_order_received_email(order)
|
9
|
+
|
10
|
+
# Send email to products owner
|
11
|
+
commerce_send_order_received_admin_notice(order)
|
12
|
+
|
13
|
+
flash[:notice] = t('plugins.ecommerce.messages.payment_completed', default: "Payment completed successfully")
|
14
|
+
args = {order: order}; hooks_run("commerce_after_payment_completed", args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def commerce_send_order_received_email(order, is_after_bank_confirmation = false)
|
18
|
+
data = _commerce_prepare_send_order_email_data(order)
|
19
|
+
if is_after_bank_confirmation
|
20
|
+
cama_send_email(order.user.email, t('plugin.ecommerce.mail.order_confirmed.subject'), {template_name: 'order_confirmed', extra_data: data[:extra_data], attachs: data[:files]})
|
21
|
+
else
|
22
|
+
data.delete(:files) unless order.paid?
|
23
|
+
cama_send_email(order.user.email, t('plugin.ecommerce.email.order_received.subject'), {template_name: 'order_received', extra_data: data[:extra_data], attachs: data[:files]})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def commerce_send_order_received_admin_notice(order)
|
28
|
+
data = _commerce_prepare_send_order_email_data(order)
|
29
|
+
data[:owners].each do |user|
|
30
|
+
data[:extra_data][:admin] = user
|
31
|
+
cama_send_email(user.email, t('plugin.ecommerce.email.order_received_admin.subject'), {template_name: 'order_received_admin', extra_data: data[:extra_data], attachs: data[:files]})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_recovery_cart_email(order)
|
5
36
|
extra_data = {
|
6
|
-
:fullname => order.
|
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],
|
37
|
+
:fullname => order.user.fullname,
|
13
38
|
:order => order
|
14
39
|
}
|
15
|
-
send_email(order.
|
40
|
+
send_email(order.user.email, t('plugin.ecommerce.email.recovery_cart.subject'), '', nil, [], 'recovery_cart', nil, extra_data)
|
41
|
+
Rails.logger.info "Send recovery to #{order.user.email} with order #{order.slug}"
|
16
42
|
end
|
17
43
|
|
18
|
-
|
19
|
-
|
20
|
-
|
44
|
+
# return translated message
|
45
|
+
def commerce_coupon_error_message(error_code, coupon = nil)
|
46
|
+
case error_code
|
47
|
+
when 'coupon_not_found'
|
48
|
+
t('plugins.ecommerce.messages.coupon_not_found', default: "Coupon not found")
|
49
|
+
when 'coupon_expired'
|
50
|
+
t('plugins.ecommerce.messages.coupon_expired', default: 'Coupon Expired')
|
51
|
+
when 'inactive_coupon'
|
52
|
+
t('plugins.ecommerce.messages.inactive_coupon', default: 'Coupon disabled')
|
53
|
+
when 'times_exceeded'
|
54
|
+
t('plugins.ecommerce.messages.times_exceeded', default: 'Number of times exceeded')
|
55
|
+
when 'required_minimum_price'
|
56
|
+
t('plugins.ecommerce.messages.required_minimum_price', min_amount: coupon.min_cart_total, default: 'Your amount should be great than %{min_amount}')
|
57
|
+
else
|
58
|
+
'Unknown error'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# verify all products and qty, coupons availability
|
63
|
+
# return an array of errors
|
64
|
+
def ecommerce_verify_cart_errors(cart)
|
65
|
+
errors = []
|
66
|
+
# products verification
|
67
|
+
cart.product_items.each do |item|
|
68
|
+
product = item.product.decorate
|
69
|
+
unless product.decrement_qty(item.qty)
|
70
|
+
errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_title, qty: product.the_qty_real, default: 'There is not enough products "%{product}" (%{qty})')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# coupon verification
|
75
|
+
res = cart.discount_for(cart.coupon)
|
76
|
+
if res[:error].present?
|
77
|
+
errors << commerce_coupon_error_message(res[:error], res[:coupon])
|
78
|
+
cart.update_column(:coupon, '')
|
79
|
+
end
|
80
|
+
|
81
|
+
args = {cart: cart, errors: errors}; hooks_run("commerce_on_error_verifications", args)
|
82
|
+
errors
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def _commerce_prepare_send_order_email_data(order)
|
87
|
+
data = {}
|
88
|
+
data[:extra_data] = {
|
89
|
+
:fullname => order.user.fullname,
|
21
90
|
:order_slug => order.slug,
|
22
91
|
:order_url => plugins_ecommerce_order_show_url(order: order.slug),
|
23
92
|
:billing_information => order.get_meta('billing_address'),
|
24
93
|
:shipping_address => order.get_meta('shipping_address'),
|
25
|
-
:subtotal => order.
|
26
|
-
:total_cost => order.
|
94
|
+
:subtotal => order.cache_the_sub_total,
|
95
|
+
:total_cost => order.cache_the_total,
|
27
96
|
:order => order
|
28
97
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
98
|
+
files = []
|
99
|
+
owners = []
|
100
|
+
order.products.each do |product|
|
101
|
+
files += product.get_fields('ecommerce_files').map{|f| CamaleonCmsLocalUploader::private_file_path(f, current_site) }
|
102
|
+
owners << product.owner if product.owner.present?
|
34
103
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
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}"
|
104
|
+
data[:owners] = owners.uniq
|
105
|
+
data[:files] = files.uniq
|
106
|
+
data
|
44
107
|
end
|
45
108
|
|
46
109
|
end
|
@@ -10,36 +10,21 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
10
10
|
include Plugins::Ecommerce::EcommerceEmailHelper
|
11
11
|
|
12
12
|
def ecommerce_on_render_post(d)
|
13
|
-
|
14
|
-
ecommerce_add_assets_in_front
|
15
|
-
d[:render] = 'plugins/ecommerce/front/product'
|
16
|
-
end
|
17
|
-
d
|
13
|
+
|
18
14
|
end
|
19
15
|
|
20
16
|
def ecommerce_on_render_post_type(d)
|
21
|
-
|
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
|
17
|
+
|
28
18
|
end
|
29
19
|
|
30
20
|
def ecommerce_admin_list_post(d)
|
31
|
-
|
32
|
-
ecommerce_add_assets_in_front
|
33
|
-
d[:render] = 'plugins/ecommerce/admin/products/index'
|
34
|
-
end
|
35
|
-
d
|
21
|
+
|
36
22
|
end
|
37
23
|
|
38
24
|
def ecommerce_form_post(d)
|
39
25
|
if d[:post_type].slug == 'commerce'
|
40
26
|
append_asset_libraries({ecommerce: {css: [], js: [plugin_gem_asset('fix_form')]}})
|
41
27
|
end
|
42
|
-
d
|
43
28
|
end
|
44
29
|
|
45
30
|
def ecommerce_front_before_load
|
@@ -53,105 +38,31 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
53
38
|
if pt.present?
|
54
39
|
items_i = []
|
55
40
|
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
|
41
|
+
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
|
57
42
|
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
|
43
|
+
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
|
59
44
|
end
|
60
45
|
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
|
46
|
+
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
|
62
47
|
end
|
63
48
|
if can? :posts, pt
|
64
|
-
items_i << {icon: "reorder", title: "<span>#{t('plugin.ecommerce.orders')} <small class='label label-primary'>#{current_site.orders.
|
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}
|
49
|
+
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}
|
50
|
+
items_i << {icon: "money", title: t('plugin.ecommerce.tax_rates', default: 'Tax rates'), url: admin_plugins_ecommerce_tax_rates_path}
|
51
|
+
items_i << {icon: "taxi", title: t('plugin.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path}
|
52
|
+
items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
|
53
|
+
items_i << {icon: "tag", title: t('plugin.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
|
54
|
+
items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
|
70
55
|
end
|
71
56
|
|
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?
|
57
|
+
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?
|
73
58
|
end
|
74
59
|
|
75
60
|
# add assets admin
|
76
|
-
append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: [
|
61
|
+
append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: []}})
|
77
62
|
|
78
63
|
end
|
79
64
|
|
80
65
|
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
66
|
|
156
67
|
end
|
157
68
|
|
@@ -167,22 +78,12 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
167
78
|
# plugin: plugin model
|
168
79
|
def ecommerce_on_active(plugin)
|
169
80
|
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
81
|
end
|
181
82
|
|
182
83
|
# here all actions on going to inactive
|
183
84
|
# plugin: plugin model
|
184
85
|
def ecommerce_on_inactive(plugin)
|
185
|
-
|
86
|
+
current_site.post_types.hidden_menu.where(slug: "commerce").first.destroy
|
186
87
|
end
|
187
88
|
|
188
89
|
def get_commerce_post_type
|
@@ -190,51 +91,44 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
190
91
|
unless @ecommerce.present?
|
191
92
|
@ecommerce = current_site.post_types.hidden_menu.new(slug: "commerce", name: "Product")
|
192
93
|
if @ecommerce.save
|
193
|
-
@ecommerce.
|
94
|
+
@ecommerce.set_options({
|
194
95
|
has_category: true,
|
195
96
|
has_tags: true,
|
196
97
|
not_deleted: true,
|
197
98
|
has_summary: true,
|
198
99
|
has_content: true,
|
199
|
-
has_comments:
|
100
|
+
has_comments: true,
|
200
101
|
has_picture: true,
|
201
102
|
has_template: false,
|
103
|
+
has_featured: true,
|
104
|
+
cama_post_decorator_class: 'Plugins::Ecommerce::ProductDecorator'
|
202
105
|
})
|
203
106
|
@ecommerce.categories.create({name: 'Uncategorized', slug: 'Uncategorized'.parameterize})
|
204
107
|
end
|
205
|
-
|
108
|
+
@ecommerce.set_options({posts_feature_image_label: 'plugin.ecommerce.product.image_label',
|
109
|
+
posts_feature_image_label_default: 'Product Image'})
|
206
110
|
end
|
207
|
-
|
208
111
|
end
|
209
112
|
|
210
113
|
def ecommerce_add_assets_in_front
|
211
114
|
append_asset_libraries({ecommerce_front: {css: [plugin_gem_asset('front')], js: [plugin_gem_asset('cart')]}})
|
212
115
|
end
|
213
116
|
|
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
117
|
private
|
223
118
|
def generate_custom_field_products
|
224
119
|
get_commerce_post_type
|
225
120
|
unless @ecommerce.get_field_groups.where(slug: "plugin_ecommerce_product_data").present?
|
226
121
|
@ecommerce.get_field_groups.destroy_all
|
227
122
|
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" => "
|
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" => "
|
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.
|
123
|
+
group.add_manual_field({"name" => "t('plugin.ecommerce.product.sku', default: 'Sku')", "slug" => "ecommerce_sku"}, {field_key: "text_box", required: true, label_eval: true})
|
124
|
+
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})
|
125
|
+
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})
|
126
|
+
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})
|
127
|
+
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})
|
128
|
+
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})
|
129
|
+
group.add_manual_field({"name" => "t('plugin.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true})
|
130
|
+
group.add_manual_field({"name" => "t('plugin.ecommerce.product.qty', default: 'Quantity')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true, label_eval: true})
|
131
|
+
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})
|
237
132
|
end
|
238
133
|
end
|
239
|
-
|
240
134
|
end
|
@@ -1,22 +1,15 @@
|
|
1
1
|
module Plugins::Ecommerce::EcommercePaymentHelper
|
2
2
|
include Plugins::Ecommerce::EcommerceHelper
|
3
3
|
|
4
|
-
def payment_pay_by_credit_card_authorize_net(order)
|
5
|
-
payment = order.get_meta("payment")
|
4
|
+
def payment_pay_by_credit_card_authorize_net(order, payment_method)
|
6
5
|
billing_address = order.get_meta("billing_address")
|
7
6
|
details = order.get_meta("details")
|
8
|
-
|
9
|
-
|
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 = {
|
7
|
+
amount = commerce_to_cents(order.total_amount)
|
8
|
+
payment_params = {
|
16
9
|
:order_id => order.slug,
|
17
10
|
:currency => current_site.currency_code,
|
18
|
-
:email =>
|
19
|
-
:billing_address => {:name => "#{
|
11
|
+
:email => order.user.email,
|
12
|
+
:billing_address => {:name => "#{order.user.fullname}",
|
20
13
|
:address1 => billing_address[:address1],
|
21
14
|
:address2 => billing_address[:address2],
|
22
15
|
:city => billing_address[:city],
|
@@ -43,25 +36,26 @@ module Plugins::Ecommerce::EcommercePaymentHelper
|
|
43
36
|
:year => "20#{params[:expYear]}",
|
44
37
|
:verification_value => params[:cvCode]
|
45
38
|
)
|
46
|
-
|
47
39
|
if credit_card.validate.empty?
|
48
40
|
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(authorize_net_options)
|
49
|
-
response = gateway.purchase(amount, credit_card,
|
41
|
+
response = gateway.purchase(amount, credit_card, payment_params)
|
50
42
|
if response.success?
|
51
|
-
order.set_meta('pay_authorize_net',
|
52
|
-
|
53
|
-
return {success: 'Paid Correct'}
|
43
|
+
order.set_meta('pay_authorize_net', payment_params)
|
44
|
+
return {}
|
54
45
|
else
|
55
46
|
return {error: response.message}
|
56
47
|
end
|
57
48
|
else
|
58
|
-
return {error:
|
49
|
+
return {error: credit_card.validate.map{|k, v| "#{k}: #{v.join(', ')}"}.join('<br>')}
|
59
50
|
end
|
60
|
-
|
61
51
|
end
|
62
52
|
|
63
|
-
def
|
53
|
+
def commerce_to_cents(money)
|
64
54
|
(money*100).round
|
65
55
|
end
|
66
56
|
|
57
|
+
def commerce_current_currency
|
58
|
+
current_site.get_meta("_setting_ecommerce", {})[:current_unit] || 'USD'
|
59
|
+
end
|
60
|
+
|
67
61
|
end
|