camaleon_ecommerce 1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/plugins/ecommerce/admin_product.js.coffee +17 -1
  3. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +1 -1
  4. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +24 -21
  5. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +2 -34
  6. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +3 -6
  7. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +2 -1
  8. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +2 -2
  9. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +1 -1
  10. data/app/controllers/plugins/ecommerce/admin_controller.rb +2 -2
  11. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +34 -18
  12. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +3 -4
  13. data/app/controllers/plugins/ecommerce/front_controller.rb +26 -11
  14. data/app/decorators/plugins/ecommerce/cart_decorator.rb +5 -5
  15. data/app/decorators/plugins/ecommerce/coupon_decorator.rb +8 -27
  16. data/app/decorators/plugins/ecommerce/order_decorator.rb +1 -1
  17. data/app/decorators/plugins/ecommerce/product_decorator.rb +33 -20
  18. data/app/decorators/plugins/ecommerce/product_item_decorator.rb +8 -2
  19. data/app/decorators/plugins/ecommerce/product_variation_decorator.rb +1 -1
  20. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +7 -6
  21. data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +276 -33
  22. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +59 -56
  23. data/app/models/plugins/ecommerce/attribute.rb +3 -0
  24. data/app/models/plugins/ecommerce/cart.rb +31 -7
  25. data/app/models/plugins/ecommerce/legacy_order.rb +1 -30
  26. data/app/models/plugins/ecommerce/order.rb +11 -5
  27. data/app/models/plugins/ecommerce/order_detail.rb +1 -0
  28. data/app/models/plugins/ecommerce/payment_method.rb +9 -5
  29. data/app/models/plugins/ecommerce/product_variation.rb +6 -0
  30. data/app/services/plugins/ecommerce/cart_service.rb +4 -17
  31. data/app/views/camaleon_cms/html_mailer/order_canceled.html.erb +2 -2
  32. data/app/views/camaleon_cms/html_mailer/order_confirmed.html.erb +2 -2
  33. data/app/views/camaleon_cms/html_mailer/order_received.html.erb +5 -3
  34. data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +3 -3
  35. data/app/views/camaleon_cms/html_mailer/order_shipped.html.erb +2 -2
  36. data/app/views/camaleon_cms/html_mailer/recovery_cart.html.erb +3 -3
  37. data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +11 -11
  38. data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +11 -11
  39. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +2 -2
  40. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +53 -63
  41. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +30 -24
  42. data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +8 -8
  43. data/app/views/plugins/ecommerce/admin/payment_methods/show.html.erb +22 -22
  44. data/app/views/plugins/ecommerce/admin/prices/form.html.erb +6 -6
  45. data/app/views/plugins/ecommerce/admin/prices/index.html.erb +8 -8
  46. data/app/views/plugins/ecommerce/admin/product_attributes.html.erb +1 -1
  47. data/app/views/plugins/ecommerce/admin/products/_variations.html.erb +4 -4
  48. data/app/views/plugins/ecommerce/admin/products/index.html.erb +5 -5
  49. data/app/views/plugins/ecommerce/admin/settings/index.html.erb +20 -8
  50. data/app/views/plugins/ecommerce/admin/shipping_methods/form.html.erb +5 -5
  51. data/app/views/plugins/ecommerce/admin/shipping_methods/index.html.erb +8 -9
  52. data/app/views/plugins/ecommerce/admin/shipping_methods/show.html.erb +4 -4
  53. data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +3 -3
  54. data/app/views/plugins/ecommerce/admin/tax_rates/index.html.erb +7 -7
  55. data/app/views/plugins/ecommerce/front/checkout/index.html.erb +4 -4
  56. data/app/views/plugins/ecommerce/front/login.html.erb +3 -6
  57. data/app/views/plugins/ecommerce/front/orders/show.html.erb +7 -1
  58. data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +14 -29
  59. data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +1 -1
  60. data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +100 -99
  61. data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +2 -2
  62. data/app/views/post_types/commerce/{_product_widget.html.erb → _post_list_item.html.erb} +0 -0
  63. data/app/views/post_types/commerce/_product_info.html.erb +45 -0
  64. data/app/views/post_types/commerce/single.html.erb +63 -85
  65. data/config/camaleon_plugin.json +3 -8
  66. data/config/custom_models.rb +28 -4
  67. data/config/locales/en.yml +27 -12
  68. data/config/locales/es.yml +70 -57
  69. data/config/routes.rb +1 -0
  70. data/db/migrate/20161202182552_add_cookie_key_to_cart.rb +5 -0
  71. data/lib/ecommerce/version.rb +1 -1
  72. metadata +7 -14
  73. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +0 -6
  74. data/app/models/plugins/ecommerce/legacy_cart.rb +0 -50
  75. data/app/services/plugins/ecommerce/product_item_service.rb +0 -29
  76. data/app/services/plugins/ecommerce/product_service.rb +0 -17
  77. data/app/services/plugins/ecommerce/site_service.rb +0 -21
  78. data/app/services/plugins/ecommerce/user_cart_service.rb +0 -12
  79. data/app/services/plugins/ecommerce/user_product_service.rb +0 -29
  80. data/app/views/post_types/commerce.html.erb +0 -22
  81. data/app/views/post_types/commerce/category.html.erb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d5a7d45b38213978fbc5fc1e46a33b28f513808
4
- data.tar.gz: 9681269b718331bbf6ea48b03b05fb7c8bd7a51f
3
+ metadata.gz: b0c541a7311004ac7d1612a1526fe1bbe74ba6da
4
+ data.tar.gz: a4a62e0f80a8f9ae124417580584a325c4a98a7f
5
5
  SHA512:
6
- metadata.gz: dc9c967dce8e3cf4ba124087a9357e248fd0bed5fde41fa6eb3b6d71f503d5d5547f75f0ddd5ccf573bd291db489022c8f0ddd6221dfe2dbc29ecaab2b395a96
7
- data.tar.gz: 84b1cb427d77a4db5c49a5665174ae3900e67e3bc380e98a6bdc61e223723230547e27cf90878a00ea2b303290efbc760aa3524f629bc0f0b4a0a8bb1ad2b0ba
6
+ metadata.gz: adff56c87875152cd91047a8a2180b90c0d0b69b3dffb873d0b202c7063755d182c5dd4a1785e47e8800d8fd8de232683a5ffecbd9a75fa9b5f73cfa0151c2ac
7
+ data.tar.gz: 803c28e4d16fa6786a3710db1d9a06d2812d2a58f16b05cb3312626dcb67513bfe75203175ca52596fe9d6e030cd68a3fd66e6532f38212450bcf48cf9d450b9
@@ -26,6 +26,7 @@ $ ->
26
26
  clone = cache_variation.clone().attr('data-id', 'new_'+variation_id+=1)
27
27
  product_variations.children('.variations_sortable').append(clone)
28
28
  clone.trigger('fill_variation_id')
29
+ check_variation_status()
29
30
  return false
30
31
 
31
32
  # add new variation value
@@ -46,7 +47,7 @@ $ ->
46
47
  sel = $(this).closest('.row').find('.product_attribute_vals_select').html('')
47
48
  for attr in PRODUCT_ATTRIBUTES
48
49
  if `attr.id == v`
49
- for value in attr.values
50
+ for value in attr.translated_values
50
51
  sel.append('<option value="'+value.id+'">'+value.label.replace(/</g, '&lt;')+'</option>')
51
52
  )
52
53
 
@@ -78,6 +79,21 @@ $ ->
78
79
  return false
79
80
  $(this).closest('.product_variation').fadeOut('slow', ->
80
81
  $(this).remove()
82
+ check_variation_status()
81
83
  )
82
84
  return false
83
85
  )
86
+
87
+ # check the variation status and disable or enable some custom fields
88
+ check_variation_status = ->
89
+ fields = ['ecommerce_sku', 'ecommerce_price', 'ecommerce_weight', 'ecommerce_stock', 'ecommerce_qty']
90
+ if product_variations.find('.product_variation').length > 0 # is a variation product
91
+ for key in fields
92
+ p_field = form.find('.c-field-group .item-custom-field[data-field-key="'+key+'"]')
93
+ p_field.hide().find('.required').addClass('e_skip_required').removeClass('required')
94
+ else
95
+ for key in fields
96
+ p_field = form.find('.c-field-group .item-custom-field[data-field-key="'+key+'"]')
97
+ p_field.show().find('.e_skip_required').removeClass('e_skip_required').addClass('required')
98
+ check_variation_status()
99
+
@@ -7,7 +7,7 @@ class Plugins::Ecommerce::Admin::CouponsController < Plugins::Ecommerce::AdminCo
7
7
 
8
8
  def new
9
9
  @coupon = current_site.coupons.new
10
- add_breadcrumb("#{t('plugin.ecommerce.new')}")
10
+ add_breadcrumb("#{t('plugins.ecommerce.new')}")
11
11
  render 'form'
12
12
  end
13
13
 
@@ -5,19 +5,16 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
5
5
  def index
6
6
  orders = current_site.orders
7
7
  if params[:q].present?
8
- orders = orders.where(slug: params[:q])
8
+ orders = orders.where("#{Plugins::Ecommerce::Order.table_name}.slug LIKE ?", "%#{params[:q]}%")
9
9
  end
10
10
  if params[:c].present?
11
- orders = orders.joins(:details).where("plugins_order_details.customer LIKE ?", "%#{params[:c]}%")
11
+ orders = orders.joins(:user).where("#{Cama::User.table_name}.first_name LIKE ? OR #{Cama::User.table_name}.last_name LIKE ?", "%#{params[:c]}%", "%#{params[:c]}%")
12
12
  end
13
13
  if params[:e].present?
14
- orders = orders.joins(:details).where("plugins_order_details.email LIKE ?", "%#{params[:e]}%")
15
- end
16
- if params[:p].present?
17
- orders = orders.joins(:details).where("plugins_order_details.phone LIKE ?", "%#{params[:p]}%")
14
+ orders = orders.joins(:user).where("#{Cama::User.table_name}.email LIKE ?", "%#{params[:e]}%")
18
15
  end
19
16
  if params[:s].present?
20
- orders = orders.where(status: params[:s])
17
+ orders = orders.where(status: params[:s].split('|'))
21
18
  end
22
19
  orders = orders.order('received_at desc')
23
20
  @orders = orders.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
@@ -25,7 +22,7 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
25
22
 
26
23
  def show
27
24
  @order = @order.decorate
28
- add_breadcrumb("#{t('plugin.ecommerce.details_order', default: 'Order details')} - #{@order.slug}")
25
+ add_breadcrumb("#{t('plugins.ecommerce.details_order', default: 'Order details')} - #{@order.slug}")
29
26
  end
30
27
 
31
28
  def new
@@ -43,49 +40,55 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
43
40
  @order.set_meta("shipping_address", params[:order][:shipping_address])
44
41
  @order.set_metas(params[:metas])
45
42
  @order.update(params.require(:plugins_ecommerce_order).permit(:shipped_at))
46
- flash[:notice] = "#{t('plugin.ecommerce.message.order_updated', default: 'Order Updated')}"
43
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_updated', default: 'Order Updated')}"
47
44
  redirect_to action: :show, id: params[:id]
48
45
  end
49
46
 
50
47
  def destroy
51
48
  if @order.destroy
52
- flash[:notice] = "#{t('plugin.ecommerce.message.order_destroyed', default: 'Order Destroyed')}"
49
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_destroyed', default: 'Order Destroyed')}"
53
50
  else
54
- flash[:error] = "#{t('plugin.ecommerce.message.order_no_destroyed', default: 'Occurred some problems destroying the order')}"
51
+ flash[:error] = "#{t('plugins.ecommerce.message.order_no_destroyed', default: 'Occurred some problems destroying the order')}"
55
52
  end
56
53
  redirect_to action: :index
57
54
  end
58
55
 
59
56
  # accepted order
60
57
  def mark_accepted
61
- @order.accepted!
62
58
  r = {order: @order}; hooks_run('plugin_ecommerce_before_accepted_order', r)
63
- message = "#{t('plugin.ecommerce.message.order_accepted', default: 'Order Accepted')}"
59
+ @order.accepted!
60
+ message = "#{t('plugins.ecommerce.message.order_accepted', default: 'Order Accepted')}"
64
61
  r = {order: @order, message: message}; hooks_run('plugin_ecommerce_after_accepted_order', r)
65
62
  flash[:notice] = r[:message]
66
63
  redirect_to action: :index
67
64
  end
68
65
 
69
66
  def mark_bank_confirmed
70
- @order.bank_confirmed!
71
- commerce_send_order_received_email(@order, true)
72
- flash[:notice] = "#{t('plugin.ecommerce.message.order_bank_confirmed', default: 'Pay Bank Confirmed')}"
67
+ if @order.on_delivery_pending?
68
+ @order.on_delivery_confirmed!
69
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_on_delivery_confirmed', default: 'Payment on Delivery Confirmed')}"
70
+ commerce_send_order_received_email(@order)
71
+ else
72
+ @order.bank_confirmed!
73
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_bank_confirmed', default: 'Pay Bank Confirmed')}"
74
+ commerce_send_order_received_email(@order, true)
75
+ end
73
76
  redirect_to action: :index
74
77
  end
75
78
 
76
79
  # shipped order
77
80
  def mark_shipped
78
81
  @order.shipped!(params[:consignment_number])
79
- cama_send_email(@order.user.email, t('plugin.ecommerce.mail.order_shipped.subject'), {template_name: 'order_shipped', extra_data: {order: @order, consignment_number: params[:consignment_number]}})
80
- flash[:notice] = "#{t('plugin.ecommerce.message.order_shipped', default: 'Order Shipped')}"
82
+ cama_send_email(@order.user.email, t('plugins.ecommerce.mail.order_shipped.subject'), {template_name: 'order_shipped', extra_data: {order: @order, consignment_number: params[:consignment_number]}})
83
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_shipped', default: 'Order Shipped')}"
81
84
  redirect_to action: :index
82
85
  end
83
86
 
84
87
  def mark_canceled
85
88
  @order.canceled!
86
89
  @order.set_meta('description', params[:description])
87
- cama_send_email(@order.user.email, t('plugin.ecommerce.mail.order_canceled.subject'), {template_name: 'order_canceled', extra_data: {order: @order}, description: params[:description]})
88
- flash[:notice] = "#{t('plugin.ecommerce.message.order_canceled', default: 'Order canceled')}"
90
+ cama_send_email(@order.user.email, t('plugins.ecommerce.mail.order_canceled.subject'), {template_name: 'order_canceled', extra_data: {order: @order}, description: params[:description]})
91
+ flash[:notice] = "#{t('plugins.ecommerce.message.order_canceled', default: 'Order canceled')}"
89
92
  redirect_to action: :index
90
93
  end
91
94
 
@@ -95,7 +98,7 @@ class Plugins::Ecommerce::Admin::OrdersController < Plugins::Ecommerce::AdminCon
95
98
  end
96
99
 
97
100
  def set_order_bread
98
- add_breadcrumb I18n.t("plugin.ecommerce.orders", default: 'Orders'), admin_plugins_ecommerce_orders_path
101
+ add_breadcrumb I18n.t("plugins.ecommerce.orders", default: 'Orders'), admin_plugins_ecommerce_orders_path
99
102
  end
100
103
 
101
104
  end
@@ -8,12 +8,12 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
8
8
  def new
9
9
  @payment_method = current_site.payment_methods.new
10
10
  @payment_method.status = 1
11
- add_breadcrumb("#{t('plugin.ecommerce.new')}")
11
+ add_breadcrumb("#{t('plugins.ecommerce.new')}")
12
12
  render 'form'
13
13
  end
14
14
 
15
15
  def show
16
- add_breadcrumb("#{t('plugin.ecommerce.table.details')}")
16
+ add_breadcrumb("#{t('plugins.ecommerce.table.details')}")
17
17
  @payment_method = @payment_method.decorate
18
18
  end
19
19
 
@@ -34,17 +34,6 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
34
34
  end
35
35
 
36
36
  def update
37
-
38
- if defined?(params[:options][:type]) && params[:options][:type] == 'paypal'
39
- unless valid_paypal_data(params[:options])
40
- flash.now[:error] = "#{t('plugin.ecommerce.message.error_paypal_values')}"
41
- render 'form'
42
- return
43
- end
44
- end
45
-
46
- #FIXME create valid_authorize_net_data function
47
-
48
37
  if @payment_method.update(payment_permit_data)
49
38
  @payment_method.set_meta('_default',params[:options])
50
39
  flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
@@ -54,11 +43,7 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
54
43
  end
55
44
  end
56
45
 
57
-
58
-
59
-
60
46
  private
61
-
62
47
  def payment_permit_data
63
48
  params.require(:plugins_ecommerce_payment_method).permit!
64
49
  end
@@ -66,21 +51,4 @@ class Plugins::Ecommerce::Admin::PaymentMethodsController < Plugins::Ecommerce::
66
51
  def set_order
67
52
  @payment_method = current_site.payment_methods.find(params[:id])#.decorate
68
53
  end
69
-
70
- def valid_paypal_data(data)
71
- ActiveMerchant::Billing::Base.mode = data[:paypal_sandbox].to_s.to_bool ? :test : :production
72
- paypal_options = {
73
- :login => data[:paypal_login],
74
- :password => data[:paypal_password],
75
- :signature => data[:paypal_signature]
76
- }
77
- opts = {
78
- :ip => request.remote_ip,
79
- :return_url => plugins_ecommerce_order_success_url(order: 'test'),
80
- :cancel_return_url => plugins_ecommerce_order_cancel_url(order: 'test')
81
- }
82
- @gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
83
- response = @gateway.setup_authorization(500, opts)
84
- response.success?
85
- end
86
54
  end
@@ -2,13 +2,11 @@ class Plugins::Ecommerce::Admin::PricesController < Plugins::Ecommerce::AdminCon
2
2
  before_action :set_shipping_method
3
3
 
4
4
  def index
5
- add_breadcrumb("#{t('plugin.ecommerce.product.price')}")
6
5
  end
7
6
 
8
7
  def new
9
8
  @price = {}
10
- add_breadcrumb("#{t('plugin.ecommerce.product.price')}", admin_plugins_ecommerce_shipping_method_prices_path( params[:shipping_method_id] ))
11
- add_breadcrumb("#{t('plugin.ecommerce.new')}")
9
+ add_breadcrumb("#{t('plugins.ecommerce.new')}")
12
10
  render 'form'
13
11
  end
14
12
 
@@ -17,7 +15,6 @@ class Plugins::Ecommerce::Admin::PricesController < Plugins::Ecommerce::AdminCon
17
15
 
18
16
  def edit
19
17
  @price = @prices[params[:id].to_sym] || {}
20
- add_breadcrumb("#{t('plugin.ecommerce.product.price')}", admin_plugins_ecommerce_shipping_method_prices_path( params[:shipping_method_id] ))
21
18
  add_breadcrumb("#{t('camaleon_cms.admin.button.edit')}")
22
19
  render 'form'
23
20
  end
@@ -53,9 +50,9 @@ class Plugins::Ecommerce::Admin::PricesController < Plugins::Ecommerce::AdminCon
53
50
  private
54
51
  def set_shipping_method
55
52
  @shipping_method = current_site.shipping_methods.find(params[:shipping_method_id])
56
- add_breadcrumb(t("plugin.ecommerce.shipping_methods"))
53
+ add_breadcrumb(t("plugins.ecommerce.shipping_methods"))
57
54
  add_breadcrumb(@shipping_method.name)
58
- add_breadcrumb(t("plugin.ecommerce.shipping_prices"))
55
+ add_breadcrumb(t("plugins.ecommerce.shipping_prices"), admin_plugins_ecommerce_shipping_method_prices_path(params[:shipping_method_id]))
59
56
  @prices = @shipping_method.get_meta("prices", {})
60
57
  end
61
58
 
@@ -1,9 +1,10 @@
1
1
  class Plugins::Ecommerce::Admin::SettingsController < Plugins::Ecommerce::AdminController
2
- add_breadcrumb I18n.t("plugin.ecommerce.e_commerce")
2
+ add_breadcrumb I18n.t("plugins.ecommerce.e_commerce")
3
3
  def index
4
4
  @setting = current_site.get_meta("_setting_ecommerce", {})
5
5
  end
6
6
 
7
+ # save settings
7
8
  def saved
8
9
  current_site.set_meta('_setting_ecommerce', params[:setting])
9
10
  flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
@@ -7,12 +7,12 @@ class Plugins::Ecommerce::Admin::ShippingMethodsController < Plugins::Ecommerce:
7
7
 
8
8
  def new
9
9
  @shipping_method = current_site.shipping_methods.new
10
- add_breadcrumb("#{t('plugin.ecommerce.new')}")
10
+ add_breadcrumb("#{t('plugins.ecommerce.new')}")
11
11
  render 'form'
12
12
  end
13
13
 
14
14
  def show
15
- add_breadcrumb("#{t('plugin.ecommerce.table.details')}")
15
+ add_breadcrumb("#{t('plugins.ecommerce.table.details')}")
16
16
  end
17
17
 
18
18
  def edit
@@ -7,7 +7,7 @@ class Plugins::Ecommerce::Admin::TaxRatesController < Plugins::Ecommerce::AdminC
7
7
 
8
8
  def new
9
9
  @tax_rate = current_site.tax_rates.new
10
- add_breadcrumb("#{t('plugin.ecommerce.new')}")
10
+ add_breadcrumb("#{t('plugins.ecommerce.new')}")
11
11
  render 'form'
12
12
  end
13
13
 
@@ -33,7 +33,7 @@ class Plugins::Ecommerce::AdminController < CamaleonCms::Apps::PluginsAdminContr
33
33
 
34
34
  private
35
35
  def verify_ecommerce_permission
36
- authorize! :posts, get_commerce_post_type
37
- add_breadcrumb I18n.t("plugin.ecommerce.e_commerce", default: 'Ecommerce'), admin_plugins_ecommerce_index_path
36
+ authorize! :posts, cama_ecommerce_post_type
37
+ add_breadcrumb I18n.t("plugins.ecommerce.e_commerce", default: 'Ecommerce'), admin_plugins_ecommerce_index_path
38
38
  end
39
39
  end
@@ -1,11 +1,11 @@
1
1
  class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontController
2
- before_action :commerce_authenticate
2
+ before_action :commerce_authenticate, except: [:cart_add, :cart_update, :cart_remove, :cart_index]
3
3
  before_action :set_cart
4
- before_action :set_payment, only: [:pay_by_stripe, :pay_by_bank_transfer, :pay_by_credit_card, :pay_by_authorize_net, :pay_by_paypal]
4
+ before_action :set_payment, only: [:pay_by_stripe, :pay_by_bank_transfer, :pay_by_credit_card, :pay_by_authorize_net, :pay_by_paypal, :pay_by_on_delivery]
5
5
 
6
6
  def index
7
7
  unless @cart.product_items.count > 0
8
- flash[:notice] = t('plugins.ecommerce.messages.cart_no_products', default: 'Not exist products in your cart')
8
+ flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.cart_no_products', default: 'Not exist products in your cart')
9
9
  return redirect_to action: :cart_index
10
10
  end
11
11
  @ecommerce_breadcrumb << [t('plugins.ecommerce.messages.checkout', default: 'Checkout')]
@@ -31,7 +31,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
31
31
  if @cart.free_cart?
32
32
  errors = ecommerce_verify_cart_errors(@cart)
33
33
  if errors.present?
34
- flash[:error] = errors.join('<br>')
34
+ flash[:cama_ecommerce][:error] = errors.join('<br>')
35
35
  redirect_to :back
36
36
  else
37
37
  @cart.set_meta('free_order', true)
@@ -39,7 +39,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
39
39
  redirect_to plugins_ecommerce_orders_path
40
40
  end
41
41
  else
42
- flash[:error] = "Invalid complete payment"
42
+ flash[:cama_ecommerce][:error] = "Invalid complete payment"
43
43
  redirect_to :back
44
44
  end
45
45
  end
@@ -66,16 +66,16 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
66
66
  qty = data[:qty].to_f rescue 0
67
67
  product = current_site.products.find(data[:product_id]).decorate
68
68
  unless product.valid_variation?(params[:variation_id])
69
- flash[:error] = t('plugins.ecommerce.messages.missing_variation', default: 'Invalid Product Variation')
69
+ flash[:cama_ecommerce][:error] = t('plugins.ecommerce.messages.missing_variation', default: 'Invalid Product Variation')
70
70
  return redirect_to action: :cart_index
71
71
  end
72
72
 
73
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})')
74
+ flash[:cama_ecommerce][: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})')
75
75
  return redirect_to :back
76
76
  end
77
77
  @cart.add_product(product, qty, params[:variation_id])
78
- flash[:notice] = t('plugins.ecommerce.messages.added_product_in_cart', default: 'Product added into cart')
78
+ flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.added_product_in_cart', default: 'Product added into cart')
79
79
  redirect_to action: :cart_index
80
80
  end
81
81
 
@@ -91,20 +91,20 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
91
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})')
92
92
  end
93
93
  end
94
- flash[:error] = errors.join('<br>') if errors.present?
95
- flash[:notice] = t('plugins.ecommerce.messages.cart_updated', default: 'Shopping cart updated') unless errors.present?
94
+ flash[:cama_ecommerce][:error] = errors.join('<br>') if errors.present?
95
+ flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.cart_updated', default: 'Shopping cart updated') unless errors.present?
96
96
  redirect_to action: :cart_index
97
97
  end
98
98
 
99
99
  def cart_remove
100
100
  @cart.product_items.find(params[:product_item_id]).destroy
101
- flash[:notice] = t('plugins.ecommerce.messages.cart_deleted', default: 'Product removed from your shopping cart')
101
+ flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.cart_deleted', default: 'Product removed from your shopping cart')
102
102
  redirect_to action: :cart_index
103
103
  end
104
104
 
105
105
  def cancel_order
106
106
  @cart.update({status: 'canceled', kind: 'order', closed_at: Time.now})
107
- flash[:notice] = t('plugins.ecommerce.messages.canceled_order', default: "Canceled Order")
107
+ flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.canceled_order', default: "Canceled Order")
108
108
  redirect_to plugins_ecommerce_orders_url
109
109
  end
110
110
 
@@ -115,7 +115,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
115
115
  stripe_token: params[:stripeToken],
116
116
  )
117
117
  if result[:error].present?
118
- flash[:error] = result[:error]
118
+ flash[:cama_ecommerce][:error] = result[:error]
119
119
  if result[:payment_error]
120
120
  flash[:payment_error] = true
121
121
  end
@@ -132,6 +132,12 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
132
132
  redirect_to plugins_ecommerce_orders_url
133
133
  end
134
134
 
135
+ def pay_by_on_delivery
136
+ @cart.set_meta("payment_data", params[:details])
137
+ mark_order_like_received(@cart, 'on_delivery')
138
+ redirect_to plugins_ecommerce_orders_url
139
+ end
140
+
135
141
  def pay_by_authorize_net
136
142
  res = Plugins::Ecommerce::CartService.new(current_site, @cart).
137
143
  pay_with_authorize_net(payment_method: @payment, ip: request.remote_ip,
@@ -143,7 +149,7 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
143
149
  cvc: params[:cvCode],
144
150
  )
145
151
  if res[:error].present?
146
- flash[:error] = res[:error]
152
+ flash[:cama_ecommerce][:error] = res[:error]
147
153
  flash[:payment_error] = true
148
154
  redirect_to :back
149
155
  else
@@ -153,8 +159,18 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
153
159
  end
154
160
 
155
161
  def success_paypal
156
- @cart.set_meta('payment_data', {token: params[:token], PayerID: params[:PayerID]})
157
- mark_order_like_received(@cart)
162
+ response = @cart.paypal_gateway.purchase(Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(@cart.total_amount), {
163
+ :ip => request.remote_ip,
164
+ :token => params[:token],
165
+ :payer_id => params[:PayerID]
166
+ })
167
+
168
+ if response.success?
169
+ @cart.set_meta('payment_data', {token: params[:token], PayerID: params[:PayerID], ip: request.remote_ip})
170
+ mark_order_like_received(@cart)
171
+ else
172
+ flash[:cama_ecommerce][:error] = response.message
173
+ end
158
174
  redirect_to plugins_ecommerce_orders_url
159
175
  end
160
176
 
@@ -165,13 +181,13 @@ class Plugins::Ecommerce::Front::CheckoutController < Plugins::Ecommerce::FrontC
165
181
 
166
182
  def pay_by_paypal
167
183
  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))
184
+ pay_with_paypal(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
185
  redirect_to result[:redirect_url]
170
186
  end
171
187
 
172
188
  private
173
189
  def set_cart
174
- @cart = Plugins::Ecommerce::UserCartService.new(current_site, current_user).get_cart
190
+ @cart = e_current_cart
175
191
  end
176
192
 
177
193
  def set_bread