camaleon_ecommerce 0.0.4 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/plugins/ecommerce/admin.js +0 -33
  3. data/app/assets/javascripts/plugins/ecommerce/cart.js +83 -200
  4. data/app/assets/javascripts/plugins/ecommerce/fix_form.js +1 -4
  5. data/app/assets/stylesheets/plugins/ecommerce/checkout.css.scss +46 -0
  6. data/app/assets/stylesheets/plugins/ecommerce/front.scss +2 -30
  7. data/app/controllers/plugins/ecommerce/admin/coupons_controller.rb +2 -2
  8. data/app/controllers/plugins/ecommerce/admin/orders_controller.rb +45 -34
  9. data/app/controllers/plugins/ecommerce/admin/payment_methods_controller.rb +4 -3
  10. data/app/controllers/plugins/ecommerce/admin/prices_controller.rb +5 -5
  11. data/app/controllers/plugins/ecommerce/admin/settings_controller.rb +0 -2
  12. data/app/controllers/plugins/ecommerce/admin/shipping_methods_controller.rb +3 -3
  13. data/app/controllers/plugins/ecommerce/admin/tax_rates_controller.rb +2 -2
  14. data/app/controllers/plugins/ecommerce/admin_controller.rb +1 -1
  15. data/app/controllers/plugins/ecommerce/front/checkout_controller.rb +162 -110
  16. data/app/controllers/plugins/ecommerce/front/orders_controller.rb +7 -234
  17. data/app/controllers/plugins/ecommerce/front_controller.rb +42 -3
  18. data/app/decorators/plugins/ecommerce/cart_decorator.rb +27 -0
  19. data/app/{models → decorators}/plugins/ecommerce/coupon_decorator.rb +1 -1
  20. data/app/decorators/plugins/ecommerce/order_decorator.rb +22 -0
  21. data/app/decorators/plugins/ecommerce/product_decorator.rb +88 -0
  22. data/app/decorators/plugins/ecommerce/product_item_decorator.rb +18 -0
  23. data/app/helpers/plugins/ecommerce/ecommerce_email_helper.rb +91 -28
  24. data/app/helpers/plugins/ecommerce/ecommerce_helper.rb +30 -136
  25. data/app/helpers/plugins/ecommerce/ecommerce_payment_helper.rb +14 -20
  26. data/app/models/plugins/ecommerce/cart.rb +139 -15
  27. data/app/models/plugins/ecommerce/coupon.rb +33 -7
  28. data/app/models/plugins/ecommerce/order.rb +47 -31
  29. data/app/models/plugins/ecommerce/{product.rb → product_item.rb} +11 -5
  30. data/app/views/camaleon_cms/html_mailer/order_canceled.html.erb +2 -0
  31. data/app/views/camaleon_cms/html_mailer/order_confirmed.html.erb +2 -0
  32. data/app/views/camaleon_cms/html_mailer/order_received_admin.html.erb +1 -1
  33. data/app/views/camaleon_cms/html_mailer/order_shipped.html.erb +2 -0
  34. data/app/views/plugins/ecommerce/admin/coupons/form.html.erb +10 -10
  35. data/app/views/plugins/ecommerce/admin/coupons/index.html.erb +1 -1
  36. data/app/views/plugins/ecommerce/admin/orders/form.html.erb +5 -49
  37. data/app/views/plugins/ecommerce/admin/orders/index.html.erb +140 -80
  38. data/app/views/plugins/ecommerce/admin/orders/show.html.erb +7 -169
  39. data/app/views/plugins/ecommerce/admin/payment_methods/form.html.erb +30 -3
  40. data/app/views/plugins/ecommerce/admin/payment_methods/index.html.erb +1 -3
  41. data/app/views/plugins/ecommerce/admin/prices/index.html.erb +0 -2
  42. data/app/views/plugins/ecommerce/admin/prices/show.html.erb +0 -2
  43. data/app/views/plugins/ecommerce/admin/products/index.html.erb +1 -1
  44. data/app/views/plugins/ecommerce/admin/settings/index.html.erb +0 -1
  45. data/app/views/plugins/ecommerce/admin/tax_rates/form.html.erb +1 -1
  46. data/app/views/plugins/ecommerce/front/checkout/cart_index.html.erb +46 -57
  47. data/app/views/plugins/ecommerce/front/checkout/index.html.erb +34 -158
  48. data/app/views/plugins/ecommerce/front/login.html.erb +67 -0
  49. data/app/views/plugins/ecommerce/front/orders/index.html.erb +36 -44
  50. data/app/views/plugins/ecommerce/front/orders/show.html.erb +121 -67
  51. data/app/views/plugins/ecommerce/partials/_cart_widget.html.erb +38 -0
  52. data/app/views/plugins/ecommerce/partials/checkout/_details.html.erb +35 -0
  53. data/app/views/plugins/ecommerce/partials/checkout/_payments.html.erb +123 -0
  54. data/app/views/plugins/ecommerce/partials/checkout/_products_detail.html.erb +49 -0
  55. data/app/views/plugins/ecommerce/partials/checkout/_user_info.html.erb +93 -0
  56. data/app/views/post_types/commerce.html.erb +22 -0
  57. data/app/views/post_types/commerce/_product_widget.html.erb +13 -0
  58. data/app/views/post_types/commerce/category.html.erb +23 -0
  59. data/app/views/post_types/commerce/single.html.erb +91 -0
  60. data/config/custom_models.rb +24 -57
  61. data/config/locales/en.yml +192 -0
  62. data/config/locales/es.yml +405 -0
  63. data/config/routes.rb +26 -16
  64. data/db/migrate/20160502221327_add_cama_ecommerce_structure_plugin.rb +12 -0
  65. data/db/migrate/20160504162311_move_featured_attribute_of_products.rb +15 -0
  66. data/db/migrate/20160527184747_add_new_cart_structure.rb +21 -0
  67. data/lib/ecommerce/version.rb +1 -1
  68. metadata +42 -19
  69. data/app/models/plugins/ecommerce/order_decorator.rb +0 -54
  70. data/app/views/layouts/plugins/ecommerce/mailer.html.erb +0 -22
  71. data/app/views/plugins/ecommerce/admin/index.html.erb +0 -2
  72. data/app/views/plugins/ecommerce/front/_post_list_item.html.erb +0 -18
  73. data/app/views/plugins/ecommerce/front/index.html.erb +0 -2
  74. data/app/views/plugins/ecommerce/front/list_products.html.erb +0 -34
  75. data/app/views/plugins/ecommerce/front/orders/pay_by_bank_transfer.html.erb +0 -67
  76. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card.html.erb +0 -131
  77. data/app/views/plugins/ecommerce/front/orders/pay_by_credit_card_authorize_net.erb +0 -150
  78. data/app/views/plugins/ecommerce/front/orders/select_payment.html.erb +0 -70
  79. data/app/views/plugins/ecommerce/front/product.html.erb +0 -105
  80. data/app/views/plugins/ecommerce/layouts/_ecommerce.html.erb +0 -41
  81. data/app/views/plugins/ecommerce/partials/_form_address.html.erb +0 -84
  82. data/app/views/plugins/ecommerce/partials/_table_order_products.html.erb +0 -85
  83. data/config/locales/translation.yml +0 -371
@@ -7,249 +7,22 @@
7
7
  See the GNU Affero General Public License (GPLv3) for more details.
8
8
  =end
9
9
  class Plugins::Ecommerce::Front::OrdersController < Plugins::Ecommerce::FrontController
10
-
11
-
10
+ before_action :commerce_authenticate
11
+ before_action :set_bread
12
12
  def index
13
- @ecommerce_bredcrumb << ["Orders"]
14
- @orders = current_site.orders.set_user(current_user).all
13
+ @orders = current_site.orders.set_user(current_user).decorate
14
+ render "index"
15
15
  end
16
16
 
17
17
  def show
18
18
  @order = current_site.orders.find_by_slug(params[:order]).decorate
19
- @ecommerce_bredcrumb << ["Orders", url_for(action: :index)]
20
- @ecommerce_bredcrumb << ["Detail Order: #{params[:order]}"]
21
- end
22
-
23
- def res_coupon
24
- coupon = current_site.coupons.find_by_slug(params[:code].to_s.parameterize)
25
- error = false
26
- if coupon.nil?
27
- error = 'Not Found Coupon'
28
- elsif "#{coupon.options[:expirate_date]} 23:59:59".to_time.to_i < Time.now.to_i
29
- error = 'Coupon Expired'
30
- elsif coupon.status != '1'
31
- error = 'Coupon not active'
32
- end
33
- if error
34
- render json: {error: error}
35
- else
36
- coupon = coupon.decorate
37
- render json: {data: {text: "#{coupon.the_amount}", options: coupon.options, code: coupon.slug, current_unit: current_site.current_unit}}
38
- end
19
+ @ecommerce_bredcrumb << [t('plugins.ecommerce.messages.detail_order', default: "Detail order: #%{order}", order: params[:order])]
39
20
  end
40
21
 
41
- def select_payment
42
- @order = current_site.orders.find_by_slug(params[:order])
43
- if params[:cancel].present?
44
- @order.update({status: 'canceled'})
45
- @order.details.update({closed_at: Time.now})
46
- flash[:notice] = "Canceled Order"
47
- redirect_to action: :index
48
- end
49
- @ecommerce_bredcrumb << ["Orders", url_for(action: :index)]
50
- @ecommerce_bredcrumb << ["Payment Order: #{params[:order]}"]
51
- end
52
22
 
53
- def set_select_payment
54
- @order = current_site.orders.find_by_slug(params[:order])
55
- @order.set_meta("payment", @order.get_meta("payment", {}).merge(params[:payment] || {}))
56
- redirect_to plugins_ecommerce_order_pay_path(order: @order.slug)
57
- end
58
-
59
- def pay
60
- @order = current_site.orders.find_by_slug(params[:order])
61
- @ecommerce_bredcrumb << ["Orders", url_for(action: :index)]
62
- if @order.get_meta("payment", {})[:type] == 'paypal'
63
- pay_by_paypal
64
- elsif @order.get_meta("payment", {})[:type] == 'credit_card'
65
- @payment_methods = current_site.payment_methods.find(@order.get_meta("payment", {})[:payment_id])
66
- @ecommerce_bredcrumb << ["Payment by Credit Card"]
67
- render 'pay_by_credit_card'
68
- elsif @order.get_meta("payment", {})[:type] == 'authorize_net'
69
- @payment_methods = current_site.payment_methods.find(@order.get_meta("payment", {})[:payment_id])
70
- @ecommerce_bredcrumb << ['Payment by Credit Card']
71
- render 'pay_by_credit_card_authorize_net'
72
- else
73
- @payment_methods = current_site.payment_methods.find(@order.get_meta("payment", {})[:payment_id])
74
- @ecommerce_bredcrumb << ["Payment by Bank Transfer"]
75
- render 'pay_by_bank_transfer'
76
- end
77
- end
78
-
79
- def pay_by_bank_transfer
80
- @order = current_site.orders.find_by_slug(params[:order])
81
- @order.set_meta("pay_bank_transfer", params[:details])
82
- mark_order_like_received(@order)
83
- flash[:notice] = "Updated Pay"
84
- redirect_to action: :index
85
- end
86
-
87
- def pay_by_credit_card
88
- @order = current_site.orders.find_by_slug(params[:order])
89
- res = pay_by_credit_card_run
90
- if res[:error].present?
91
- @error = res[:error]
92
- @payment_methods = current_site.payment_methods.find(@order.get_meta("payment", {})[:payment_id])
93
- render 'pay_by_credit_card'
94
- else
95
- @order.set_meta('pay_credit_card', params)
96
- mark_order_like_received(@order)
97
- flash[:notice] = 'Updated Pay'
98
- redirect_to action: :index
99
- end
100
- end
101
-
102
- def pay_by_credit_card_authorize_net
103
- @order = current_site.orders.find_by_slug(params[:order])
104
- res = payment_pay_by_credit_card_authorize_net(@order)
105
- if res[:error].present?
106
- @error = res[:error]
107
- @payment_methods = current_site.payment_methods.find(@order.get_meta("payment", {})[:payment_id])
108
- render 'pay_by_credit_card_authorize_net'
109
- else
110
- flash[:notice] = 'Updated Pay'
111
- redirect_to action: :index
112
- end
113
- end
114
-
115
- def success
116
- @order = current_site.orders.find_by_slug(params[:order])
117
- @order.set_meta('pay_paypal', {token: params[:token], PayerID: params[:PayerID]})
118
- mark_order_like_received(@order)
119
- flash[:notice] = 'Updated Pay'
120
- redirect_to action: :index
121
- end
122
-
123
- def cancel
124
- #@order = current_site.orders.find_by_slug(params[:order])
125
- flash[:notice] = 'Cancel Pay by Paypal'
126
- redirect_to action: :index
127
- end
128
23
 
129
24
  private
130
-
131
-
132
- def pay_by_credit_card_run
133
- payment = @order.get_meta("payment", {})
134
- billing_address = @order.get_meta("billing_address")
135
- details = @order.get_meta("details")
136
- @payment_method = current_site.payment_methods.find(payment[:payment_id])
137
-
138
- @params = {
139
- :order_id => @order.slug,
140
- :currency => current_site.currency_code,
141
- :email => details[:email],
142
- :billing_address => {:name => "#{billing_address[:first_name]} #{billing_address[:last_name]}",
143
- :address1 => billing_address[:address1],
144
- :address2 => billing_address[:address2],
145
- :city => billing_address[:city],
146
- :state => billing_address[:state],
147
- :country => billing_address[:country],
148
- :zip => billing_address[:zip]
149
- },
150
- :description => 'Buy Products',
151
- :ip => request.remote_ip
152
- }
153
-
154
- @amount = to_cents(payment[:amount].to_f)
155
-
156
- paypal_options = {
157
- :login => @payment_method.options[:cc_paypal_login],
158
- :password => @payment_method.options[:cc_paypal_password],
159
- :signature => @payment_method.options[:cc_paypal_signature]
160
- }
161
-
162
- ActiveMerchant::Billing::Base.mode = @payment_method.options[:cc_paypal_sandbox].to_s.to_bool ? :test : :production
163
- @gateway = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
164
-
165
- @credit_card = ActiveMerchant::Billing::CreditCard.new(
166
- :first_name => params[:firstName],
167
- :last_name => params[:lastName],
168
- :number => params[:cardNumber],
169
- :month => params[:expMonth],
170
- :year => "20#{params[:expYear]}",
171
- :verification_value => params[:cvCode])
172
-
173
- if @credit_card.validate.empty?
174
- puts "--#{@params.inspect}--"
175
- response = @gateway.verify(@credit_card, @params)
176
- #response = @gateway.purchase(@amount, @credit_card, @params)
177
- if response.success?
178
- return {success: 'Paid Correct'} #puts "Successfully charged $#{sprintf("%.2f", @amount / 100)} to the credit card #{@credit_card.display_number}"
179
- else
180
- return {error: response.message} #raise StandardError, response.message
181
- end
182
- else
183
- return {error: "Credit Card Invalid"}
184
- end
25
+ def set_bread
26
+ @ecommerce_bredcrumb << [t('plugins.ecommerce.messages.my_orders', default: 'My Orders'), url_for(action: :index)]
185
27
  end
186
-
187
- def pay_by_paypal
188
- payment = @order.get_meta("payment", {})
189
- billing_address = @order.get_meta("billing_address")
190
- details = @order.get_meta("details")
191
- @payment_method = current_site.payment_methods.find(payment[:payment_id])
192
-
193
- ActiveMerchant::Billing::Base.mode = @payment_method.options[:paypal_sandbox].to_s.to_bool ? :test : :production
194
- paypal_options = {
195
- :login => @payment_method.options[:paypal_login],
196
- :password => @payment_method.options[:paypal_password],
197
- :signature => @payment_method.options[:paypal_signature]
198
- }
199
-
200
- @gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
201
-
202
- #subtotal, shipping, total, tax = get_totals(payment)
203
- @options = {
204
- brand_name: current_site.name,
205
-
206
- #allow_guest_checkout: true,
207
- #items: get_items(@order.meta[:products]),
208
-
209
- items: [{number: @order.slug, name: 'Buy Products', amount: to_cents(payment[:amount].to_f)}],
210
- :order_id => @order.slug,
211
- :currency => current_site.currency_code,
212
- :email => details[:email],
213
- :billing_address => {:name => "#{billing_address[:first_name]} #{billing_address[:last_name]}",
214
- :address1 => billing_address[:address1],
215
- :address2 => billing_address[:address2],
216
- :city => billing_address[:city],
217
- :state => billing_address[:state],
218
- :country => billing_address[:country],
219
- :zip => billing_address[:zip]
220
- },
221
- :description => 'Buy Products',
222
- :ip => request.remote_ip,
223
- :return_url => plugins_ecommerce_order_success_url(order: @order.slug),
224
- :cancel_return_url => plugins_ecommerce_order_cancel_url(order: @order.slug)
225
- }
226
-
227
- response = @gateway.setup_purchase(to_cents(payment[:amount].to_f), @options)
228
-
229
- redirect_to @gateway.redirect_url_for(response.token)
230
- end
231
-
232
- def get_items(products)
233
- products.collect do |key, product|
234
- {
235
- :name => product[:product_title],
236
- :number => product[:product_id],
237
- :quantity => product[:qty],
238
- :amount => to_cents(product[:price].to_f),
239
- }
240
- end
241
- end
242
-
243
- def get_totals(payment)
244
- tax = payment[:tax_total].to_f
245
- subtotal = payment[:sub_total].to_f
246
- shipping = payment[:weight_price].to_f + payment[:sub_total].to_f
247
- total = subtotal + shipping
248
- return subtotal, shipping, total, tax
249
- end
250
-
251
- def to_cents(money)
252
- (money*100).round
253
- end
254
-
255
28
  end
@@ -7,12 +7,51 @@
7
7
  See the GNU Affero General Public License (GPLv3) for more details.
8
8
  =end
9
9
  class Plugins::Ecommerce::FrontController < CamaleonCms::Apps::PluginsFrontController
10
+ include Plugins::Ecommerce::EcommercePaymentHelper
10
11
  before_action :ecommerce_add_assets_in_front
11
- def index
12
- # here your actions for frontend module
12
+ before_action :save_cache_redirect, only: [:login, :register]
13
+ def login
14
+ @user ||= current_site.users.new
15
+ render 'login'
13
16
  end
14
17
 
15
- def product
18
+ def do_login
19
+ if login_user_with_password(params[:username], params[:password])
20
+ login_user(@user, false, (cookies[:return_to] || plugins_ecommerce_orders_path))
21
+ return cookies.delete(:return_to)
22
+ else
23
+ flash[:error] = t('plugins.ecommerce.messages.invalid_access', default: 'Invalid access')
24
+ return login
25
+ end
26
+ end
27
+
28
+ def register
29
+ params[:kind_form] = 'register-form'
30
+ @user ||= current_site.users.new
31
+ render 'login'
32
+ end
33
+
34
+ def do_register
35
+ @user = current_site.users.new(params.require(:camaleon_cms_user).permit(:first_name, :last_name, :username, :email, :password, :password_confirmation))
36
+ if @user.save
37
+ flash[:notice] = t('plugins.ecommerce.messages.created_account', default: "Account created successfully")
38
+ login_user(@user, false, (cookies[:return_to] || plugins_ecommerce_orders_path))
39
+ return cookies.delete(:return_to)
40
+ else
41
+ return register
42
+ end
43
+ end
44
+
45
+ private
46
+ def save_cache_redirect
47
+ cookies[:return_to] = params[:return_to] if params[:return_to].present?
48
+ end
16
49
 
50
+ def commerce_authenticate
51
+ unless cama_sign_in?
52
+ flash[:error] = t('camaleon_cms.admin.login.please_login')
53
+ cookies[:return_to] = request.referer
54
+ redirect_to plugins_ecommerce_login_path
55
+ end
17
56
  end
18
57
  end
@@ -0,0 +1,27 @@
1
+ class Plugins::Ecommerce::CartDecorator < Draper::Decorator
2
+ delegate_all
3
+ def the_sub_total
4
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.sub_total)}"
5
+ end
6
+
7
+ def the_total_discounts
8
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.total_discounts)}"
9
+ end
10
+
11
+ def the_total_amount
12
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.total_amount)}"
13
+ end
14
+ alias_method :the_price, :the_total_amount
15
+
16
+ def the_tax_total
17
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.tax_total)}"
18
+ end
19
+
20
+ def the_weight_total
21
+ "#{h.current_site.current_weight} #{sprintf('%.2f', object.weight_total)}"
22
+ end
23
+
24
+ def the_total_shipping
25
+ "#{h.current_site.current_unit}#{sprintf('%.2f', object.total_shipping)}"
26
+ end
27
+ end
@@ -28,7 +28,7 @@ class Plugins::Ecommerce::CouponDecorator < CamaleonCms::TermTaxonomyDecorator
28
28
  when 'percent'
29
29
  "#{opts[:amount].to_f}%"
30
30
  when 'money'
31
- "#{the_symbol} #{opts[:amount].to_f}"
31
+ "#{h.current_site.current_unit}#{opts[:amount].to_f}"
32
32
  else
33
33
  "Free"
34
34
  end
@@ -0,0 +1,22 @@
1
+ class Plugins::Ecommerce::OrderDecorator < Draper::Decorator
2
+ delegate_all
3
+
4
+ def the_status(include_date_action = false)
5
+ res = if object.bank_pending?
6
+ "<span class='label label-warning'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>"
7
+ elsif object.canceled?
8
+ "<span class='label label-danger'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>"
9
+ else
10
+ "<span class='label label-success'>#{h.t("plugins.ecommerce.messages.order_status.#{object.status}", default: object.status.titleize)}</span>"
11
+ end
12
+ res = "#{res} #{object.action_date}" if include_date_action
13
+ res
14
+ end
15
+
16
+ def the_url_tracking
17
+ if object.shipped?
18
+ consignment_number = object.get_meta("consignment_number")
19
+ _url = object.shipping_method.options[:url_tracking].gsub("{{consignment_number}}", consignment_number) rescue ''
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,88 @@
1
+ class Plugins::Ecommerce::ProductDecorator < CamaleonCms::PostDecorator
2
+ def the_sku
3
+ object.get_field_value('ecommerce_sku').to_s
4
+ end
5
+ def the_price
6
+ "#{h.current_site.current_unit}#{sprintf('%.2f', price)}"
7
+ end
8
+ def the_weight
9
+ "#{h.current_site.current_weight} #{weight}"
10
+ end
11
+ def weight
12
+ object.get_field_value('ecommerce_weight').to_f || 0
13
+ end
14
+ def the_qty
15
+ object.get_field_value('ecommerce_qty') || 0
16
+ end
17
+ def the_photos
18
+ object.get_field_values('ecommerce_photos') || []
19
+ end
20
+ def in_stock?
21
+ object.get_field_value('ecommerce_stock').to_s.to_bool
22
+ end
23
+
24
+ def price
25
+ object.get_field_value(:ecommerce_price).to_f || 0
26
+ end
27
+
28
+ def the_tax
29
+ tax
30
+ end
31
+
32
+ def tax
33
+ tax_rate_id = object.get_field_value(:ecommerce_tax)
34
+ if tax_rate_id.present?
35
+ percent = h.current_site.tax_rates.find(tax_rate_id).options[:rate].to_f rescue 0
36
+ price * percent / 100
37
+ else # tax not defined
38
+ 0
39
+ end
40
+ end
41
+
42
+ def the_stock_status
43
+ if in_stock? && the_qty_real.to_i > 0
44
+ "<span class='label label-success'>#{I18n.t('plugin.ecommerce.product.in_stock')}</span>"
45
+ else
46
+ "<span class='label label-danger'>#{I18n.t('plugin.ecommerce.product.not_in_tock')}</span>"
47
+ end
48
+ end
49
+
50
+ def eco_featured?
51
+ object.get_field_value('ecommerce_featured').to_s.to_bool
52
+ end
53
+
54
+ def the_featured_status
55
+ if eco_featured?
56
+ "<span class='label label-primary'>#{I18n.t('plugin.ecommerce.product.featured')}</span>"
57
+ else
58
+ ""
59
+ end
60
+ end
61
+
62
+ # 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
74
+ else
75
+ false
76
+ end
77
+ end
78
+
79
+ # 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
83
+ end
84
+
85
+ def self.object_class_name
86
+ 'CamaleonCms::Post'
87
+ end
88
+ end