camaleon_ecommerce 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/images/plugins/ecommerce/switch.png +0 -0
- data/app/assets/javascripts/plugins/ecommerce/admin_product.js.coffee +1 -1
- data/app/assets/javascripts/plugins/ecommerce/admin_settings.js +16 -0
- data/app/assets/javascripts/plugins/ecommerce/cart.js +1 -0
- data/app/assets/javascripts/plugins/ecommerce/jquery.multi-select.js +535 -0
- data/app/assets/stylesheets/plugins/ecommerce/multi-select.css.scss +94 -0
- data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +37 -20
- data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +2 -2
- data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +16 -15
- data/app/decorators/plugins/ecommerce/cart_decorator.rb +19 -0
- data/app/decorators/plugins/ecommerce/order_decorator.rb +70 -0
- data/app/decorators/plugins/ecommerce/product_decorator.rb +16 -9
- data/app/decorators/plugins/ecommerce/product_item_decorator.rb +5 -1
- data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +60 -59
- data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +5 -10
- data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +12 -3
- data/app/models/plugins/ecommerce/cart.rb +3 -25
- data/app/models/plugins/ecommerce/order.rb +0 -21
- data/app/models/plugins/ecommerce/payment_method.rb +4 -0
- data/app/models/plugins/ecommerce/shipping_method.rb +4 -1
- data/app/services/plugins/ecommerce/cart_service.rb +0 -9
- data/app/views/plugins/ecommerce/admin/orders/index.html.erb +47 -51
- data/app/views/plugins/ecommerce/admin/orders/show.html.erb +1 -1
- data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +2 -6
- data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +4 -6
- data/app/views/plugins/ecommerce/admin/settings/index.html.erb +60 -20
- data/app/views/plugins/ecommerce/admin/shipping_methods/form.html.erb +1 -5
- data/app/views/plugins/ecommerce/admin/shipping_methods/index.html.erb +2 -4
- data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +2 -2
- data/app/views/plugins/ecommerce/front/checkout/index.html.erb +1 -1
- data/app/views/plugins/ecommerce/front/login.html.erb +1 -1
- data/app/views/plugins/ecommerce/front/orders/index.html.erb +2 -2
- data/app/views/plugins/ecommerce/front/orders/show.html.erb +13 -14
- data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +1 -1
- data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +116 -110
- data/app/views/plugins/ecommerce/partials/checkout/_products_detail.html.erb +5 -2
- data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +0 -1
- data/app/views/plugins/ecommerce/partials/email/_billing_address.html.erb +11 -0
- data/app/views/plugins/ecommerce/partials/email/_product_table.html.erb +46 -0
- data/app/views/plugins/ecommerce/partials/email/_shipping_address.html.erb +11 -0
- data/app/views/{plugins/ecommerce/partials → post_types/commerce}/_cart_widget.html.erb +0 -0
- data/app/views/post_types/commerce/_product_info.html.erb +30 -32
- data/app/views/post_types/commerce/single.html.erb +9 -13
- data/config/camaleon_plugin.json +2 -1
- data/config/custom_models.rb +43 -0
- data/config/locales/en.yml +0 -1
- data/config/locales/es.yml +69 -7
- data/config/routes.rb +1 -0
- data/db/migrate/20161213222142_add_invoice_number.rb +6 -0
- data/db/migrate/20161214224919_remove_ecommerce_stock_field.rb +7 -0
- data/lib/ecommerce/engine.rb +4 -2
- data/lib/ecommerce/version.rb +1 -1
- metadata +58 -15
- data/app/assets/javascripts/plugins/ecommerce/jquery.creditCardValidator.js +0 -208
- data/app/services/plugins/ecommerce/order_service.rb +0 -26
- data/app/views/camaleon_cms/html_mailer/order_canceled.html.erb +0 -2
- data/app/views/camaleon_cms/html_mailer/order_confirmed.html.erb +0 -2
- data/app/views/camaleon_cms/html_mailer/order_received.html.erb +0 -5
- data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +0 -3
- data/app/views/camaleon_cms/html_mailer/order_shipped.html.erb +0 -2
- data/app/views/camaleon_cms/html_mailer/recovery_cart.html.erb +0 -4
@@ -4,6 +4,10 @@ class Plugins::Ecommerce::ProductItemDecorator < Draper::Decorator
|
|
4
4
|
get_product.the_variation_title(object.variation_id)
|
5
5
|
end
|
6
6
|
|
7
|
+
def the_url
|
8
|
+
get_product.the_url(variation_id: object.variation_id)
|
9
|
+
end
|
10
|
+
|
7
11
|
def the_sub_total
|
8
12
|
h.e_parse_price(object.sub_total)
|
9
13
|
end
|
@@ -43,6 +47,6 @@ class Plugins::Ecommerce::ProductItemDecorator < Draper::Decorator
|
|
43
47
|
# verify if the quantity of the cart item is avilable
|
44
48
|
# return true if quantity is available
|
45
49
|
def is_valid_qty?
|
46
|
-
(get_product.
|
50
|
+
(get_product.the_qty(object.variation_id) - object.qty).to_i >= 0
|
47
51
|
end
|
48
52
|
end
|
@@ -1,49 +1,17 @@
|
|
1
1
|
module Plugins::Ecommerce::EcommerceEmailHelper
|
2
2
|
include CamaleonCms::EmailHelper
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
commerce_send_order_received_admin_notice(order)
|
13
|
-
|
14
|
-
flash[:notice] = t('plugins.ecommerce.messages.payment_completed', default: "Payment completed successfully")
|
15
|
-
args = {order: order}; hooks_run("commerce_after_payment_completed", args)
|
16
|
-
|
4
|
+
# mark current cart into order with specific status
|
5
|
+
def commerce_mark_cart_received(cart, status = 'paid')
|
6
|
+
args = {cart: cart, status: status}; hooks_run('commerce_before_payment_completed', args)
|
7
|
+
order = cart.convert_to_order(status)
|
8
|
+
order.set_meta('locale', I18n.locale)
|
9
|
+
commerce_order_send_mail(order)
|
10
|
+
flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.payment_completed', default: "Payment completed successfully")
|
11
|
+
args = {order: order, status: status}; hooks_run("commerce_after_payment_completed", args)
|
17
12
|
order
|
18
13
|
end
|
19
14
|
|
20
|
-
def commerce_send_order_received_email(order, is_after_bank_confirmation = false)
|
21
|
-
data = _commerce_prepare_send_order_email_data(order)
|
22
|
-
if is_after_bank_confirmation
|
23
|
-
cama_send_email(order.user.email, t('plugins.ecommerce.mail.order_confirmed.subject'), {template_name: 'order_confirmed', extra_data: data[:extra_data], attachs: data[:files]})
|
24
|
-
else
|
25
|
-
data.delete(:files) unless order.paid?
|
26
|
-
cama_send_email(order.user.email, t('plugins.ecommerce.email.order_received.subject'), {template_name: 'order_received', extra_data: data[:extra_data], attachs: data[:files]})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def commerce_send_order_received_admin_notice(order)
|
31
|
-
data = _commerce_prepare_send_order_email_data(order)
|
32
|
-
data[:owners].each do |user|
|
33
|
-
data[:extra_data][:admin] = user
|
34
|
-
cama_send_email(user.email, t('plugins.ecommerce.email.order_received_admin.subject'), {template_name: 'order_received_admin', extra_data: data[:extra_data], attachs: data[:files]})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def send_recovery_cart_email(order)
|
39
|
-
extra_data = {
|
40
|
-
:fullname => order.user.fullname,
|
41
|
-
:order => order
|
42
|
-
}
|
43
|
-
send_email(order.user.email, t('plugins.ecommerce.email.recovery_cart.subject'), '', nil, [], 'recovery_cart', nil, extra_data)
|
44
|
-
Rails.logger.info "Send recovery to #{order.user.email} with order #{order.slug}"
|
45
|
-
end
|
46
|
-
|
47
15
|
# return translated message
|
48
16
|
def commerce_coupon_error_message(error_code, coupon = nil)
|
49
17
|
case error_code
|
@@ -70,7 +38,7 @@ module Plugins::Ecommerce::EcommerceEmailHelper
|
|
70
38
|
cart.product_items.decorate.each do |item|
|
71
39
|
unless item.is_valid_qty?
|
72
40
|
product = item.product.decorate
|
73
|
-
errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.
|
41
|
+
errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(item.variation_id), qty: product.the_qty(item.variation_id), default: 'There is not enough products "%{product}" (Available %{qty})')
|
74
42
|
end
|
75
43
|
end
|
76
44
|
|
@@ -85,24 +53,57 @@ module Plugins::Ecommerce::EcommerceEmailHelper
|
|
85
53
|
errors
|
86
54
|
end
|
87
55
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
56
|
+
# send the email to the user for specific events or status
|
57
|
+
# event: (String) email_order_received | email_order_shipped | email_order_cancelled | email_order_confirmed_bank | email_order_confirmed_on_delivery
|
58
|
+
def commerce_order_send_mail(order, event = 'email_order_received')
|
59
|
+
bk_l = I18n.locale
|
60
|
+
I18n.locale = order.get_meta('locale', 'en').to_s
|
61
|
+
subject, content_key = case event
|
62
|
+
when 'email_order_received'
|
63
|
+
[I18n.t('plugins.ecommerce.email.order_received_label', default: 'Order Received'), 'email_order_received']
|
64
|
+
when 'email_order_confirmed'
|
65
|
+
[I18n.t('plugins.ecommerce.email.order_confirmed_label', default: 'Order Confirmed'), 'email_order_confirmed']
|
66
|
+
when 'email_order_confirmed_bank'
|
67
|
+
[I18n.t('plugins.ecommerce.email.order_bank_confirmed_label', default: 'Order Bank Confirmed'), 'email_order_confirmed']
|
68
|
+
when 'email_order_confirmed_on_delivery'
|
69
|
+
[I18n.t('plugins.ecommerce.email.order_on_delivery_confirmed_label', default: 'Order on Delivery Confirmed'), 'email_order_confirmed']
|
70
|
+
when 'email_order_shipped'
|
71
|
+
[I18n.t('plugins.ecommerce.email.order_shipped_label', default: 'Order Shipped'), 'email_order_shipped']
|
72
|
+
when 'email_order_cancelled'
|
73
|
+
[I18n.t('plugins.ecommerce.email.order_cancelled_label', default: 'Order Cancelled'), 'email_order_cancelled']
|
74
|
+
end
|
75
|
+
data = {template_name: nil, content: current_site.e_email_for(content_key).to_s.translate, files: []}
|
76
|
+
replaces = {
|
77
|
+
order_table: render_to_string(partial: 'plugins/ecommerce/partials/email/product_table', locals: {order: order}),
|
78
|
+
shipping_info: render_to_string(partial: 'plugins/ecommerce/partials/email/shipping_address', locals: {order: order}),
|
79
|
+
billing_info: render_to_string(partial: 'plugins/ecommerce/partials/email/billing_address', locals: {order: order}),
|
80
|
+
cancelled_description: order.get_meta('description').to_s,
|
81
|
+
root_url: current_site.the_url,
|
82
|
+
date: order.the_created_at,
|
83
|
+
current_date: l(Date.today, format: :long),
|
84
|
+
number: order.slug,
|
85
|
+
name: order.user.first_name,
|
86
|
+
full_name: order.user.fullname,
|
87
|
+
tracking_url: order.the_url_tracking.to_s,
|
88
|
+
shipping_name: order.the_shipping_method.to_s,
|
89
|
+
invoice_number: order.invoice_number.to_s,
|
90
|
+
status: order.the_status,
|
91
|
+
url: order.the_url
|
101
92
|
}
|
102
|
-
|
103
|
-
data[:owners] = order_service.product_owners
|
104
|
-
data[:files] = order_service.product_files
|
105
|
-
data
|
106
|
-
end
|
93
|
+
args={order: order, replaces: replaces}; hooks_run('commerce_custom_email_replacements', args) # permit to add custom replacements
|
107
94
|
|
95
|
+
if order.status == 'paid'
|
96
|
+
order.products.each do |product|
|
97
|
+
data[:files] += product.get_fields('ecommerce_files').map{|f| CamaleonCmsLocalUploader::private_file_path(f, current_site) }
|
98
|
+
end
|
99
|
+
data[:files] = data[:files].uniq
|
100
|
+
pdf_path = order.the_invoice_path
|
101
|
+
data[:ecommerce_invoice] = {pdf_path: pdf_path, html: current_site.e_email_for('email_order_invoice').to_s.translate.to_s.cama_replace_codes(replaces, format_code = '{')}
|
102
|
+
data[:files] << pdf_path
|
103
|
+
order.update_column(:invoice_path, pdf_path.split('/').last)
|
104
|
+
end
|
105
|
+
data[:content] = data[:content].to_s.cama_replace_codes(replaces, format_code = '{')
|
106
|
+
cama_send_email(order.user.email, subject, data)
|
107
|
+
I18n.locale = bk_l
|
108
|
+
end
|
108
109
|
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
module Plugins::Ecommerce::EcommerceFunctionsHelper
|
3
|
-
# return the settings for ecommerce (Hash)
|
4
|
-
def ecommerce_get_settings
|
5
|
-
current_site.get_meta("_setting_ecommerce", {})
|
6
|
-
end
|
7
|
-
|
8
3
|
# return the visitor key which is used to relate the cart until login/register
|
9
4
|
def ecommerce_get_visitor_key
|
10
5
|
cookies[:e_cart_id] ||= cama_get_session_id unless cama_current_user.present?
|
@@ -17,12 +12,12 @@ module Plugins::Ecommerce::EcommerceFunctionsHelper
|
|
17
12
|
|
18
13
|
# return all shipping country codes supported for shipping
|
19
14
|
def e_shipping_countries
|
20
|
-
|
15
|
+
current_site.e_settings[:shipping_countries] || ISO3166::Country.codes
|
21
16
|
end
|
22
17
|
|
23
18
|
# return (Array) all the currencies for visitors
|
24
19
|
def e_visitor_unit_currencies
|
25
|
-
|
20
|
+
current_site.e_settings[:visitor_unit_currencies] || ['USD']
|
26
21
|
end
|
27
22
|
|
28
23
|
# draw a select dropdown with all frontend currencies and actions to change current currency
|
@@ -61,13 +56,13 @@ module Plugins::Ecommerce::EcommerceFunctionsHelper
|
|
61
56
|
|
62
57
|
# return the currency defined for admin panel
|
63
58
|
def e_system_currency
|
64
|
-
|
59
|
+
current_site.e_settings[:current_unit] || 'USD'
|
65
60
|
end
|
66
61
|
|
67
62
|
# render price formatted of a product with current currency
|
68
63
|
def e_parse_price(price)
|
69
64
|
currency = cama_is_admin_request? ? e_system_currency : e_current_visitor_currency
|
70
|
-
args = {currency: currency, price: price, data:
|
65
|
+
args = {currency: currency, price: price, data: number_to_currency(e_parse_to_current_currency(price), unit: currency)}; hooks_run('ecommerce_parse_price', args) # permit to customize price format
|
71
66
|
args[:data]
|
72
67
|
end
|
73
68
|
|
@@ -275,7 +270,7 @@ module Plugins::Ecommerce::EcommerceFunctionsHelper
|
|
275
270
|
|
276
271
|
def ecommerce_draw_breadcrumb
|
277
272
|
res = '<ol class="breadcrumb" style="margin: 0;">'
|
278
|
-
@ecommerce_breadcrumb.each_with_index do |m, index|
|
273
|
+
(@ecommerce_breadcrumb || []).each_with_index do |m, index|
|
279
274
|
if m[1].present?
|
280
275
|
res << "<li class='#{"active" if @ecommerce_breadcrumb.size == index+1}'><a href='#{m[1]}'>#{m[0]}</a></li>"
|
281
276
|
else
|
@@ -36,8 +36,9 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
36
36
|
items_i << {icon: "taxi", title: t('plugins.ecommerce.shipping_methods', default: 'Shipping Methods'), url: admin_plugins_ecommerce_shipping_methods_path}
|
37
37
|
items_i << {icon: "credit-card", title: t('plugins.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
|
38
38
|
items_i << {icon: "tag", title: t('plugins.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
|
39
|
-
items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
|
40
39
|
items_i << {icon: "cubes", title: t('plugins.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path}
|
40
|
+
items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
|
41
|
+
hooks_run('plugin_ecommerce_after_menus', items_i) # permit to add menus for ecommerce plugin
|
41
42
|
end
|
42
43
|
|
43
44
|
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?
|
@@ -47,6 +48,13 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
47
48
|
def ecommerce_app_before_load
|
48
49
|
end
|
49
50
|
|
51
|
+
# permit to generate invoice PDF by background just before delivery email
|
52
|
+
def ecommerce_admin_before_email_send(args)
|
53
|
+
if args[:ecommerce_invoice].present?
|
54
|
+
File.open(args[:ecommerce_invoice][:pdf_path], 'wb'){|file| file << WickedPdf.new.pdf_from_string(args[:ecommerce_invoice][:html], encoding: 'utf8') }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
50
58
|
# here all actions on plugin destroying
|
51
59
|
# plugin: plugin model
|
52
60
|
def ecommerce_on_destroy(plugin)
|
@@ -74,7 +82,7 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
74
82
|
# verify no deletable variances
|
75
83
|
no_deletable_variances = false
|
76
84
|
args[:post].product_variations.where.not(id: params[:product_variation].keys).each{|prod| no_deletable_variances = true unless prod.destroy }
|
77
|
-
flash[:warning] +=
|
85
|
+
flash[:warning] += t('plugins.ecommerce.variations.not_deletable_product_variations', default: 'Some Product variations can not be deleted.') if no_deletable_variances
|
78
86
|
|
79
87
|
params[:product_variation].each do |p_key, p_var|
|
80
88
|
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(',')}
|
@@ -124,7 +132,8 @@ module Plugins::Ecommerce::EcommerceHelper
|
|
124
132
|
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
133
|
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
134
|
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
|
-
|
135
|
+
# changed to validate using the quantity of the inventory
|
136
|
+
# group.add_manual_field({"name" => "t('plugins.ecommerce.product.stock', default: 'Stock')", "slug" => "ecommerce_stock"}, {field_key: "checkbox", default: true, label_eval: true})
|
128
137
|
group.add_manual_field({"name" => "t('plugins.ecommerce.product.qty', default: 'Quantity')", "slug" => "ecommerce_qty"}, {field_key: "numeric", required: true, label_eval: true})
|
129
138
|
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})
|
130
139
|
end
|
@@ -8,6 +8,7 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
8
8
|
|
9
9
|
belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :site_id
|
10
10
|
belongs_to :user, :class_name => "CamaleonCms::User", foreign_key: :user_id
|
11
|
+
belongs_to :shipping_method, class_name: 'Plugins::Ecommerce::ShippingMethod'
|
11
12
|
scope :active_cart, ->{ where("#{Plugins::Ecommerce::Cart.table_name}.updated_at >= ?", 24.hours.ago) }
|
12
13
|
|
13
14
|
after_create :generate_slug
|
@@ -16,7 +17,6 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
16
17
|
# paid => paid by some method
|
17
18
|
# canceled => canceled order
|
18
19
|
# shipped => shipped status
|
19
|
-
# accepted => received status
|
20
20
|
|
21
21
|
def payment_method
|
22
22
|
@_cama_cache_payment_method ||= Plugins::Ecommerce::PaymentMethod.find_by_id(get_meta('payment_method_id', self.payment_method_id))
|
@@ -32,11 +32,6 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
32
32
|
pi
|
33
33
|
end
|
34
34
|
|
35
|
-
# return the product titles in array format
|
36
|
-
def products_title
|
37
|
-
product_items.map{|i| p=i.product.decorate; p.the_variation_title(i.variation_id) }.join(', ')
|
38
|
-
end
|
39
|
-
|
40
35
|
def items_total
|
41
36
|
product_items.map{|item| item.qty }.inject{|sum,x| sum + x } || 0
|
42
37
|
end
|
@@ -79,8 +74,8 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
79
74
|
res[:discount] = opts[:amount].to_f
|
80
75
|
end
|
81
76
|
end
|
82
|
-
else
|
83
|
-
|
77
|
+
# else
|
78
|
+
# res[:error] = 'coupon_not_found'
|
84
79
|
end
|
85
80
|
res
|
86
81
|
end
|
@@ -94,16 +89,6 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
94
89
|
end
|
95
90
|
end
|
96
91
|
|
97
|
-
# convert into order current cart
|
98
|
-
def convert_to_order
|
99
|
-
self.update_columns(kind: 'order', created_at: Time.current)
|
100
|
-
site.orders.find(self.id)
|
101
|
-
end
|
102
|
-
|
103
|
-
def shipping_method
|
104
|
-
Plugins::Ecommerce::ShippingMethod.find_by_id(self.shipping_method_id)
|
105
|
-
end
|
106
|
-
|
107
92
|
# return the total price without coupon price
|
108
93
|
def total_to_pay_without_discounts
|
109
94
|
sub_total + tax_total + total_shipping
|
@@ -180,13 +165,6 @@ class Plugins::Ecommerce::Cart < ActiveRecord::Base
|
|
180
165
|
)
|
181
166
|
end
|
182
167
|
|
183
|
-
def mark_paid(status = 'paid')
|
184
|
-
self.update_columns(
|
185
|
-
status: status,
|
186
|
-
paid_at: Time.current,
|
187
|
-
)
|
188
|
-
end
|
189
|
-
|
190
168
|
# return the gateway for paypal transactions
|
191
169
|
def paypal_gateway
|
192
170
|
ActiveMerchant::Billing::Base.mode = payment_method.options[:paypal_sandbox].to_s.to_bool ? :test : :production
|
@@ -18,27 +18,14 @@ class Plugins::Ecommerce::Order < Plugins::Ecommerce::Cart
|
|
18
18
|
status == 'accepted'
|
19
19
|
end
|
20
20
|
|
21
|
-
def accepted!
|
22
|
-
update_columns({status: 'accepted', accepted_at: Time.current})
|
23
|
-
end
|
24
|
-
|
25
21
|
def shipped?
|
26
22
|
status == 'shipped'
|
27
23
|
end
|
28
24
|
|
29
|
-
def shipped!(code)
|
30
|
-
update_columns({status: 'shipped', shipped_at: Time.current})
|
31
|
-
set_meta('consignment_number', code)
|
32
|
-
end
|
33
|
-
|
34
25
|
def canceled?
|
35
26
|
status == 'canceled'
|
36
27
|
end
|
37
28
|
|
38
|
-
def canceled!
|
39
|
-
update_columns({status: 'canceled', shipped_at: Time.current})
|
40
|
-
end
|
41
|
-
|
42
29
|
def received?
|
43
30
|
status == 'received'
|
44
31
|
end
|
@@ -51,14 +38,6 @@ class Plugins::Ecommerce::Order < Plugins::Ecommerce::Cart
|
|
51
38
|
status == 'on_delivery'
|
52
39
|
end
|
53
40
|
|
54
|
-
def bank_confirmed!
|
55
|
-
update_columns({status: 'paid', updated_at: Time.current})
|
56
|
-
end
|
57
|
-
|
58
|
-
def on_delivery_confirmed!
|
59
|
-
update_columns({status: 'paid', updated_at: Time.current})
|
60
|
-
end
|
61
|
-
|
62
41
|
def payment_data
|
63
42
|
get_meta('payment_data', {})
|
64
43
|
end
|
@@ -4,6 +4,10 @@ class Plugins::Ecommerce::PaymentMethod < CamaleonCms::TermTaxonomy
|
|
4
4
|
|
5
5
|
scope :actives, -> {where(status: '1')}
|
6
6
|
|
7
|
+
def skip_slug_validation?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
7
11
|
def method_text
|
8
12
|
if options[:type] == 'paypal'
|
9
13
|
I18n.t 'plugins.ecommerce.by_paypal', default: 'Paypal'
|
@@ -1,9 +1,12 @@
|
|
1
1
|
class Plugins::Ecommerce::ShippingMethod < CamaleonCms::TermTaxonomy
|
2
2
|
default_scope { where(taxonomy: :ecommerce_shipping_method) }
|
3
3
|
belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
|
4
|
-
|
5
4
|
scope :actives, -> {where(status: '1')}
|
6
5
|
|
6
|
+
def skip_slug_validation?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
7
10
|
def get_price_from_weight(weight = 0)
|
8
11
|
price_total = 0
|
9
12
|
prices = get_meta("prices")
|
@@ -124,13 +124,4 @@ class Plugins::Ecommerce::CartService
|
|
124
124
|
{error: e.message}
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
128
|
-
def convert_to_order(status = 'paid')
|
129
|
-
Plugins::Ecommerce::Cart.transaction do
|
130
|
-
cart.prepare_to_pay
|
131
|
-
cart.update_amounts
|
132
|
-
cart.mark_paid(status)
|
133
|
-
cart.convert_to_order
|
134
|
-
end
|
135
|
-
end
|
136
127
|
end
|
@@ -4,36 +4,39 @@
|
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div class="panel-body">
|
7
|
-
<%=
|
8
|
-
<div class="
|
9
|
-
|
10
|
-
|
11
|
-
<button type="button" title="<%= t('plugins.ecommerce.advanced_search', default: 'Advanced Search') %>" class="btn btn-default" id="ecommerce_adv_search_btn"><span class="caret"></span></button>
|
12
|
-
<button type="submit" class="btn btn-primary"><span class="fa fa-search"></span></button>
|
13
|
-
</div>
|
7
|
+
<%= search_form_for @q, url: url_for(action: :index), class: 'row' do |f| %>
|
8
|
+
<div class="col-md-3">
|
9
|
+
<%= f.label :user_email_or_slug_or_coupon_cont, t('.search_field', default: 'Email or Number or Coupon') %>
|
10
|
+
<%= f.search_field :user_email_or_slug_or_coupon_cont, class: 'form-control' %>
|
14
11
|
</div>
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
<
|
20
|
-
<input class="form-control" type="text" name="c" value="<%= params[:c] %>"/>
|
21
|
-
</div>
|
22
|
-
<div class="form-group">
|
23
|
-
<label for="contain"><%= t('plugins.ecommerce.e_mail_address') %></label>
|
24
|
-
<input class="form-control" type="email" name="e" value="<%= params[:e] %>"/>
|
12
|
+
<div class="col-md-2">
|
13
|
+
<%= f.label :created_at_gteq, t('.created_after', default: 'Created After') %>
|
14
|
+
<div class='input-group date date_field_w'>
|
15
|
+
<%= f.text_field :created_at_gteq, class: 'form-control ' %>
|
16
|
+
<span class='add-on input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>
|
25
17
|
</div>
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
<
|
32
|
-
<%= select_tag "s", options_for_select([[""], [t('plugins.ecommerce.select.accepted'), "accepted"], [cama_t('plugins.ecommerce.select.shipped'), "shipped"], [cama_t('plugins.ecommerce.select.canceled'), "canceled"], [cama_t('plugins.ecommerce.select.paid'), "paid"], [cama_t('plugins.ecommerce.select.pending'), "on_delivery|bank_pending"]], params[:s]), class: 'form-control' %>
|
18
|
+
</div>
|
19
|
+
<div class="col-md-2">
|
20
|
+
<%= f.label :created_at_lteq, t('.created_before', default: 'Created Before') %>
|
21
|
+
<div class='input-group date date_field_w'>
|
22
|
+
<%= f.text_field :created_at_lteq, class: 'form-control ' %>
|
23
|
+
<span class='add-on input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>
|
33
24
|
</div>
|
34
|
-
|
35
|
-
|
36
|
-
|
25
|
+
</div>
|
26
|
+
<div class="col-md-2">
|
27
|
+
<%= f.label :status_eq, t('.search_status', default: 'Status') %>
|
28
|
+
<%= f.select :status_eq, [[t('plugins.ecommerce.select.shipped', default: 'Shipped'), "shipped"], [t('plugins.ecommerce.select.canceled', default: 'Cancelled'), "canceled"], [t('plugins.ecommerce.select.paid', default: 'Paid'), "paid"], [t('plugins.ecommerce.messages.order_status.bank_pending', default: 'Bank Pending'), "bank_pending"], [t('plugins.ecommerce.by_on_delivery', default: 'Payment no Delivery'), "on_delivery"]], {include_blank: true}, class: 'form-control' %>
|
29
|
+
</div>
|
30
|
+
<div class="col-md-2">
|
31
|
+
<%= f.label :user_id_eq, t('.search_user', default: 'User') %>
|
32
|
+
<%= f.collection_select :user_id_eq, current_site.users.where(id: current_site.orders.pluck(:user_id)).decorate, :id, :the_name, {include_blank: true}, class: 'form-control' %>
|
33
|
+
</div>
|
34
|
+
<div class="col-md-1 text-left">
|
35
|
+
<label> </label><br>
|
36
|
+
<button type="submit" class="btn btn-primary"><span class="fa fa-search"></span></button>
|
37
|
+
</div>
|
38
|
+
<% end %>
|
39
|
+
<hr>
|
37
40
|
<div class="hidden" id="commerce_cancel_modal">
|
38
41
|
<%= form_tag '#' do %>
|
39
42
|
<div class="form-group">
|
@@ -61,22 +64,19 @@
|
|
61
64
|
<table class="table">
|
62
65
|
<thead>
|
63
66
|
<tr>
|
64
|
-
<th><%=
|
65
|
-
<th><%=
|
66
|
-
<th><%=
|
67
|
-
<th><%=
|
68
|
-
<th><%=
|
69
|
-
<th><%=
|
70
|
-
<th><%=
|
71
|
-
<th><%=
|
72
|
-
<th><%=
|
67
|
+
<th><%= t('plugins.ecommerce.table.id', default: 'Id') %></th>
|
68
|
+
<th><%= t('plugins.ecommerce.table.customer', default: 'Customer') %></th>
|
69
|
+
<th><%= t('plugins.ecommerce.table.status', default: 'Status') %></th>
|
70
|
+
<th><%= t('plugins.ecommerce.table.paid', default: 'Paid?') %></th>
|
71
|
+
<th><%= t('plugins.ecommerce.table.products', default: 'Products') %></th>
|
72
|
+
<th><%= t('plugins.ecommerce.table.amount', default: 'Amount') %></th>
|
73
|
+
<th><%= t('plugins.ecommerce.table.created_at', default: 'Created at') %></th>
|
74
|
+
<th><%= t('plugins.ecommerce.table.payment_method', default: 'Payment Method') %></th>
|
75
|
+
<th><%= t('camaleon_cms.admin.table.actions', default: 'Actions') %></th>
|
73
76
|
</tr>
|
74
77
|
</thead>
|
75
78
|
<tbody>
|
76
|
-
<%
|
77
|
-
@orders.each do |order|
|
78
|
-
order = order.decorate
|
79
|
-
%>
|
79
|
+
<% amount = 0; @orders.each do |order| order = order.decorate; amount += order.amount %>
|
80
80
|
<tr>
|
81
81
|
<td><%= order.slug %></td>
|
82
82
|
<td>
|
@@ -94,7 +94,7 @@
|
|
94
94
|
<% end %>
|
95
95
|
</td>
|
96
96
|
<td><%= order.cache_the_total %></td>
|
97
|
-
<td><%= order.
|
97
|
+
<td><%= order.the_created_at %></td>
|
98
98
|
<td><%= order.payment_method.name rescue "" %></td>
|
99
99
|
<td>
|
100
100
|
<%= link_to raw('<i class="fa fa-eye"></i>'), {action: :show, id: order.slug}, class: "btn btn-info btn-xs", title: "#{t('camaleon_cms.admin.button.preview')}" %>
|
@@ -103,7 +103,8 @@
|
|
103
103
|
<div class="btn-group">
|
104
104
|
<button class="btn btn-info btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="<%= t('camaleon_cms.admin.button.settings') %>"><i class="fa fa-cog"></i></button>
|
105
105
|
<ul class="dropdown-menu pull-right" style="min-width: 50px;">
|
106
|
-
|
106
|
+
<%#= content_tag :li, link_to(t('plugins.ecommerce.table.make_accepted', default: 'Mark as Accepted'), url_for(action: :mark_accepted, order_id: order.slug), class: 'btn btn-xs') if order.paid? %>
|
107
|
+
<%= content_tag :li, link_to(t('.resend_email', default: 'Resend Email'), url_for(action: :resend_email, order_id: order.slug), class: 'btn btn-xs') %>
|
107
108
|
<%= content_tag :li, link_to(t('plugins.ecommerce.table.make_shipped', default: 'Mark as Shipped'), url_for(action: :mark_shipped, order_id: order.slug), class: 'btn btn-xs mark_shipped_btn') if order.accepted? || order.paid? %>
|
108
109
|
<%= content_tag :li, link_to(t('plugins.ecommerce.table.make_canceled', default: 'Mark as Canceled'), url_for(action: :mark_canceled, order_id: order.slug), class: 'btn btn-xs mark_canceled_btn', 'data-confirm_msg'=> t('plugins.ecommerce.table.confirm_mark_as_cancel', default: 'Are you sure to mark as Canceled?')) if order.bank_pending? || order.on_delivery_pending? || order.paid? %>
|
109
110
|
<%= content_tag :li, link_to(t('plugins.ecommerce.table.make_bank_confirmed', default: 'Mark as Paid'), url_for(action: :mark_bank_confirmed, order_id: order.slug), class: 'btn btn-xs', 'data-confirm'=> t('plugins.ecommerce.table.confirm_mark_as_paid', default: 'Are you sure to mark as Paid?')) if order.bank_pending? || order.on_delivery_pending? %>
|
@@ -115,26 +116,21 @@
|
|
115
116
|
</tbody>
|
116
117
|
</table>
|
117
118
|
<%= content_tag("div", raw(t('camaleon_cms.admin.message.data_found_list')), class: "alert alert-warning") if @orders.empty? %>
|
118
|
-
<%=
|
119
|
+
<%= content_tag("div", "<strong>#{t('plugins.ecommerce.front.orders.index.total_amount', default: 'Total Amount')}: #{e_parse_price(amount)}</strong>".html_safe, class: "") %>
|
120
|
+
<%= raw cama_do_pagination @orders %>
|
119
121
|
</div>
|
120
122
|
</div>
|
121
123
|
<script>
|
122
124
|
jQuery(function () {
|
123
125
|
var panel = $('#commerce-orders-list');
|
126
|
+
panel.find('.date_field_w').datepicker();
|
127
|
+
|
124
128
|
panel.find('.mark_shipped_btn').click(function(e){
|
125
129
|
var link = $(this);
|
126
130
|
e.preventDefault();
|
127
131
|
open_modal({title: link.text(), content: panel.find('#commerce_shipped_modal').html(), callback: function(modal){ modal.find('form').attr('action', link.attr('href')).validate(); }});
|
128
132
|
});
|
129
133
|
|
130
|
-
panel.find('#ecommerce_adv_search_btn').click(function(e){
|
131
|
-
var link = $(this);
|
132
|
-
e.preventDefault();
|
133
|
-
open_modal({title: link.attr('title'), content: panel.find('#commerce_adv_search_modal').html(), callback: function(modal){
|
134
|
-
modal.find('form').validate();
|
135
|
-
}});
|
136
|
-
});
|
137
|
-
|
138
134
|
panel.find('.mark_canceled_btn').click(function(e){
|
139
135
|
var link = $(this);
|
140
136
|
e.preventDefault();
|