camaleon_ecommerce 1.1 → 1.2
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/javascripts/plugins/ecommerce/admin_product.js.coffee +83 -0
- data/app/assets/javascripts/plugins/ecommerce/cart.js +3 -0
- data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +6 -12
- data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +2 -8
- data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +7 -12
- data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +0 -8
- data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +0 -8
- data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +6 -14
- data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +6 -12
- data/app/controllers/plugins/ecommerce/admin_controller.rb +27 -8
- data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +42 -75
- data/app/controllers/plugins/ecommerce/front/orders_controller.rb +2 -10
- data/app/controllers/plugins/ecommerce/front_controller.rb +0 -8
- data/app/decorators/plugins/ecommerce/coupon_decorator.rb +0 -8
- data/app/decorators/plugins/ecommerce/product_decorator.rb +86 -35
- data/app/decorators/plugins/ecommerce/product_item_decorator.rb +27 -3
- data/app/decorators/plugins/ecommerce/product_variation_decorator.rb +18 -0
- data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +11 -13
- data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +25 -11
- data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +22 -27
- data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +1 -56
- data/app/models/plugins/ecommerce/attribute.rb +9 -0
- data/app/models/plugins/ecommerce/cart.rb +46 -28
- data/app/models/plugins/ecommerce/coupon.rb +0 -8
- data/app/models/plugins/ecommerce/legacy_cart.rb +50 -0
- data/app/models/plugins/ecommerce/legacy_order.rb +48 -0
- data/app/models/plugins/ecommerce/order.rb +0 -8
- data/app/models/plugins/ecommerce/order_detail.rb +0 -9
- data/app/models/plugins/ecommerce/payment_method.rb +0 -8
- data/app/models/plugins/ecommerce/product_item.rb +3 -10
- data/app/models/plugins/ecommerce/product_variation.rb +9 -0
- data/app/models/plugins/ecommerce/shipping_method.rb +0 -8
- data/app/models/plugins/ecommerce/tax_rate.rb +0 -8
- data/app/services/plugins/ecommerce/cart_service.rb +149 -0
- data/app/services/plugins/ecommerce/order_service.rb +26 -0
- data/app/services/plugins/ecommerce/product_item_service.rb +29 -0
- data/app/services/plugins/ecommerce/product_service.rb +17 -0
- data/app/services/plugins/ecommerce/site_service.rb +21 -0
- data/app/services/plugins/ecommerce/user_cart_service.rb +12 -0
- data/app/services/plugins/ecommerce/user_product_service.rb +29 -0
- data/app/services/plugins/ecommerce/util_service.rb +5 -0
- data/app/views/plugins/ecommerce/admin/orders/form.html.erb +28 -16
- data/app/views/plugins/ecommerce/admin/orders/index.html.erb +7 -1
- data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +11 -1
- data/app/views/plugins/ecommerce/admin/product_attributes.html.erb +95 -0
- data/app/views/plugins/ecommerce/admin/products/_variations.html.erb +72 -0
- data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +5 -5
- data/app/views/plugins/ecommerce/front/orders/show.html.erb +96 -89
- data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +3 -3
- data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +1 -1
- data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +6 -1
- data/app/views/plugins/ecommerce/partials/checkout/_products_detail.html.erb +1 -1
- data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +26 -22
- data/app/views/post_types/commerce/single.html.erb +28 -12
- data/config/camaleon_plugin.json +4 -12
- data/config/custom_models.rb +10 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/es.yml +112 -54
- data/config/routes.rb +2 -0
- data/db/migrate/20160527184747_add_new_cart_structure.rb +7 -4
- data/db/migrate/20160620200501_add_product_attributes_structure.rb +21 -0
- data/db/migrate/20160825174848_set_cama_post_decorator_class.rb +13 -0
- data/db/migrate/20160825232739_migrate_order_data.rb +87 -0
- data/lib/ecommerce/version.rb +1 -1
- metadata +22 -7
- data/app/assets/javascripts/plugins/ecommerce/admin.js +0 -0
- data/app/assets/javascripts/plugins/ecommerce/fix_form.js +0 -7
- data/config/currency_en.json +0 -154
- data/config/currency_es.json +0 -154
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d5a7d45b38213978fbc5fc1e46a33b28f513808
|
4
|
+
data.tar.gz: 9681269b718331bbf6ea48b03b05fb7c8bd7a51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9c967dce8e3cf4ba124087a9357e248fd0bed5fde41fa6eb3b6d71f503d5d5547f75f0ddd5ccf573bd291db489022c8f0ddd6221dfe2dbc29ecaab2b395a96
|
7
|
+
data.tar.gz: 84b1cb427d77a4db5c49a5665174ae3900e67e3bc380e98a6bdc61e223723230547e27cf90878a00ea2b303290efbc760aa3524f629bc0f0b4a0a8bb1ad2b0ba
|
@@ -0,0 +1,83 @@
|
|
1
|
+
$ ->
|
2
|
+
form = $('#form-post')
|
3
|
+
variation_id = 1
|
4
|
+
product_variations = form.find('#product_variations')
|
5
|
+
form.find('.content-frame-body > .c-field-group:last').after(product_variations.removeClass('hidden'))
|
6
|
+
|
7
|
+
# photo uploader
|
8
|
+
product_variations.on('click', '.product_variation_photo_link', ->
|
9
|
+
$input = $(this).prev()
|
10
|
+
$.fn.upload_filemanager({
|
11
|
+
formats: "image",
|
12
|
+
dimension: $input.attr("data-dimension") || '',
|
13
|
+
versions: $input.attr("data-versions") || '',
|
14
|
+
thumb_size: $input.attr("data-thumb_size") || '',
|
15
|
+
selected: (file, response) ->
|
16
|
+
$input.val(file.url);
|
17
|
+
})
|
18
|
+
return false
|
19
|
+
)
|
20
|
+
|
21
|
+
cache_variation = product_variations.find('.blank_product_variation').remove().clone().removeClass('hidden')
|
22
|
+
cache_values = cache_variation.find('.sortable_values > li:first').remove().clone()
|
23
|
+
|
24
|
+
# add new variation
|
25
|
+
product_variations.find('.add_new_variation').click ->
|
26
|
+
clone = cache_variation.clone().attr('data-id', 'new_'+variation_id+=1)
|
27
|
+
product_variations.children('.variations_sortable').append(clone)
|
28
|
+
clone.trigger('fill_variation_id')
|
29
|
+
return false
|
30
|
+
|
31
|
+
# add new variation value
|
32
|
+
product_variations.on('click', '.add_new_value', ->
|
33
|
+
clone = cache_values.clone()
|
34
|
+
key = $(this).closest('.product_variation').attr('data-id')
|
35
|
+
clone.find('input, select').each(->
|
36
|
+
$(this).attr('name', $(this).attr('name').replace('[]', '['+key+']')).removeAttr('id')
|
37
|
+
)
|
38
|
+
$(this).closest('.variation_attributes').find('.sortable_values').append(clone)
|
39
|
+
clone.find('.product_attribute_select').trigger('change')
|
40
|
+
return false
|
41
|
+
)
|
42
|
+
|
43
|
+
# change attribute
|
44
|
+
product_variations.on('change', '.product_attribute_select', ->
|
45
|
+
v = $(this).val()
|
46
|
+
sel = $(this).closest('.row').find('.product_attribute_vals_select').html('')
|
47
|
+
for attr in PRODUCT_ATTRIBUTES
|
48
|
+
if `attr.id == v`
|
49
|
+
for value in attr.values
|
50
|
+
sel.append('<option value="'+value.id+'">'+value.label.replace(/</g, '<')+'</option>')
|
51
|
+
)
|
52
|
+
|
53
|
+
product_variations.on('fill_variation_id', '.product_variation', ->
|
54
|
+
key = $(this).attr('data-id')
|
55
|
+
$(this).find('input, select').each(->
|
56
|
+
$(this).attr('name', $(this).attr('name').replace('[]', '['+key+']')).removeAttr('id')
|
57
|
+
)
|
58
|
+
$(this).find('.sortable_values').sortable({handle: '.val_sorter'})
|
59
|
+
)
|
60
|
+
|
61
|
+
# sortables
|
62
|
+
product_variations.find('.sortable_values').sortable({handle: '.val_sorter'})
|
63
|
+
product_variations.find('.variations_sortable').sortable({handle: '.variation_sorter', update: ()->
|
64
|
+
$(this).children().each((index)->
|
65
|
+
$(this).find('.product_variation_position').val(index);
|
66
|
+
)
|
67
|
+
})
|
68
|
+
|
69
|
+
# delete actions
|
70
|
+
product_variations.on('click', '.val_del', ->
|
71
|
+
$(this).closest('li').fadeOut('slow', ->
|
72
|
+
$(this).remove()
|
73
|
+
)
|
74
|
+
return false
|
75
|
+
)
|
76
|
+
product_variations.on('click', '.var_del', ->
|
77
|
+
unless confirm(product_variations.attr('data-confirm-msg'))
|
78
|
+
return false
|
79
|
+
$(this).closest('.product_variation').fadeOut('slow', ->
|
80
|
+
$(this).remove()
|
81
|
+
)
|
82
|
+
return false
|
83
|
+
)
|
@@ -35,6 +35,9 @@ function cama_checkout_actions(){
|
|
35
35
|
});
|
36
36
|
return false;
|
37
37
|
}});
|
38
|
+
panel.find('#checkout_address_form #billing_address input').blur(function(){
|
39
|
+
panel.find('#checkout_address_form #'+$(this).attr('id').replace('billing_address', 'shipping_address')).val($(this).val())
|
40
|
+
});
|
38
41
|
|
39
42
|
// shipping form
|
40
43
|
panel.find('#checkout_shipping_form').validate({submitHandler: function(form){
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::CouponsController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_order, only: ['show','edit','update','destroy']
|
11
3
|
|
@@ -28,8 +20,7 @@ class Plugins::Ecommerce::Admin::CouponsController < Plugins::Ecommerce::AdminCo
|
|
28
20
|
end
|
29
21
|
|
30
22
|
def create
|
31
|
-
|
32
|
-
@coupon = current_site.coupons.new(data)
|
23
|
+
@coupon = current_site.coupons.new(coupons_permit_data)
|
33
24
|
if @coupon.save
|
34
25
|
@coupon.set_meta('_default', params[:options])
|
35
26
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
|
@@ -40,8 +31,7 @@ class Plugins::Ecommerce::Admin::CouponsController < Plugins::Ecommerce::AdminCo
|
|
40
31
|
end
|
41
32
|
|
42
33
|
def update
|
43
|
-
|
44
|
-
if @coupon.update(data)
|
34
|
+
if @coupon.update(coupons_permit_data)
|
45
35
|
@coupon.set_meta('_default', params[:options])
|
46
36
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
|
47
37
|
redirect_to action: :index
|
@@ -54,6 +44,10 @@ class Plugins::Ecommerce::Admin::CouponsController < Plugins::Ecommerce::AdminCo
|
|
54
44
|
|
55
45
|
|
56
46
|
private
|
47
|
+
|
48
|
+
def coupons_permit_data
|
49
|
+
params.require(:plugins_ecommerce_coupon).permit!
|
50
|
+
end
|
57
51
|
def set_order
|
58
52
|
@coupon = current_site.coupons.find(params[:id])
|
59
53
|
end
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_order, except: [:index, :new] #, only: ['show', 'edit', 'update', 'destroy']
|
11
3
|
before_action :set_order_bread
|
@@ -27,6 +19,7 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
|
|
27
19
|
if params[:s].present?
|
28
20
|
orders = orders.where(status: params[:s])
|
29
21
|
end
|
22
|
+
orders = orders.order('received_at desc')
|
30
23
|
@orders = orders.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
|
31
24
|
end
|
32
25
|
|
@@ -49,6 +42,7 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
|
|
49
42
|
@order.set_meta("billing_address", params[:order][:billing_address])
|
50
43
|
@order.set_meta("shipping_address", params[:order][:shipping_address])
|
51
44
|
@order.set_metas(params[:metas])
|
45
|
+
@order.update(params.require(:plugins_ecommerce_order).permit(:shipped_at))
|
52
46
|
flash[:notice] = "#{t('plugin.ecommerce.message.order_updated', default: 'Order Updated')}"
|
53
47
|
redirect_to action: :show, id: params[:id]
|
54
48
|
end
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_order, only: ['show','edit','update','destroy']
|
11
3
|
|
@@ -31,8 +23,7 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
|
|
31
23
|
end
|
32
24
|
|
33
25
|
def create
|
34
|
-
|
35
|
-
@payment_method = current_site.payment_methods.new(data)
|
26
|
+
@payment_method = current_site.payment_methods.new(payment_permit_data)
|
36
27
|
if @payment_method.save
|
37
28
|
@payment_method.set_meta('_default',params[:options])
|
38
29
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
|
@@ -43,7 +34,6 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
|
|
43
34
|
end
|
44
35
|
|
45
36
|
def update
|
46
|
-
data = params[:plugins_ecommerce_payment_method]
|
47
37
|
|
48
38
|
if defined?(params[:options][:type]) && params[:options][:type] == 'paypal'
|
49
39
|
unless valid_paypal_data(params[:options])
|
@@ -55,7 +45,7 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
|
|
55
45
|
|
56
46
|
#FIXME create valid_authorize_net_data function
|
57
47
|
|
58
|
-
if @payment_method.update(
|
48
|
+
if @payment_method.update(payment_permit_data)
|
59
49
|
@payment_method.set_meta('_default',params[:options])
|
60
50
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
|
61
51
|
redirect_to action: :index
|
@@ -68,6 +58,11 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
|
|
68
58
|
|
69
59
|
|
70
60
|
private
|
61
|
+
|
62
|
+
def payment_permit_data
|
63
|
+
params.require(:plugins_ecommerce_payment_method).permit!
|
64
|
+
end
|
65
|
+
|
71
66
|
def set_order
|
72
67
|
@payment_method = current_site.payment_methods.find(params[:id])#.decorate
|
73
68
|
end
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::PricesController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_shipping_method
|
11
3
|
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::SettingsController < Plugins::Ecommerce::AdminController
|
10
2
|
add_breadcrumb I18n.t("plugin.ecommerce.e_commerce")
|
11
3
|
def index
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::ShippingMethodsController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_order, only: ['show','edit','update','destroy']
|
11
3
|
|
@@ -29,8 +21,7 @@ class Plugins::Ecommerce::Admin::ShippingMethodsController < Plugins::Ecommerce:
|
|
29
21
|
end
|
30
22
|
|
31
23
|
def create
|
32
|
-
|
33
|
-
@shipping_method = current_site.shipping_methods.new(data)
|
24
|
+
@shipping_method = current_site.shipping_methods.new(shipping_permit_data)
|
34
25
|
if @shipping_method.save
|
35
26
|
@shipping_method.set_meta('_default',params[:options])
|
36
27
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
|
@@ -41,8 +32,7 @@ class Plugins::Ecommerce::Admin::ShippingMethodsController < Plugins::Ecommerce:
|
|
41
32
|
end
|
42
33
|
|
43
34
|
def update
|
44
|
-
|
45
|
-
if @shipping_method.update(data)
|
35
|
+
if @shipping_method.update(shipping_permit_data)
|
46
36
|
@shipping_method.set_meta('_default',params[:options])
|
47
37
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
|
48
38
|
redirect_to action: :index
|
@@ -52,11 +42,13 @@ class Plugins::Ecommerce::Admin::ShippingMethodsController < Plugins::Ecommerce:
|
|
52
42
|
end
|
53
43
|
|
54
44
|
|
55
|
-
|
56
|
-
|
57
45
|
private
|
58
46
|
def set_order
|
59
47
|
@shipping_method = current_site.shipping_methods.find(params[:id])
|
60
48
|
end
|
61
49
|
|
50
|
+
def shipping_permit_data
|
51
|
+
params.require(:plugins_ecommerce_shipping_method).permit!
|
52
|
+
end
|
53
|
+
|
62
54
|
end
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Admin::TaxRatesController < Plugins::Ecommerce::AdminController
|
10
2
|
before_action :set_order, only: ['show','edit','update','destroy']
|
11
3
|
|
@@ -28,8 +20,7 @@ class Plugins::Ecommerce::Admin::TaxRatesController < Plugins::Ecommerce::AdminC
|
|
28
20
|
end
|
29
21
|
|
30
22
|
def create
|
31
|
-
|
32
|
-
@tax_rate = current_site.tax_rates.new(data)
|
23
|
+
@tax_rate = current_site.tax_rates.new(tax_rate_permit_data)
|
33
24
|
if @tax_rate.save
|
34
25
|
@tax_rate.set_meta('_default', params[:options])
|
35
26
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
|
@@ -40,8 +31,7 @@ class Plugins::Ecommerce::Admin::TaxRatesController < Plugins::Ecommerce::AdminC
|
|
40
31
|
end
|
41
32
|
|
42
33
|
def update
|
43
|
-
|
44
|
-
if @tax_rate.update(data)
|
34
|
+
if @tax_rate.update(tax_rate_permit_data)
|
45
35
|
@tax_rate.set_meta('_default', params[:options])
|
46
36
|
flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
|
47
37
|
redirect_to action: :index
|
@@ -54,6 +44,10 @@ class Plugins::Ecommerce::Admin::TaxRatesController < Plugins::Ecommerce::AdminC
|
|
54
44
|
|
55
45
|
|
56
46
|
private
|
47
|
+
def tax_rate_permit_data
|
48
|
+
params.require(:plugins_ecommerce_tax_rate).permit!
|
49
|
+
end
|
50
|
+
|
57
51
|
def set_order
|
58
52
|
@tax_rate = current_site.tax_rates.find(params[:id])
|
59
53
|
end
|
@@ -1,17 +1,36 @@
|
|
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
1
|
class Plugins::Ecommerce::AdminController < CamaleonCms::Apps::PluginsAdminController
|
10
2
|
before_action :verify_ecommerce_permission
|
11
3
|
def index
|
12
4
|
# here your actions for admin panel
|
13
5
|
end
|
14
6
|
|
7
|
+
def product_attributes
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def save_product_attributes
|
12
|
+
current_site.product_attributes.where.not(id: params[:attribute].keys).destroy_all
|
13
|
+
params[:attribute].each do |key, values|
|
14
|
+
if key.include?('new')
|
15
|
+
group = current_site.product_attributes.create(label: params[:attribute_names][key][:label])
|
16
|
+
else
|
17
|
+
group = current_site.product_attributes.find(key)
|
18
|
+
group.update(label: params[:attribute_names][key][:label])
|
19
|
+
end
|
20
|
+
group.values.where.not(id: values.map{|v| v[:id] }).delete_all
|
21
|
+
values.each do |val|
|
22
|
+
data = {key: val[:key], label: val[:value], position: val[:position]}
|
23
|
+
if val[:id].present?
|
24
|
+
group.values.find(val[:id]).update(data)
|
25
|
+
else
|
26
|
+
group.values.create(data)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
flash[:notice] = t('.saved_product_attributes', default: 'Attributes Saved')
|
31
|
+
redirect_to action: :product_attributes
|
32
|
+
end
|
33
|
+
|
15
34
|
private
|
16
35
|
def verify_ecommerce_permission
|
17
36
|
authorize! :posts, get_commerce_post_type
|
@@ -1,11 +1,3 @@
|
|
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
1
|
class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontController
|
10
2
|
before_action :commerce_authenticate
|
11
3
|
before_action :set_cart
|
@@ -16,7 +8,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
16
8
|
flash[:notice] = t('plugins.ecommerce.messages.cart_no_products', default: 'Not exist products in your cart')
|
17
9
|
return redirect_to action: :cart_index
|
18
10
|
end
|
19
|
-
@
|
11
|
+
@ecommerce_breadcrumb << [t('plugins.ecommerce.messages.checkout', default: 'Checkout')]
|
20
12
|
end
|
21
13
|
|
22
14
|
def step_address
|
@@ -54,7 +46,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
54
46
|
|
55
47
|
def cart_index
|
56
48
|
@products = @cart.product_items.decorate
|
57
|
-
@
|
49
|
+
@ecommerce_breadcrumb << [t('plugins.ecommerce.messages.shopping_cart', default: 'Shopping cart')]
|
58
50
|
end
|
59
51
|
|
60
52
|
def res_coupon
|
@@ -73,24 +65,30 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
73
65
|
data = params[:cart]
|
74
66
|
qty = data[:qty].to_f rescue 0
|
75
67
|
product = current_site.products.find(data[:product_id]).decorate
|
76
|
-
unless product.
|
77
|
-
flash[:error] =
|
68
|
+
unless product.valid_variation?(params[:variation_id])
|
69
|
+
flash[:error] = t('plugins.ecommerce.messages.missing_variation', default: 'Invalid Product Variation')
|
70
|
+
return redirect_to action: :cart_index
|
71
|
+
end
|
72
|
+
|
73
|
+
unless product.can_added?(qty, params[:variation_id])
|
74
|
+
flash[:error] = t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(params[:variation_id]), qty: product.the_qty_real(params[:variation_id]), default: 'There is not enough products "%{product}" (Available %{qty})')
|
78
75
|
return redirect_to :back
|
79
76
|
end
|
80
|
-
@cart.add_product(product, qty)
|
77
|
+
@cart.add_product(product, qty, params[:variation_id])
|
81
78
|
flash[:notice] = t('plugins.ecommerce.messages.added_product_in_cart', default: 'Product added into cart')
|
82
79
|
redirect_to action: :cart_index
|
83
80
|
end
|
84
81
|
|
85
82
|
def cart_update
|
86
83
|
errors = []
|
87
|
-
params[:
|
88
|
-
|
84
|
+
params[:product_items].each do |data|
|
85
|
+
item = @cart.product_items.find(data[:item_id])
|
86
|
+
product = item.product.decorate
|
89
87
|
qty = data[:qty].to_f
|
90
|
-
if product.can_added?(qty)
|
91
|
-
@cart.add_product(product, qty)
|
88
|
+
if product.can_added?(qty, item.variation_id)
|
89
|
+
@cart.add_product(product, qty, item.variation_id)
|
92
90
|
else
|
93
|
-
errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.
|
91
|
+
errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(item.variation_id), qty: product.the_qty_real(item.variation_id), default: 'There is not enough products "%{product}" (Available %{qty})')
|
94
92
|
end
|
95
93
|
end
|
96
94
|
flash[:error] = errors.join('<br>') if errors.present?
|
@@ -99,40 +97,32 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
99
97
|
end
|
100
98
|
|
101
99
|
def cart_remove
|
102
|
-
@cart.
|
100
|
+
@cart.product_items.find(params[:product_item_id]).destroy
|
103
101
|
flash[:notice] = t('plugins.ecommerce.messages.cart_deleted', default: 'Product removed from your shopping cart')
|
104
102
|
redirect_to action: :cart_index
|
105
103
|
end
|
106
104
|
|
107
105
|
def cancel_order
|
108
|
-
# @cart = current_site.orders.find_by_slug(params[:order])
|
109
106
|
@cart.update({status: 'canceled', kind: 'order', closed_at: Time.now})
|
110
107
|
flash[:notice] = t('plugins.ecommerce.messages.canceled_order', default: "Canceled Order")
|
111
108
|
redirect_to plugins_ecommerce_orders_url
|
112
109
|
end
|
113
110
|
|
114
|
-
# pay by stripe
|
115
111
|
def pay_by_stripe
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
charge = Stripe::Charge.create(
|
121
|
-
:customer => customer.id,
|
122
|
-
:amount => commerce_to_cents(@cart.total_amount),
|
123
|
-
:description => "Payment Products: #{@cart.products_title}",
|
124
|
-
:currency => commerce_current_currency
|
112
|
+
result = Plugins::Ecommerce::CartService.new(current_site, @cart).
|
113
|
+
pay_with_stripe(payment_method: @payment,
|
114
|
+
email: params[:stripeEmail],
|
115
|
+
stripe_token: params[:stripeToken],
|
125
116
|
)
|
126
|
-
|
117
|
+
if result[:error].present?
|
118
|
+
flash[:error] = result[:error]
|
119
|
+
if result[:payment_error]
|
120
|
+
flash[:payment_error] = true
|
121
|
+
end
|
122
|
+
redirect_to :back
|
123
|
+
else
|
127
124
|
mark_order_like_received(@cart)
|
128
125
|
redirect_to plugins_ecommerce_orders_url
|
129
|
-
rescue Stripe::CardError => e
|
130
|
-
flash[:error] = e.message
|
131
|
-
flash[:payment_error] = true
|
132
|
-
redirect_to :back
|
133
|
-
rescue => e
|
134
|
-
flash[:error] = e.message
|
135
|
-
redirect_to :back
|
136
126
|
end
|
137
127
|
end
|
138
128
|
|
@@ -143,7 +133,15 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
143
133
|
end
|
144
134
|
|
145
135
|
def pay_by_authorize_net
|
146
|
-
res =
|
136
|
+
res = Plugins::Ecommerce::CartService.new(current_site, @cart).
|
137
|
+
pay_with_authorize_net(payment_method: @payment, ip: request.remote_ip,
|
138
|
+
first_name: params[:firstName],
|
139
|
+
last_name: params[:lastName],
|
140
|
+
number: params[:cardNumber],
|
141
|
+
exp_month: params[:expMonth],
|
142
|
+
exp_year: params[:expYear],
|
143
|
+
cvc: params[:cvCode],
|
144
|
+
)
|
147
145
|
if res[:error].present?
|
148
146
|
flash[:error] = res[:error]
|
149
147
|
flash[:payment_error] = true
|
@@ -155,7 +153,6 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
155
153
|
end
|
156
154
|
|
157
155
|
def success_paypal
|
158
|
-
# @cart = current_site.carts.find_by_slug(params[:order])
|
159
156
|
@cart.set_meta('payment_data', {token: params[:token], PayerID: params[:PayerID]})
|
160
157
|
mark_order_like_received(@cart)
|
161
158
|
redirect_to plugins_ecommerce_orders_url
|
@@ -167,48 +164,18 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
|
|
167
164
|
end
|
168
165
|
|
169
166
|
def pay_by_paypal
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
:login => @payment.options[:paypal_login],
|
174
|
-
:password => @payment.options[:paypal_password],
|
175
|
-
:signature => @payment.options[:paypal_signature]
|
176
|
-
}
|
177
|
-
@gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
|
178
|
-
@options = {
|
179
|
-
brand_name: current_site.name,
|
180
|
-
items: [{number: @cart.slug, name: "Buy Products from #{current_site.the_title}: #{@cart.products_title}", amount: commerce_to_cents(@cart.total_amount)}],
|
181
|
-
:order_id => @cart.slug,
|
182
|
-
:currency => current_site.currency_code,
|
183
|
-
:email => @cart.user.email,
|
184
|
-
:billing_address => {:name => "#{billing_address[:first_name]} #{billing_address[:last_name]}",
|
185
|
-
:address1 => billing_address[:address1],
|
186
|
-
:address2 => billing_address[:address2],
|
187
|
-
:city => billing_address[:city],
|
188
|
-
:state => billing_address[:state],
|
189
|
-
:country => billing_address[:country],
|
190
|
-
:zip => billing_address[:zip]
|
191
|
-
},
|
192
|
-
:description => "Buy Products from #{current_site.the_title}: #{@cart.total_amount}",
|
193
|
-
:ip => request.remote_ip,
|
194
|
-
:return_url => plugins_ecommerce_checkout_success_paypal_url(order: @cart.slug),
|
195
|
-
:cancel_return_url => plugins_ecommerce_checkout_cancel_paypal_url(order: @cart.slug)
|
196
|
-
}
|
197
|
-
response = @gateway.setup_purchase(commerce_to_cents(@cart.total_amount), @options)
|
198
|
-
redirect_to @gateway.redirect_url_for(response.token)
|
167
|
+
result = Plugins::Ecommerce::CartService.new(current_site, @cart).
|
168
|
+
pay_with_paypal(payment_method: @payment, ip: request.remote_ip, return_url: plugins_ecommerce_checkout_success_paypal_url(order: @cart.slug), cancel_return_url: plugins_ecommerce_checkout_cancel_paypal_url(order: @cart.slug))
|
169
|
+
redirect_to result[:redirect_url]
|
199
170
|
end
|
200
171
|
|
201
172
|
private
|
202
173
|
def set_cart
|
203
|
-
@cart =
|
204
|
-
end
|
205
|
-
|
206
|
-
def commerce_to_cents(money)
|
207
|
-
(money*100).round
|
174
|
+
@cart = Plugins::Ecommerce::UserCartService.new(current_site, current_user).get_cart
|
208
175
|
end
|
209
176
|
|
210
177
|
def set_bread
|
211
|
-
@
|
178
|
+
@ecommerce_breadcrumb << [t('plugins.ecommerce.messages.checkout', default: 'Checkout'), url_for(action: :cart_index)]
|
212
179
|
end
|
213
180
|
|
214
181
|
def set_payment
|