spree_frontend 2.1.12 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/{store → spree/frontend}/cart.png +0 -0
  3. data/app/assets/images/{store → spree/frontend}/select_arrow.gif +0 -0
  4. data/app/assets/javascripts/spree/frontend.js +5 -0
  5. data/app/assets/javascripts/{store → spree/frontend}/cart.js.coffee +7 -1
  6. data/app/assets/javascripts/spree/frontend/checkout.js.coffee +11 -0
  7. data/app/assets/javascripts/{store/checkout.js.coffee → spree/frontend/checkout/address.js.coffee} +12 -40
  8. data/app/assets/javascripts/spree/frontend/checkout/payment.js.coffee +64 -0
  9. data/app/assets/javascripts/{store → spree/frontend}/product.js.coffee +2 -3
  10. data/app/assets/stylesheets/{store/spree_frontend.css → spree/frontend.css} +1 -1
  11. data/app/assets/stylesheets/{store → spree/frontend}/_variables.scss +0 -0
  12. data/app/assets/stylesheets/{store → spree/frontend}/screen.css.scss +37 -4
  13. data/app/controllers/spree/checkout_controller.rb +2 -44
  14. data/app/controllers/spree/content_controller.rb +1 -6
  15. data/app/controllers/spree/home_controller.rb +1 -0
  16. data/app/controllers/spree/orders_controller.rb +14 -25
  17. data/app/controllers/spree/products_controller.rb +5 -22
  18. data/app/controllers/spree/store_controller.rb +23 -0
  19. data/app/controllers/spree/taxons_controller.rb +1 -0
  20. data/app/views/spree/checkout/_address.html.erb +2 -0
  21. data/app/views/spree/checkout/_delivery.html.erb +1 -1
  22. data/app/views/spree/checkout/_payment.html.erb +4 -6
  23. data/app/views/spree/checkout/_summary.html.erb +41 -15
  24. data/app/views/spree/checkout/edit.html.erb +6 -2
  25. data/app/views/spree/checkout/payment/_gateway.html.erb +7 -3
  26. data/app/views/spree/content/test.html.erb +1 -0
  27. data/app/views/spree/home/index.html.erb +3 -1
  28. data/app/views/spree/orders/_adjustment_row.html.erb +6 -0
  29. data/app/views/spree/orders/_adjustments.html.erb +19 -9
  30. data/app/views/spree/orders/_form.html.erb +13 -1
  31. data/app/views/spree/orders/_line_item.html.erb +1 -1
  32. data/app/views/spree/orders/edit.html.erb +14 -18
  33. data/app/views/spree/payments/_payment.html.erb +15 -0
  34. data/app/views/spree/products/_cart_form.html.erb +11 -10
  35. data/app/views/spree/products/index.html.erb +3 -1
  36. data/app/views/spree/products/show.html.erb +34 -32
  37. data/app/views/spree/shared/_frontend_routes.html.erb +3 -0
  38. data/app/views/spree/shared/_google_analytics.html.erb +7 -7
  39. data/app/views/spree/shared/_head.html.erb +3 -2
  40. data/app/views/spree/shared/_link_to_cart.html.erb +1 -0
  41. data/app/views/spree/shared/_main_nav_bar.html.erb +7 -1
  42. data/app/views/spree/shared/_order_details.html.erb +40 -14
  43. data/app/views/spree/shared/_products.html.erb +8 -5
  44. data/app/views/spree/shared/_search.html.erb +6 -4
  45. data/app/views/spree/shared/_taxonomies.html.erb +5 -3
  46. data/app/views/spree/store/cart_link.html.erb +1 -0
  47. data/app/views/spree/taxons/show.html.erb +6 -5
  48. data/config/routes.rb +1 -0
  49. data/lib/spree/frontend.rb +0 -7
  50. data/lib/spree/frontend/engine.rb +1 -2
  51. data/lib/spree/frontend/preference_rescue.rb +25 -0
  52. metadata +25 -16
  53. data/app/assets/javascripts/store/spree_frontend.js +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cc8aeaf94e1bce4df9c73c960efc855f8f8c21b
4
- data.tar.gz: 30f0b3554add427e0650f90025fbfe836866f357
3
+ metadata.gz: 29db93da707c1bbb9a6ef087863995df92f50c94
4
+ data.tar.gz: aba8daaa326750b739f5166436c7dc176612b931
5
5
  SHA512:
6
- metadata.gz: aa8a3a7f040b1287bea24efac679b7eb1c01c6df8c0a8c32ef2f0f048ea19485e0985cfd207f1719196050551957ec133552ea8fd59af3e38efbf4ac0893a062
7
- data.tar.gz: c463b0ab120a3fbaf955047d94835c1d4702ce186129fcbe4b75a9c3c57833e735e515c1d1a3d5334171b12aa266bc09b06664b75ffef5ae561fc1ec6136fd29
6
+ metadata.gz: b58abca47b3506fe2dfee3c2d96e79c3adb1fd2e5d5b3d5dc3cfc974a0170f1ff6c5e0afaa5cea35175dd174adea1036f1ae5fb26a22e7993953a7d717d97fe8
7
+ data.tar.gz: 447914326a17b8c14bfa48a7a6f276913e240f0c21516e4ff3d1fc37920c4bc60a87b9263c2f0eb9cdc221f6c6cbb3f51d99694b3a81e2da0efae6ea239c1ab4
@@ -0,0 +1,5 @@
1
+ //= require jquery.validate/jquery.validate.min
2
+ //= require spree
3
+ //= require spree/frontend/checkout
4
+ //= require spree/frontend/product
5
+ //= require spree/frontend/cart
@@ -6,4 +6,10 @@ Spree.ready ($) ->
6
6
  false
7
7
 
8
8
  ($ 'form#update-cart').submit ->
9
- ($ 'form#update-cart #update-button').attr('disabled', true)
9
+ ($ 'form#update-cart #update-button').attr('disabled', true)
10
+
11
+ Spree.fetch_cart = ->
12
+ $.ajax
13
+ url: Spree.routes.cart_link,
14
+ success: (data) ->
15
+ $('#link-to-cart').html data
@@ -0,0 +1,11 @@
1
+ //= require jquery.payment
2
+ //= require_self
3
+ //= require spree/frontend/checkout/address
4
+ //= require spree/frontend/checkout/payment
5
+
6
+ Spree.disableSaveOnClick = ->
7
+ ($ 'form.edit_order').submit ->
8
+ ($ this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass 'disabled'
9
+
10
+ Spree.ready ($) ->
11
+ Spree.Checkout = {}
@@ -1,25 +1,11 @@
1
- //= require jquery.payment
2
-
3
- Spree.disableSaveOnClick = ->
4
- ($ 'form.edit_order').submit ->
5
- ($ this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass 'disabled'
6
-
7
- Spree.ready ($) ->
8
- Spree.Checkout = {}
9
- $(".cardNumber").payment('formatCardNumber')
10
- $(".cardExpiry").payment('formatCardExpiry')
11
- $(".cardCode").payment('formatCardCVC')
12
-
13
- $(".cardNumber").change ->
14
- $(this).parent().siblings(".ccType").val($.payment.cardType(@value))
15
-
1
+ Spree.onAddress = () ->
16
2
  if ($ '#checkout_form_address').is('*')
17
3
  ($ '#checkout_form_address').validate()
18
4
 
19
5
  getCountryId = (region) ->
20
6
  $('#' + region + 'country select').val()
21
7
 
22
- updateState = (region) ->
8
+ Spree.updateState = (region) ->
23
9
  countryId = getCountryId(region)
24
10
  if countryId?
25
11
  unless Spree.Checkout[countryId]?
@@ -27,11 +13,11 @@ Spree.ready ($) ->
27
13
  Spree.Checkout[countryId] =
28
14
  states: data.states
29
15
  states_required: data.states_required
30
- fillStates(Spree.Checkout[countryId], region)
16
+ Spree.fillStates(Spree.Checkout[countryId], region)
31
17
  else
32
- fillStates(Spree.Checkout[countryId], region)
18
+ Spree.fillStates(Spree.Checkout[countryId], region)
33
19
 
34
- fillStates = (data, region) ->
20
+ Spree.fillStates = (data, region) ->
35
21
  statesRequired = data.states_required
36
22
  states = data.states
37
23
 
@@ -71,12 +57,12 @@ Spree.ready ($) ->
71
57
  stateSelect.removeClass('required')
72
58
 
73
59
  ($ '#bcountry select').change ->
74
- updateState 'b'
60
+ Spree.updateState 'b'
75
61
 
76
62
  ($ '#scountry select').change ->
77
- updateState 's'
63
+ Spree.updateState 's'
78
64
 
79
- updateState 'b'
65
+ Spree.updateState 'b'
80
66
 
81
67
  order_use_billing = ($ 'input#order_use_billing')
82
68
  order_use_billing.change ->
@@ -89,23 +75,9 @@ Spree.ready ($) ->
89
75
  else
90
76
  ($ '#shipping .inner').show()
91
77
  ($ '#shipping .inner input, #shipping .inner select').prop 'disabled', false
92
- updateState('s')
93
-
94
- update_shipping_form_state order_use_billing
95
-
96
- if ($ '#checkout_form_payment').is('*')
97
- ($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
98
- ($ '#payment-methods li').hide()
99
- ($ '#payment_method_' + @value).show() if @checked
100
- )
78
+ Spree.updateState('s')
101
79
 
102
- ($ document).on('click', '#cvv_link', (event) ->
103
- windowName = 'cvv_info'
104
- windowOptions = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1'
105
- window.open(($ this).attr('href'), windowName, windowOptions)
106
- event.preventDefault()
107
- )
80
+ update_shipping_form_state order_use_billing
108
81
 
109
- # Activate already checked payment method if form is re-rendered
110
- # i.e. if user enters invalid data
111
- ($ 'input[type="radio"]:checked').click()
82
+ Spree.ready ($) ->
83
+ Spree.onAddress()
@@ -0,0 +1,64 @@
1
+ Spree.onPayment = () ->
2
+ if ($ '#checkout_form_payment').is('*')
3
+
4
+ $(".cardNumber").payment('formatCardNumber')
5
+ $(".cardExpiry").payment('formatCardExpiry')
6
+ $(".cardCode").payment('formatCardCVC')
7
+
8
+ $(".cardNumber").change ->
9
+ $(this).parent().siblings(".ccType").val($.payment.cardType(@value))
10
+
11
+ ($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
12
+ ($ '#payment-methods li').hide()
13
+ ($ '#payment_method_' + @value).show() if @checked
14
+ )
15
+
16
+ ($ document).on('click', '#cvv_link', (event) ->
17
+ windowName = 'cvv_info'
18
+ windowOptions = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1'
19
+ window.open(($ this).attr('href'), windowName, windowOptions)
20
+ event.preventDefault()
21
+ )
22
+
23
+ # Activate already checked payment method if form is re-rendered
24
+ # i.e. if user enters invalid data
25
+ ($ 'input[type="radio"]:checked').click()
26
+
27
+ $('#checkout_form_payment').submit ->
28
+ # Coupon code application may take a number of seconds.
29
+ # Informing the user that this is happening is a good way to indicate some progress to them.
30
+ # In addition to this, if the coupon code FAILS then they don't lose their just-entered payment data.
31
+ coupon_code_field = $('#order_coupon_code')
32
+ coupon_code = $.trim(coupon_code_field.val())
33
+ if (coupon_code != '')
34
+ if $('#coupon_status').length == 0
35
+ coupon_status = $("<div id='coupon_status'></div>")
36
+ coupon_code_field.parent().append(coupon_status)
37
+ else
38
+ coupon_status = $("#coupon_status")
39
+
40
+ url = Spree.url(Spree.routes.apply_coupon_code(Spree.current_order_id),
41
+ {
42
+ order_token: Spree.current_order_token,
43
+ coupon_code: coupon_code
44
+ }
45
+ )
46
+
47
+ coupon_status.removeClass();
48
+ $.ajax({
49
+ async: false,
50
+ method: "PUT",
51
+ url: url,
52
+ success: (data) ->
53
+ coupon_code_field.val('')
54
+ coupon_status.addClass("success").html("Coupon code applied successfully.")
55
+ return true
56
+ error: (xhr) ->
57
+ handler = JSON.parse(xhr.responseText)
58
+ coupon_status.addClass("error").html(handler["error"])
59
+ $('.continue').attr('disabled', false)
60
+ return false
61
+ })
62
+
63
+ Spree.ready ($) ->
64
+ Spree.onPayment()
@@ -37,9 +37,8 @@ $ ->
37
37
  radios = ($ '#product-variants input[type="radio"]')
38
38
 
39
39
  if radios.length > 0
40
- selectedRadio = ($ '#product-variants input[type="radio"][checked="checked"]')
41
- Spree.showVariantImages selectedRadio.attr('value')
42
- Spree.updateVariantPrice selectedRadio
40
+ Spree.showVariantImages ($ '#product-variants input[type="radio"]').eq(0).attr('value')
41
+ Spree.updateVariantPrice radios.first()
43
42
 
44
43
  Spree.addImageHandlers()
45
44
 
@@ -2,5 +2,5 @@
2
2
  * This is a manifest file that includes stylesheets for spree_frontend
3
3
  *= require normalize
4
4
  *= require skeleton
5
- *= require store/screen
5
+ *= require spree/frontend/screen
6
6
  */
@@ -1,4 +1,5 @@
1
- @import 'store/variables';
1
+ @import 'spree/frontend/variables';
2
+ @import 'font-awesome';
2
3
 
3
4
  /*--------------------------------------*/
4
5
  /* Basic styles
@@ -309,7 +310,7 @@ nav #main-nav-bar {
309
310
  &#link-to-cart {
310
311
  float: right;
311
312
  padding-left: 24px;
312
- background: asset-url("store/cart.png") no-repeat left center;
313
+ background: image-url("spree/frontend/cart.png") no-repeat left center;
313
314
 
314
315
  &:hover {
315
316
  border-color: $link_text_color;
@@ -792,6 +793,12 @@ ul#products {
792
793
  }
793
794
  }
794
795
  }
796
+
797
+ &#subtotal {
798
+ text-transform: uppercase;
799
+ font-size: $base_font_size + 4;
800
+ color: $body_text_color;
801
+ }
795
802
  }
796
803
 
797
804
  .steps-data {
@@ -906,11 +913,24 @@ p[data-hook="use_billing"] {
906
913
  padding: 5px;
907
914
  }
908
915
 
916
+ #coupon_status {
917
+ font-weight: bold;
918
+ font-size: 125%;
919
+ &.success {
920
+ color: $c_green;
921
+ }
922
+ &.error {
923
+ color: $c_red;
924
+ }
925
+ }
926
+
909
927
  /*--------------------------------------*/
910
928
  /* Cart
911
929
  /*--------------------------------------*/
912
930
  table#cart-detail {
913
931
  width: 100%;
932
+ border-collapse: separate;
933
+
914
934
  tbody#line_items {
915
935
  tr {
916
936
 
@@ -920,7 +940,7 @@ table#cart-detail {
920
940
  }
921
941
  td[data-hook="cart_item_quantity"] {
922
942
  .line_item_quantity {
923
- width: 40px;
943
+ width: 65px;
924
944
  }
925
945
  }
926
946
  td[data-hook="cart_item_delete"] {
@@ -951,10 +971,23 @@ div[data-hook="inside_cart_form"] {
951
971
  }
952
972
 
953
973
  #empty-cart {
954
- margin-top: -75px;
974
+ margin-top: -50px;
955
975
  float: left;
956
976
  }
957
977
 
978
+ .cart-subtotal, .cart-total {
979
+ background: #00ADEE;
980
+
981
+ td h5 {
982
+ color: #fff;
983
+ }
984
+ }
985
+
986
+ .adjustment:nth-child(even) {
987
+ background: #eaeaea;
988
+
989
+ }
990
+
958
991
  /*--------------------------------------*/
959
992
  /* Account
960
993
  /*--------------------------------------*/
@@ -25,9 +25,8 @@ module Spree
25
25
 
26
26
  # Updates the order and advances to the next state (when possible.)
27
27
  def update
28
- if @order.update_attributes(object_params)
28
+ if @order.update_from_params(params, permitted_checkout_attributes)
29
29
  persist_user_address
30
-
31
30
  unless @order.next
32
31
  flash[:error] = @order.errors.full_messages.join("\n")
33
32
  redirect_to checkout_state_path(@order.state) and return
@@ -71,7 +70,7 @@ module Spree
71
70
  end
72
71
 
73
72
  def load_order_with_lock
74
- @order = current_order(lock: true)
73
+ @order = current_order(lock: true)
75
74
  redirect_to spree.cart_path and return unless @order
76
75
 
77
76
  if params[:state]
@@ -102,32 +101,6 @@ module Spree
102
101
  spree.order_path(@order)
103
102
  end
104
103
 
105
- # For payment step, filter order parameters to produce the expected nested
106
- # attributes for a single payment and its source, discarding attributes
107
- # for payment methods other than the one selected
108
- def object_params
109
- # has_checkout_step? check is necessary due to issue described in #2910
110
- if @order.has_checkout_step?("payment") && @order.payment?
111
- if params[:payment_source].present?
112
- source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
113
-
114
- if source_params
115
- params[:order][:payments_attributes].first[:source_attributes] = source_params
116
- end
117
- end
118
-
119
- if (params[:order][:payments_attributes])
120
- params[:order][:payments_attributes].first[:amount] = @order.total
121
- end
122
- end
123
-
124
- if params[:order]
125
- params[:order].permit(permitted_checkout_attributes)
126
- else
127
- {}
128
- end
129
- end
130
-
131
104
  def setup_for_current_state
132
105
  method_name = :"before_#{@order.state}"
133
106
  send(method_name) if respond_to?(method_name, true)
@@ -170,20 +143,6 @@ module Spree
170
143
  authorize!(:edit, current_order, session[:access_token])
171
144
  end
172
145
 
173
- def apply_coupon_code
174
- if params[:order] && params[:order][:coupon_code]
175
- @order.coupon_code = params[:order][:coupon_code]
176
-
177
- coupon_result = Spree::Promo::CouponApplicator.new(@order).apply
178
- if coupon_result[:coupon_applied?]
179
- flash[:success] = coupon_result[:success] if coupon_result[:success].present?
180
- else
181
- flash.now[:error] = coupon_result[:error]
182
- respond_with(@order) { |format| format.html { render :edit } } and return
183
- end
184
- end
185
- end
186
-
187
146
  def persist_user_address
188
147
  if @order.checkout_steps.include? "address"
189
148
  if @order.address? && try_spree_current_user.respond_to?(:persist_order_address)
@@ -191,6 +150,5 @@ module Spree
191
150
  end
192
151
  end
193
152
  end
194
-
195
153
  end
196
154
  end
@@ -3,7 +3,6 @@ module Spree
3
3
  # Don't serve local files or static assets
4
4
  before_filter { render_404 if params[:path] =~ /(\.|\\)/ }
5
5
  after_filter :fire_visited_path, :only => :show
6
- after_filter :fire_visited_action, :except => :show
7
6
 
8
7
  rescue_from ActionView::MissingTemplate, :with => :render_404
9
8
 
@@ -18,11 +17,7 @@ module Spree
18
17
  end
19
18
 
20
19
  def fire_visited_path
21
- fire_event('spree.content.visited', :path => "content/#{params[:path]}")
22
- end
23
-
24
- def fire_visited_action
25
- fire_event('spree.content.visited', :path => "content/#{params[:action]}")
20
+ Spree::PromotionHandler::Page.new(current_order, params[:path]).activate
26
21
  end
27
22
  end
28
23
  end
@@ -6,6 +6,7 @@ module Spree
6
6
  def index
7
7
  @searcher = build_searcher(params)
8
8
  @products = @searcher.retrieve_products
9
+ @taxonomies = Spree::Taxonomy.includes(root: :children)
9
10
  end
10
11
  end
11
12
  end
@@ -8,24 +8,16 @@ module Spree
8
8
 
9
9
  respond_to :html
10
10
 
11
+ before_filter :assign_order_with_lock, only: :update
12
+ before_filter :apply_coupon_code, only: :update
13
+ skip_before_filter :verify_authenticity_token
14
+
11
15
  def show
12
16
  @order = Order.find_by_number!(params[:id])
13
17
  end
14
18
 
15
19
  def update
16
- @order = current_order(lock: true)
17
- unless @order
18
- flash[:error] = Spree.t(:order_not_found)
19
- redirect_to root_path and return
20
- end
21
-
22
- if @order.update_attributes(order_params)
23
- @order.line_items = @order.line_items.select {|li| li.quantity > 0 }
24
- @order.ensure_updated_shipments
25
- return if after_update_attributes
26
-
27
- fire_event('spree.order.contents_changed')
28
-
20
+ if @order.contents.update_cart(order_params)
29
21
  respond_with(@order) do |format|
30
22
  format.html do
31
23
  if params.has_key?(:checkout)
@@ -45,16 +37,17 @@ module Spree
45
37
  def edit
46
38
  @order = current_order || Order.new
47
39
  associate_user
40
+ if stale?(current_order)
41
+ respond_with(current_order)
42
+ end
48
43
  end
49
44
 
50
45
  # Adds a new item to the order (creating a new order if none already exists)
51
46
  def populate
52
47
  populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency)
53
- if populator.populate(params.slice(:products, :variants, :quantity))
48
+ if populator.populate(params[:variant_id], params[:quantity])
54
49
  current_order.ensure_updated_shipments
55
50
 
56
- fire_event('spree.cart.add')
57
- fire_event('spree.order.contents_changed')
58
51
  respond_with(@order) do |format|
59
52
  format.html { redirect_to cart_path }
60
53
  end
@@ -101,15 +94,11 @@ module Spree
101
94
  end
102
95
  end
103
96
 
104
- def after_update_attributes
105
- coupon_result = Spree::Promo::CouponApplicator.new(@order).apply
106
- if coupon_result[:coupon_applied?]
107
- flash[:success] = coupon_result[:success] if coupon_result[:success].present?
108
- return false
109
- else
110
- flash.now[:error] = coupon_result[:error]
111
- respond_with(@order) { |format| format.html { render :edit } }
112
- return true
97
+ def assign_order_with_lock
98
+ @order = current_order(lock: true)
99
+ unless @order
100
+ flash[:error] = Spree.t(:order_not_found)
101
+ redirect_to root_path and return
113
102
  end
114
103
  end
115
104
  end