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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/plugins/ecommerce/admin_product.js.coffee +83 -0
  3. data/app/assets/javascripts/plugins/ecommerce/cart.js +3 -0
  4. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +6 -12
  5. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +2 -8
  6. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +7 -12
  7. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +0 -8
  8. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +0 -8
  9. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +6 -14
  10. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +6 -12
  11. data/app/controllers/plugins/ecommerce/admin_controller.rb +27 -8
  12. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +42 -75
  13. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +2 -10
  14. data/app/controllers/plugins/ecommerce/front_controller.rb +0 -8
  15. data/app/decorators/plugins/ecommerce/coupon_decorator.rb +0 -8
  16. data/app/decorators/plugins/ecommerce/product_decorator.rb +86 -35
  17. data/app/decorators/plugins/ecommerce/product_item_decorator.rb +27 -3
  18. data/app/decorators/plugins/ecommerce/product_variation_decorator.rb +18 -0
  19. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +11 -13
  20. data/app/helpers/plugins/ecommerce/ecommerce_functions_helper.rb +25 -11
  21. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +22 -27
  22. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +1 -56
  23. data/app/models/plugins/ecommerce/attribute.rb +9 -0
  24. data/app/models/plugins/ecommerce/cart.rb +46 -28
  25. data/app/models/plugins/ecommerce/coupon.rb +0 -8
  26. data/app/models/plugins/ecommerce/legacy_cart.rb +50 -0
  27. data/app/models/plugins/ecommerce/legacy_order.rb +48 -0
  28. data/app/models/plugins/ecommerce/order.rb +0 -8
  29. data/app/models/plugins/ecommerce/order_detail.rb +0 -9
  30. data/app/models/plugins/ecommerce/payment_method.rb +0 -8
  31. data/app/models/plugins/ecommerce/product_item.rb +3 -10
  32. data/app/models/plugins/ecommerce/product_variation.rb +9 -0
  33. data/app/models/plugins/ecommerce/shipping_method.rb +0 -8
  34. data/app/models/plugins/ecommerce/tax_rate.rb +0 -8
  35. data/app/services/plugins/ecommerce/cart_service.rb +149 -0
  36. data/app/services/plugins/ecommerce/order_service.rb +26 -0
  37. data/app/services/plugins/ecommerce/product_item_service.rb +29 -0
  38. data/app/services/plugins/ecommerce/product_service.rb +17 -0
  39. data/app/services/plugins/ecommerce/site_service.rb +21 -0
  40. data/app/services/plugins/ecommerce/user_cart_service.rb +12 -0
  41. data/app/services/plugins/ecommerce/user_product_service.rb +29 -0
  42. data/app/services/plugins/ecommerce/util_service.rb +5 -0
  43. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +28 -16
  44. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +7 -1
  45. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +11 -1
  46. data/app/views/plugins/ecommerce/admin/product_attributes.html.erb +95 -0
  47. data/app/views/plugins/ecommerce/admin/products/_variations.html.erb +72 -0
  48. data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +5 -5
  49. data/app/views/plugins/ecommerce/front/orders/show.html.erb +96 -89
  50. data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +3 -3
  51. data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +1 -1
  52. data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +6 -1
  53. data/app/views/plugins/ecommerce/partials/checkout/_products_detail.html.erb +1 -1
  54. data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +26 -22
  55. data/app/views/post_types/commerce/single.html.erb +28 -12
  56. data/config/camaleon_plugin.json +4 -12
  57. data/config/custom_models.rb +10 -0
  58. data/config/locales/en.yml +3 -0
  59. data/config/locales/es.yml +112 -54
  60. data/config/routes.rb +2 -0
  61. data/db/migrate/20160527184747_add_new_cart_structure.rb +7 -4
  62. data/db/migrate/20160620200501_add_product_attributes_structure.rb +21 -0
  63. data/db/migrate/20160825174848_set_cama_post_decorator_class.rb +13 -0
  64. data/db/migrate/20160825232739_migrate_order_data.rb +87 -0
  65. data/lib/ecommerce/version.rb +1 -1
  66. metadata +22 -7
  67. data/app/assets/javascripts/plugins/ecommerce/admin.js +0 -0
  68. data/app/assets/javascripts/plugins/ecommerce/fix_form.js +0 -7
  69. data/config/currency_en.json +0 -154
  70. data/config/currency_es.json +0 -154
@@ -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::OrdersController < Plugins::Ecommerce::FrontController
10
2
  before_action :commerce_authenticate
11
3
  before_action :set_bread
@@ -16,13 +8,13 @@ class Plugins::Ecommerce::Front::OrdersController < Plugins::Ecommerce::FrontCon
16
8
 
17
9
  def show
18
10
  @order = current_site.orders.find_by_slug(params[:order]).decorate
19
- @ecommerce_bredcrumb << [t('plugins.ecommerce.messages.detail_order', default: "Detail order: #%{order}", order: params[:order])]
11
+ @ecommerce_breadcrumb << [t('plugins.ecommerce.messages.detail_order', default: "Detail order: #%{order}", order: params[:order])]
20
12
  end
21
13
 
22
14
 
23
15
 
24
16
  private
25
17
  def set_bread
26
- @ecommerce_bredcrumb << [t('plugins.ecommerce.messages.my_orders', default: 'My Orders'), url_for(action: :index)]
18
+ @ecommerce_breadcrumb << [t('plugins.ecommerce.messages.my_orders', default: 'My Orders'), url_for(action: :index)]
27
19
  end
28
20
  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::FrontController < CamaleonCms::Apps::PluginsFrontController
10
2
  include Plugins::Ecommerce::EcommercePaymentHelper
11
3
  before_action :ecommerce_add_assets_in_front
@@ -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::CouponDecorator < CamaleonCms::TermTaxonomyDecorator
10
2
  delegate_all
11
3
 
@@ -1,46 +1,89 @@
1
1
  class Plugins::Ecommerce::ProductDecorator < CamaleonCms::PostDecorator
2
- def the_sku
3
- object.get_field_value('ecommerce_sku').to_s
2
+
3
+ def the_sku(variation_id = nil)
4
+ sku(variation_id)
4
5
  end
5
- def the_price
6
- "#{h.current_site.current_unit}#{sprintf('%.2f', price)}"
6
+
7
+ def sku(variation_id = nil)
8
+ if variation_id.present?
9
+ get_variation(variation_id).sku
10
+ else
11
+ object.get_field_value('ecommerce_sku').to_s
12
+ end
7
13
  end
8
- def the_weight
9
- "#{h.current_site.current_weight} #{weight}"
14
+
15
+ def the_price(variation_id = nil)
16
+ "#{h.current_site.current_unit}#{sprintf('%.2f', price(variation_id))}"
10
17
  end
11
- def weight
12
- object.get_field_value('ecommerce_weight').to_f || 0
18
+
19
+ def the_weight(variation_id = nil)
20
+ "#{h.current_site.current_weight} #{weight(variation_id)}"
13
21
  end
14
- def the_qty
15
- object.get_field_value('ecommerce_qty') || 0
22
+
23
+ def weight(variation_id = nil)
24
+ if variation_id.present?
25
+ get_variation(variation_id).weight || 0
26
+ else
27
+ object.get_field_value('ecommerce_weight').to_f || 0
28
+ end
16
29
  end
30
+
31
+ def the_qty(variation_id = nil)
32
+ if variation_id.present?
33
+ get_variation(variation_id).qty || 0
34
+ else
35
+ object.get_field_value('ecommerce_qty') || 0
36
+ end
37
+ end
38
+
17
39
  def the_photos
18
40
  object.get_field_values('ecommerce_photos') || []
19
41
  end
20
- def in_stock?
21
- object.get_field_value('ecommerce_stock').to_s.to_bool
42
+
43
+ def in_stock?(variation_id = nil)
44
+ if variation_id.present?
45
+ get_variation(variation_id).qty > 0
46
+ else
47
+ object.get_field_value('ecommerce_stock').to_s.to_bool
48
+ end
49
+ end
50
+
51
+ def price(variation_id = nil)
52
+ if variation_id.present?
53
+ get_variation(variation_id).amount || 0
54
+ else
55
+ object.get_field_value(:ecommerce_price).to_f || 0
56
+ end
22
57
  end
23
58
 
24
- def price
25
- object.get_field_value(:ecommerce_price).to_f || 0
59
+ # return the title for variation prefixed with the title of the product
60
+ def the_variation_title(variation_id = nil)
61
+ "#{the_title}#{" - #{get_variation(variation_id).attribute_values.pluck(:label).join(', ').translate.presence || 'Not defined'}" if variation_id.present? }"
26
62
  end
27
63
 
28
- def the_tax
29
- tax
64
+ # return a product variation by id
65
+ def get_variation(variation_id)
66
+ object.cama_fetch_cache("_get_variation_#{variation_id}") do
67
+ self.product_variations.find(variation_id)
68
+ end
30
69
  end
31
70
 
32
- def tax
71
+ def the_tax(variation_id = nil)
72
+ tax(variation_id)
73
+ end
74
+
75
+ def tax(variation_id = nil)
33
76
  tax_rate_id = object.get_field_value(:ecommerce_tax)
34
77
  if tax_rate_id.present?
35
78
  percent = h.current_site.tax_rates.find(tax_rate_id).options[:rate].to_f rescue 0
36
- price * percent / 100
79
+ price(variation_id) * percent / 100
37
80
  else # tax not defined
38
81
  0
39
82
  end
40
83
  end
41
84
 
42
- def the_stock_status
43
- if in_stock? && the_qty_real.to_i > 0
85
+ def the_stock_status(variation_id = nil)
86
+ if in_stock?(variation_id) && the_qty_real.to_i > 0
44
87
  "<span class='label label-success'>#{I18n.t('plugin.ecommerce.product.in_stock')}</span>"
45
88
  else
46
89
  "<span class='label label-danger'>#{I18n.t('plugin.ecommerce.product.not_in_tock')}</span>"
@@ -60,29 +103,37 @@ class Plugins::Ecommerce::ProductDecorator < CamaleonCms::PostDecorator
60
103
  end
61
104
 
62
105
  # return the total of products available to sell
63
- def the_qty_real
64
- object.get_field_value('ecommerce_qty').to_f || 0
65
- end
66
-
67
- # decrement products quantity
68
- # return false if the quantity is not enough to be decremented
69
- def decrement_qty(qty)
70
- val = (the_qty_real - qty).to_i
71
- if val >= 0
72
- object.update_field_value('ecommerce_qty', val)
73
- true
106
+ def the_qty_real(variation_id = nil)
107
+ if h.current_user
108
+ Plugins::Ecommerce::UserProductService.new(
109
+ h.current_site, h.current_user, object, variation_id).available_qty
74
110
  else
75
- false
111
+ Plugins::Ecommerce::ProductService.new(
112
+ h.current_site, object, variation_id).available_qty
76
113
  end
77
114
  end
78
115
 
79
116
  # check if there are enough products to be purchased
80
- def can_added?(qty)
81
- val = (the_qty_real - qty).to_i
82
- val >= 0
117
+ def can_added?(qty, variation_id = nil)
118
+ (the_qty_real(variation_id) - qty).to_i >= 0
83
119
  end
84
120
 
85
121
  def self.object_class_name
86
122
  'CamaleonCms::Post'
87
123
  end
124
+
125
+ # verify if current product needs a variation id to be purchased
126
+ # return true/false
127
+ def valid_variation?(variation_id = nil)
128
+ if self.product_variations.any?
129
+ self.product_variations.where(id: variation_id).any?
130
+ else
131
+ true
132
+ end
133
+ end
134
+
135
+ # check if current product is a variation product
136
+ def is_variation_product?
137
+ @_cache_is_variation_product ||= self.product_variations.any?
138
+ end
88
139
  end
@@ -1,18 +1,42 @@
1
1
  class Plugins::Ecommerce::ProductItemDecorator < Draper::Decorator
2
2
  delegate_all
3
+ def the_title
4
+ get_product.the_variation_title(object.variation_id)
5
+ end
6
+
3
7
  def the_sub_total
4
8
  "#{h.current_site.current_unit}#{sprintf('%.2f', object.sub_total)}"
5
9
  end
6
10
 
7
11
  def the_price
8
- product.decorate.the_price
12
+ get_product.the_price(object.variation_id)
9
13
  end
10
14
 
11
15
  def the_tax
12
- product.decorate.the_tax
16
+ get_product.the_tax(object.variation_id)
13
17
  end
14
18
 
15
19
  def price
16
- product.decorate.price
20
+ get_product.price(object.variation_id)
21
+ end
22
+
23
+ def get_product
24
+ @_get_product ||= object.product.decorate
25
+ end
26
+
27
+ # return a product variation by id
28
+ def get_variation
29
+ @_get_variation ||= self.product_variation.decorate
30
+ end
31
+
32
+ # update quantity of product or product variation used in current cart item
33
+ def decrement_qty!
34
+ Plugins::Ecommerce::ProductItemService.new(object.cart.site, object).decrement_qty!
35
+ end
36
+
37
+ # verify if the quantity of the cart item is avilable
38
+ # return true if quantity is available
39
+ def is_valid_qty?
40
+ (get_product.the_qty_real(object.variation_id) - object.qty).to_i >= 0
17
41
  end
18
42
  end
@@ -0,0 +1,18 @@
1
+ class Plugins::Ecommerce::ProductVariationDecorator < Draper::Decorator
2
+ delegate_all
3
+ def the_price
4
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.amount)}"
5
+ end
6
+
7
+ def the_title
8
+ get_product.the_variation_title(object.id)
9
+ end
10
+
11
+ def the_weight
12
+ "#{h.current_site.current_weight} #{object.weight}"
13
+ end
14
+
15
+ def get_product
16
+ @_cache_get_product ||= object.product.decorate
17
+ end
18
+ end
@@ -2,7 +2,8 @@ module Plugins::Ecommerce::EcommerceEmailHelper
2
2
  include CamaleonCms::EmailHelper
3
3
 
4
4
  def mark_order_like_received(cart, status = 'paid')
5
- order = cart.make_paid!(status)
5
+ cart_service = Plugins::Ecommerce::CartService.new(current_site, cart)
6
+ order = cart_service.convert_to_order(status)
6
7
 
7
8
  # send email to buyer
8
9
  commerce_send_order_received_email(order)
@@ -12,6 +13,8 @@ module Plugins::Ecommerce::EcommerceEmailHelper
12
13
 
13
14
  flash[:notice] = t('plugins.ecommerce.messages.payment_completed', default: "Payment completed successfully")
14
15
  args = {order: order}; hooks_run("commerce_after_payment_completed", args)
16
+
17
+ order
15
18
  end
16
19
 
17
20
  def commerce_send_order_received_email(order, is_after_bank_confirmation = false)
@@ -64,10 +67,10 @@ module Plugins::Ecommerce::EcommerceEmailHelper
64
67
  def ecommerce_verify_cart_errors(cart)
65
68
  errors = []
66
69
  # products verification
67
- cart.product_items.each do |item|
68
- product = item.product.decorate
69
- unless product.decrement_qty(item.qty)
70
- errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_title, qty: product.the_qty_real, default: 'There is not enough products "%{product}" (%{qty})')
70
+ cart.product_items.decorate.each do |item|
71
+ unless item.is_valid_qty?
72
+ product = item.product.decorate
73
+ errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_title, qty: product.the_qty_real, default: 'There is not enough products "%{product}" (Available %{qty})')
71
74
  end
72
75
  end
73
76
 
@@ -95,14 +98,9 @@ module Plugins::Ecommerce::EcommerceEmailHelper
95
98
  :total_cost => order.cache_the_total,
96
99
  :order => order
97
100
  }
98
- files = []
99
- owners = []
100
- order.products.each do |product|
101
- files += product.get_fields('ecommerce_files').map{|f| CamaleonCmsLocalUploader::private_file_path(f, current_site) }
102
- owners << product.owner if product.owner.present?
103
- end
104
- data[:owners] = owners.uniq
105
- data[:files] = files.uniq
101
+ order_service = Plugins::Ecommerce::OrderService.new(current_site, order)
102
+ data[:owners] = order_service.product_owners
103
+ data[:files] = order_service.product_files
106
104
  data
107
105
  end
108
106
 
@@ -1,15 +1,7 @@
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
  #encoding: utf-8
10
2
  module Plugins::Ecommerce::EcommerceFunctionsHelper
11
3
  def self.included(klass)
12
- klass.helper_method [:e_get_currency_units, :e_get_currency_weight, :e_symbol_by_code] rescue ""
4
+ klass.helper_method [:e_get_currency_units, :e_get_currency_weight, :e_symbol_by_code, :ecommerce_custom_payment_methods] rescue ""
13
5
  end
14
6
  def e_get_currency_weight
15
7
  r = {}
@@ -21,8 +13,11 @@ module Plugins::Ecommerce::EcommerceFunctionsHelper
21
13
  end
22
14
 
23
15
  def e_get_currency_units
24
- file = File.read("#{File.dirname(__FILE__)}/../../../../config/currency_#{I18n.locale.to_s}.json")
25
- @e_get_currency_units ||= JSON.parse(file)
16
+ @e_get_currency_units ||= lambda{
17
+ file = File.read("#{File.dirname(__FILE__)}/../../../../config/currency.json")
18
+ args = {currencies: JSON.parse(file)}; hooks_run("ecommerce_currencies", args)
19
+ args[:currencies]
20
+ }.call
26
21
  end
27
22
 
28
23
  def e_symbol_by_code(unit)
@@ -46,4 +41,23 @@ module Plugins::Ecommerce::EcommerceFunctionsHelper
46
41
  post.metas.map{|m| metas[m.key] = m.value }
47
42
  data.merge(post: attributes, fields: post.get_field_values_hash, meta: metas)
48
43
  end
44
+
45
+ def ecommerce_custom_payment_methods
46
+ @_ecommerce_custom_payment_methods ||= lambda{
47
+ args = {custom_payment_methods: {}}; hooks_run("ecommerce_custom_payment_methods", args)
48
+ # Sample:
49
+ # def my_callback(args)
50
+ # args[:custom_payment_methods][:pay_u] = {
51
+ # title: 'Pay U',
52
+ # settings_view_path: '/my_plugin/views/payu/settings', # view must be like this: <div class="form-group"> <label>Key</label><br> <%= text_field_tag('options[payu_key]', options[:payu_key], class: 'form-control required') %> </div>
53
+ # payment_form_view_path: '/my_plugin/views/payu/payment_form',
54
+ # # view must include the payment form with your custom routes to process the payment,
55
+ # # sample: https://github.com/owen2345/camaleon-ecommerce/blob/master/app/controllers/plugins/ecommerce/front/checkout_controller.rb#L120
56
+ # # https://github.com/owen2345/camaleon-ecommerce/blob/master/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb#L104
57
+ # }
58
+ # end
59
+ args[:custom_payment_methods]
60
+ }.call
61
+ end
62
+
49
63
  end
@@ -1,35 +1,19 @@
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
  module Plugins::Ecommerce::EcommerceHelper
10
2
  include Plugins::Ecommerce::EcommerceEmailHelper
11
3
 
12
- def ecommerce_on_render_post(d)
13
-
14
- end
15
-
16
- def ecommerce_on_render_post_type(d)
17
-
18
- end
19
-
20
4
  def ecommerce_admin_list_post(d)
21
-
22
5
  end
23
6
 
24
- def ecommerce_form_post(d)
25
- if d[:post_type].slug == 'commerce'
26
- append_asset_libraries({ecommerce: {css: [], js: [plugin_gem_asset('fix_form')]}})
7
+ def ecommerce_admin_product_form(args)
8
+ if args[:post_type].slug == 'commerce'
9
+ append_asset_libraries({ecommerce: {css: [], js: [plugin_asset_path('admin_product')]}})
10
+ args[:html] = render partial: plugin_view('admin/products/variations'), locals:{post_type: args[:post_type], product: args[:post] }
27
11
  end
28
12
  end
29
13
 
30
14
  def ecommerce_front_before_load
31
15
  @ecommerce_post_type = current_site.post_types.where(slug: 'commerce').first.decorate
32
- @ecommerce_bredcrumb = [].push(["Home", cama_root_url])
16
+ @ecommerce_breadcrumb = [].push(["Home", cama_root_url])
33
17
  end
34
18
 
35
19
  def ecommerce_admin_before_load
@@ -52,24 +36,19 @@ module Plugins::Ecommerce::EcommerceHelper
52
36
  items_i << {icon: "credit-card", title: t('plugin.ecommerce.payment_methods', default: 'Payment Methods'), url: admin_plugins_ecommerce_payment_methods_path}
53
37
  items_i << {icon: "tag", title: t('plugin.ecommerce.coupons', default: 'Coupons'), url: admin_plugins_ecommerce_coupons_path}
54
38
  items_i << {icon: "cogs", title: t('camaleon_cms.admin.button.settings', default: 'Settings'), url: admin_plugins_ecommerce_settings_path}
39
+ items_i << {icon: "cubes", title: t('plugin.ecommerce.product_attributes', default: 'Product Attributes'), url: admin_plugins_ecommerce_product_attributes_path}
55
40
  end
56
41
 
57
42
  admin_menu_insert_menu_after("content", "e-commerce", {icon: "shopping-cart", title: t('plugin.ecommerce.e_commerce', default: 'E-commerce'), url: "", items: items_i}) if items_i.present?
58
43
  end
59
-
60
- # add assets admin
61
- append_asset_libraries({ecommerce: {css: [plugin_gem_asset('admin')], js: []}})
62
-
63
44
  end
64
45
 
65
46
  def ecommerce_app_before_load
66
-
67
47
  end
68
48
 
69
49
  # here all actions on plugin destroying
70
50
  # plugin: plugin model
71
51
  def ecommerce_on_destroy(plugin)
72
-
73
52
  end
74
53
 
75
54
  # here all actions on going to active
@@ -86,6 +65,22 @@ module Plugins::Ecommerce::EcommerceHelper
86
65
  current_site.post_types.hidden_menu.where(slug: "commerce").first.destroy
87
66
  end
88
67
 
68
+ # callback after create/update
69
+ def ecommerce_admin_product_created(args)
70
+ if args[:post_type].slug == 'commerce'
71
+ params[:product_variation] ||= {}
72
+ args[:post].product_variations.where.not(id: params[:product_variation].keys).delete_all
73
+ params[:product_variation].each do |p_key, p_var|
74
+ 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(',')}
75
+ if p_key.include?('new_') # new variation
76
+ args[:post].product_variations.create(data)
77
+ else
78
+ args[:post].product_variations.find(p_key).update(data)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
89
84
  def get_commerce_post_type
90
85
  @ecommerce = current_site.post_types.hidden_menu.where(slug: "commerce").first
91
86
  unless @ecommerce.present?