spree_frontend 4.2.7 → 4.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/config/spree_frontend_manifest.js +4 -0
  4. data/app/assets/images/card-image.svg +4 -0
  5. data/app/assets/images/file-image.svg +4 -0
  6. data/app/assets/images/image.svg +4 -0
  7. data/app/assets/images/noimage/large.png +0 -0
  8. data/app/assets/images/noimage/mini.png +0 -0
  9. data/app/assets/images/noimage/plp.svg +23 -0
  10. data/app/assets/images/noimage/product.png +0 -0
  11. data/app/assets/images/noimage/small.png +0 -0
  12. data/app/assets/javascripts/spree/api/main.js +36 -0
  13. data/app/assets/javascripts/spree/api/storefront/cart.js +49 -0
  14. data/app/assets/javascripts/spree/frontend/checkout/payment.js +18 -5
  15. data/app/assets/javascripts/spree/frontend/checkout.js +16 -0
  16. data/app/assets/javascripts/spree/frontend/locale.es6 +13 -0
  17. data/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js +3 -3
  18. data/app/assets/javascripts/spree/frontend/views/spree/products/index.js +0 -9
  19. data/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6 +46 -0
  20. data/app/assets/javascripts/spree/frontend.js +3 -0
  21. data/app/assets/javascripts/spree.js +78 -0
  22. data/app/assets/stylesheets/spree/frontend/application.scss +1 -0
  23. data/app/assets/stylesheets/spree/frontend/components-bootstrap/button.scss +8 -0
  24. data/app/assets/stylesheets/spree/frontend/helpers/spree/frontend_helper.scss +41 -0
  25. data/app/assets/stylesheets/spree/frontend/variables/variables.scss +2 -2
  26. data/app/assets/stylesheets/spree/frontend/views/spree/checkout/edit.scss +17 -5
  27. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/_index.scss +1 -0
  28. data/app/assets/stylesheets/spree/frontend/views/spree/cms_sections/product_buy_bar.scss +20 -0
  29. data/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss +54 -67
  30. data/app/assets/stylesheets/spree/frontend/views/spree/shared/category_nav_bar.scss +3 -3
  31. data/app/assets/stylesheets/spree/frontend/views/spree/shared/footer.scss +4 -0
  32. data/app/assets/stylesheets/spree/frontend/views/spree/shared/main_nav_bar.scss +12 -1
  33. data/app/controllers/spree/addresses_controller.rb +14 -19
  34. data/app/controllers/spree/checkout_controller.rb +5 -3
  35. data/app/controllers/spree/cms_pages_controller.rb +29 -0
  36. data/app/controllers/spree/content_controller.rb +0 -2
  37. data/app/controllers/spree/errors_controller.rb +11 -0
  38. data/app/controllers/spree/home_controller.rb +34 -1
  39. data/app/controllers/spree/locale_controller.rb +7 -1
  40. data/app/controllers/spree/orders_controller.rb +9 -7
  41. data/app/controllers/spree/products_controller.rb +14 -13
  42. data/app/controllers/spree/store_controller.rb +25 -1
  43. data/app/controllers/spree/taxons_controller.rb +12 -5
  44. data/app/helpers/spree/addresses_helper.rb +9 -4
  45. data/app/helpers/spree/cms_pages_helper.rb +23 -0
  46. data/app/helpers/spree/frontend_helper.rb +109 -10
  47. data/app/helpers/spree/navigation_helper.rb +73 -4
  48. data/app/helpers/spree/products_filters_helper.rb +168 -0
  49. data/app/helpers/spree/store_helper.rb +3 -1
  50. data/app/views/spree/checkout/_address.html.erb +1 -1
  51. data/app/views/spree/checkout/_credit_card.html.erb +1 -0
  52. data/app/views/spree/cms_pages/show.html.erb +16 -0
  53. data/app/views/spree/errors/forbidden.html.erb +0 -0
  54. data/app/views/spree/errors/unauthorized.html.erb +0 -0
  55. data/app/views/spree/home/index.html.erb +19 -118
  56. data/app/views/spree/layouts/spree_application.html.erb +1 -1
  57. data/app/views/spree/products/_description.html.erb +16 -19
  58. data/app/views/spree/products/_filters_desktop.html.erb +50 -15
  59. data/app/views/spree/products/_filters_mobile.html.erb +38 -10
  60. data/app/views/spree/products/_sort_desktop.html.erb +17 -11
  61. data/app/views/spree/products/_sort_mobile.html.erb +16 -0
  62. data/app/views/spree/products/index.html.erb +1 -1
  63. data/app/views/spree/shared/_carousel_4_products.html.erb +2 -2
  64. data/app/views/spree/shared/_checkout_header.html.erb +22 -21
  65. data/app/views/spree/shared/_copyright.html.erb +1 -1
  66. data/app/views/spree/shared/_footer.html.erb +15 -9
  67. data/app/views/spree/shared/_head.html.erb +1 -1
  68. data/app/views/spree/shared/_header.html.erb +3 -3
  69. data/app/views/spree/shared/_main_nav_bar.html.erb +61 -43
  70. data/app/views/spree/shared/_mobile_navigation.html.erb +30 -19
  71. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  72. data/app/views/spree/shared/_option_values.html.erb +2 -21
  73. data/app/views/spree/shared/_order_details.html.erb +1 -1
  74. data/app/views/spree/shared/_paths.html.erb +8 -0
  75. data/app/views/spree/shared/_properties.html.erb +4 -0
  76. data/app/views/spree/shared/_translations.html.erb +2 -1
  77. data/app/views/spree/shared/carousel/_single.html.erb +1 -1
  78. data/app/views/spree/shared/carousel/_thumbnails.html.erb +1 -1
  79. data/app/views/spree/shared/cms/pages/_edit_mode.html.erb +13 -0
  80. data/app/views/spree/shared/cms/sections/_featured_article.html.erb +27 -0
  81. data/app/views/spree/shared/cms/sections/_hero_image.html.erb +60 -0
  82. data/app/views/spree/shared/cms/sections/_image_gallery.html.erb +171 -0
  83. data/app/views/spree/shared/cms/sections/_product_carousel.html.erb +5 -0
  84. data/app/views/spree/shared/cms/sections/_rich_text_content.html.erb +3 -0
  85. data/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb +118 -0
  86. data/app/views/spree/taxons/_header.html.erb +6 -1
  87. data/app/views/spree/users/show.html.erb +1 -1
  88. data/config/initializers/assets.rb +4 -13
  89. data/config/routes.rb +9 -3
  90. data/lib/generators/spree/frontend/install/install_generator.rb +5 -5
  91. data/lib/generators/spree/frontend/install/templates/app/assets/config/manifest.js +2 -0
  92. data/lib/generators/spree/frontend/install/templates/vendor/assets/javascripts/spree/frontend/all.js +8 -0
  93. data/lib/generators/spree/frontend/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +9 -0
  94. data/lib/spree/frontend/engine.rb +6 -0
  95. data/lib/spree/frontend.rb +6 -3
  96. data/spec/fixtures/files/store_favicon.ico +0 -0
  97. data/spree_frontend.gemspec +7 -3
  98. data/vendor/assets/javascripts/cleave.js +8 -0
  99. data/vendor/assets/javascripts/fetch.umd.js +531 -0
  100. data/vendor/assets/javascripts/jquery.payment.js +652 -0
  101. data/vendor/assets/javascripts/jsuri.js +458 -0
  102. data/vendor/assets/javascripts/polyfill.min.js +1 -0
  103. metadata +116 -70
  104. data/app/assets/images/homepage/big_category_banner.jpg +0 -0
  105. data/app/assets/images/homepage/big_category_banner_mobile.jpg +0 -0
  106. data/app/assets/images/homepage/big_category_banner_tablet_landscape.jpg +0 -0
  107. data/app/assets/images/homepage/big_category_banner_tablet_portrait.jpg +0 -0
  108. data/app/assets/images/homepage/category_banner_lower.jpg +0 -0
  109. data/app/assets/images/homepage/category_banner_lower_mobile.jpg +0 -0
  110. data/app/assets/images/homepage/category_banner_lower_tablet_landscape.jpg +0 -0
  111. data/app/assets/images/homepage/category_banner_lower_tablet_portrait.jpg +0 -0
  112. data/app/assets/images/homepage/category_banner_upper.jpg +0 -0
  113. data/app/assets/images/homepage/category_banner_upper_mobile.jpg +0 -0
  114. data/app/assets/images/homepage/category_banner_upper_tablet_landscape.jpg +0 -0
  115. data/app/assets/images/homepage/category_banner_upper_tablet_portrait.jpg +0 -0
  116. data/app/assets/images/homepage/main_banner.jpg +0 -0
  117. data/app/assets/images/homepage/main_banner_mobile.jpg +0 -0
  118. data/app/assets/images/homepage/main_banner_tablet_landscape.jpg +0 -0
  119. data/app/assets/images/homepage/main_banner_tablet_portrait.jpg +0 -0
  120. data/app/assets/images/homepage/promo_banner_left.jpg +0 -0
  121. data/app/assets/images/homepage/promo_banner_left_mobile.jpg +0 -0
  122. data/app/assets/images/homepage/promo_banner_left_tablet_landscape.jpg +0 -0
  123. data/app/assets/images/homepage/promo_banner_left_tablet_portrait.jpg +0 -0
  124. data/app/assets/images/homepage/promo_banner_right.jpg +0 -0
  125. data/app/assets/images/homepage/promo_banner_right_mobile.jpg +0 -0
  126. data/app/assets/images/homepage/promo_banner_right_tablet_landscape.jpg +0 -0
  127. data/app/assets/images/homepage/promo_banner_right_tablet_portrait.jpg +0 -0
  128. data/app/assets/images/meganav/promo_banner_left-first-category.jpg +0 -0
  129. data/app/assets/images/meganav/promo_banner_left-second-category.jpg +0 -0
  130. data/app/assets/images/meganav/promo_banner_left-third-category.jpg +0 -0
  131. data/app/assets/images/meganav/promo_banner_right-first-category.jpg +0 -0
  132. data/app/assets/images/meganav/promo_banner_right-second-category.jpg +0 -0
  133. data/app/assets/images/meganav/promo_banner_right-third-category.jpg +0 -0
  134. data/app/assets/images/noimage/big_category_banner.jpg +0 -0
  135. data/app/assets/images/noimage/big_category_banner_mobile.jpg +0 -0
  136. data/app/assets/images/noimage/big_category_banner_tablet_landscape.jpg +0 -0
  137. data/app/assets/images/noimage/big_category_banner_tablet_portrait.jpg +0 -0
  138. data/app/assets/images/noimage/category_banner.jpg +0 -0
  139. data/app/assets/images/noimage/category_banner_mobile.jpg +0 -0
  140. data/app/assets/images/noimage/category_banner_plp.jpg +0 -0
  141. data/app/assets/images/noimage/category_banner_tablet_landscape.jpg +0 -0
  142. data/app/assets/images/noimage/category_banner_tablet_portrait.jpg +0 -0
  143. data/app/assets/images/noimage/main_banner.jpg +0 -0
  144. data/app/assets/images/noimage/main_banner_mobile.jpg +0 -0
  145. data/app/assets/images/noimage/main_banner_tablet_landscape.jpg +0 -0
  146. data/app/assets/images/noimage/main_banner_tablet_portrait.jpg +0 -0
  147. data/app/assets/images/noimage/product_photo.jpg +0 -0
  148. data/app/assets/images/noimage/promo_banner.jpg +0 -0
  149. data/app/assets/images/noimage/promo_banner_megamenu.jpg +0 -0
  150. data/app/assets/images/noimage/promo_banner_mobile.jpg +0 -0
  151. data/app/assets/images/noimage/promo_banner_tablet_landscape.jpg +0 -0
  152. data/app/assets/images/noimage/promo_banner_tablet_portrait.jpg +0 -0
  153. data/app/assets/javascripts/spree/frontend/locale.js +0 -13
  154. data/app/assets/javascripts/spree/frontend/multi_currency.js +0 -13
  155. data/lib/generators/spree/frontend/install/templates/config/initializers/spree_storefront.rb +0 -1
  156. data/lib/generators/spree/frontend/install/templates/config/spree_storefront.yml +0 -99
@@ -1,10 +1,29 @@
1
+ :root {
2
+ --spree-border-color: transparent;
3
+ }
4
+
5
+ .brand {
6
+ img {
7
+ width: 85%;
8
+ max-width: 140px;
9
+ }
10
+ }
11
+
12
+ .section-row {
13
+ margin-bottom: #{$grid-gutter-width};
14
+ }
15
+
16
+ .match-col-gap {
17
+ padding-left: $container-padding;
18
+ padding-right: $container-padding;
19
+ }
20
+
1
21
  .homepage {
2
22
  &-hero-image {
3
23
  display: flex;
4
- justify-content: center;
24
+ justify-content: flex-start;
5
25
  flex-direction: column;
6
26
  text-align: center;
7
- height: 204px;
8
27
  width: 100%;
9
28
  overflow: hidden;
10
29
 
@@ -16,16 +35,7 @@
16
35
  height: 100%;
17
36
  }
18
37
 
19
- @include media-breakpoint-up(md) {
20
- height: 418px;
21
- }
22
-
23
- @include media-breakpoint-up(lg) {
24
- height: 600px;
25
- }
26
-
27
38
  .hero-content {
28
- position: absolute;
29
39
  z-index: 1;
30
40
  right: 10%;
31
41
  }
@@ -40,7 +50,7 @@
40
50
 
41
51
  @include media-breakpoint-up(md) {
42
52
  font-size: font-px-to-rem(44px);
43
- width: 288px;
53
+ width: 398px;
44
54
  }
45
55
 
46
56
  @include media-breakpoint-up(lg) {
@@ -65,17 +75,6 @@
65
75
 
66
76
  &-taxon-box {
67
77
  display: block;
68
- flex-direction: column;
69
- height: 140px;
70
- position: relative;
71
- overflow: hidden;
72
-
73
- img {
74
- display: block;
75
- object-fit: cover;
76
- width: 100%;
77
- height: 100%;
78
- }
79
78
 
80
79
  h3 {
81
80
  margin: 0;
@@ -97,14 +96,6 @@
97
96
  }
98
97
  }
99
98
 
100
- @include media-breakpoint-up(md) {
101
- height: 324px;
102
- }
103
-
104
- @include media-breakpoint-up(lg) {
105
- height: 390px;
106
- }
107
-
108
99
  &-text {
109
100
  width: 100%;
110
101
  text-transform: uppercase;
@@ -133,10 +124,10 @@
133
124
  &-fashion-trends-box {
134
125
  background: $secondary-background;
135
126
  color: $secondary-font-color;
136
- padding: 30px 0px;
127
+ padding: 30px 15px;
137
128
 
138
129
  @include media-breakpoint-up(md) {
139
- padding: 60px 0px;
130
+ padding: 5vw 0px;
140
131
  }
141
132
 
142
133
  &-summer-text {
@@ -178,11 +169,12 @@
178
169
  color: $font-color;
179
170
  margin: auto;
180
171
  font-size: font-px-to-rem(12px);
181
- width: 283px;
172
+ max-width: 283px;
182
173
 
183
174
  @include media-breakpoint-up(md) {
184
175
  font-size: font-px-to-rem(16px);
185
- width: 608px;
176
+ width: 90%;
177
+ max-width: 608px;
186
178
  }
187
179
  }
188
180
  .spree-btn {
@@ -190,58 +182,36 @@
190
182
  border: solid 2px theme-color('primary');
191
183
  font-size: font-px-to-rem(12px);
192
184
  font-weight: bold;
185
+ max-width: 100%;
193
186
  @include media-breakpoint-up(md) {
194
187
  font-size: font-px-to-rem(22px);
195
- width: 400px;
196
- padding-top: 0.7rem;
197
188
  }
198
189
  @include media-breakpoint-up(lg) {
199
190
  font-size: font-px-to-rem(20px);
200
- width: 497.2px;
201
191
  }
202
192
  }
203
193
  }
204
194
  }
205
195
 
206
196
  &-bottom-box {
207
- background: $secondary-background;
208
- color: $secondary-font-color;
209
- display: flex;
210
- justify-content: center;
211
- flex-direction: column;
212
- text-align: center;
213
- height: 168px;
214
- overflow: hidden;
215
-
216
197
  img {
217
198
  width: 100%;
218
199
  object-fit: cover;
219
200
  }
220
201
 
221
- @include media-breakpoint-up(md) {
222
- height: 363px;
223
- }
224
- @include media-breakpoint-up(lg) {
225
- height: 350px;
226
- }
227
-
228
202
  &-inner {
229
203
  background: $primary-background;
230
204
  margin: auto;
231
- padding: 10px 30px;
232
205
  position: absolute;
233
- width: 70%;
234
- left: 15%;
235
-
236
- @include media-breakpoint-up(md) {
237
- padding: 30px 100px;
238
- }
206
+ max-height: 70%;
207
+ min-width: 60%;
208
+ max-width: 80%;
209
+ bottom: 35px;
239
210
 
240
211
  &-small-text {
241
212
  font-weight: 500;
242
213
  line-height: 0.9;
243
214
  letter-spacing: 0.25px;
244
- text-align: center;
245
215
  color: theme-color('primary');
246
216
  font-size: font-px-to-rem(10px);
247
217
 
@@ -257,9 +227,12 @@
257
227
  font-weight: 600;
258
228
  line-height: 1.2;
259
229
  letter-spacing: 0.38px;
260
- text-align: center;
261
230
  color: $font-color;
262
- font-size: font-px-to-rem(15px);
231
+ font-size: font-px-to-rem(14px);
232
+
233
+ @include media-breakpoint-up(sm) {
234
+ font-size: font-px-to-rem(22px);
235
+ }
263
236
 
264
237
  @include media-breakpoint-up(md) {
265
238
  font-size: font-px-to-rem(27px);
@@ -280,14 +253,28 @@
280
253
  text-decoration: none !important;
281
254
  }
282
255
  &-text {
283
- font-size: 12px;
256
+ font-size: font-px-to-rem(12px);
284
257
 
285
258
  @include media-breakpoint-up(md) {
286
- font-size: 22px;
259
+ font-size: font-px-to-rem(22px);
287
260
  }
288
261
  @include media-breakpoint-up(lg) {
289
- font-size: 24px;
262
+ font-size: font-px-to-rem(24px);
290
263
  }
291
264
  }
292
265
  }
266
+
267
+ &-hpb {
268
+ border: 3px solid var(--spree-border-color);
269
+ }
270
+ }
271
+
272
+ #missingHomepage {
273
+ .missing-homepage-logo-container {
274
+ width: 160px;
275
+
276
+ img {
277
+ max-width: 100%;
278
+ }
279
+ }
293
280
  }
@@ -1,7 +1,7 @@
1
1
  .category {
2
2
  &-links {
3
- width: 176px;
4
- min-width: 176px;
3
+ width: 170px;
4
+ min-width: 170px;
5
5
 
6
6
  &-header {
7
7
  color: $meganav-font-color;
@@ -12,7 +12,7 @@
12
12
 
13
13
  ul {
14
14
  list-style-type: none;
15
- padding-top: 27px;
15
+ padding-top: 15px;
16
16
  }
17
17
 
18
18
  li {
@@ -41,6 +41,10 @@
41
41
  @include media-breakpoint-up(xl) {
42
42
  font-size: font-px-to-rem(16px);
43
43
  font-weight: 500;
44
+
45
+ a {
46
+ font-size: font-px-to-rem(16px) !important;
47
+ }
44
48
  }
45
49
  }
46
50
  &-info {
@@ -28,6 +28,14 @@
28
28
  }
29
29
  }
30
30
 
31
+ #{$self}-button.active {
32
+ color: $header-font-color;
33
+ text-decoration: none;
34
+ &:after {
35
+ border-bottom-color: $header-font-color;
36
+ }
37
+ }
38
+
31
39
  .dropdown-item {
32
40
  width: auto;
33
41
  padding: 0;
@@ -35,6 +43,10 @@
35
43
  &:hover, &:focus {
36
44
  background-color: transparent;
37
45
  }
46
+ &.active {
47
+ color: $header-font-color;
48
+ text-decoration: underline;
49
+ }
38
50
  }
39
51
 
40
52
  &-button {
@@ -60,7 +72,6 @@
60
72
  }
61
73
 
62
74
  &-dropdown {
63
- padding: 51px 0px 51px 0px;
64
75
  min-height: 341px;
65
76
  left: 0;
66
77
  right: 0;
@@ -10,7 +10,7 @@ module Spree
10
10
 
11
11
  def create
12
12
  @address = try_spree_current_user.addresses.build(address_params)
13
- if @address.save
13
+ if create_service.call(user: try_spree_current_user, address_params: @address.attributes).success?
14
14
  flash[:notice] = I18n.t(:successfully_created, scope: :address_book)
15
15
  redirect_to spree.account_path
16
16
  else
@@ -23,28 +23,15 @@ module Spree
23
23
  end
24
24
 
25
25
  def new
26
- @address = Spree::Address.default
26
+ @address = Spree::Address.new(country: current_store.default_country, user: try_spree_current_user)
27
27
  end
28
28
 
29
29
  def update
30
- if @address.editable?
31
- if @address.update(address_params)
32
- flash[:notice] = Spree.t(:successfully_updated, scope: :address_book)
33
- redirect_back_or_default(addresses_path)
34
- else
35
- render :edit
36
- end
30
+ if update_service.call(address: @address, address_params: address_params).success?
31
+ flash[:notice] = Spree.t(:successfully_updated, scope: :address_book)
32
+ redirect_back_or_default(addresses_path)
37
33
  else
38
- new_address = @address.clone
39
- new_address.attributes = address_params
40
- new_address.user_id = @address.user_id
41
- @address.update_attribute(:deleted_at, Time.current)
42
- if new_address.save
43
- flash[:notice] = Spree.t(:successfully_updated, scope: :address_book)
44
- redirect_back_or_default(addresses_path)
45
- else
46
- render :edit
47
- end
34
+ render :edit
48
35
  end
49
36
  end
50
37
 
@@ -60,5 +47,13 @@ module Spree
60
47
  def address_params
61
48
  params.require(:address).permit(permitted_address_attributes)
62
49
  end
50
+
51
+ def create_service
52
+ Spree::Dependencies.account_create_address_service.constantize
53
+ end
54
+
55
+ def update_service
56
+ Spree::Dependencies.account_update_address_service.constantize
57
+ end
63
58
  end
64
59
  end
@@ -141,8 +141,8 @@ module Spree
141
141
  def before_address
142
142
  # if the user has a default address, a callback takes care of setting
143
143
  # that; but if he doesn't, we need to build an empty one here
144
- @order.bill_address ||= Address.build_default
145
- @order.ship_address ||= Address.build_default if @order.checkout_steps.include?('delivery')
144
+ @order.bill_address ||= Address.new(country: current_store.default_country, user: try_spree_current_user)
145
+ @order.ship_address ||= Address.new(country: current_store.default_country, user: try_spree_current_user) if @order.checkout_steps.include?('delivery')
146
146
  end
147
147
 
148
148
  def before_delivery
@@ -161,7 +161,9 @@ module Spree
161
161
  end
162
162
  end
163
163
 
164
- @payment_sources = try_spree_current_user.payment_sources if try_spree_current_user&.respond_to?(:payment_sources)
164
+ return unless try_spree_current_user.respond_to?(:payment_sources)
165
+
166
+ @payment_sources = try_spree_current_user.payment_sources.where(payment_method: @order.available_payment_methods)
165
167
  end
166
168
 
167
169
  def add_store_credit_payments
@@ -0,0 +1,29 @@
1
+ module Spree
2
+ class CmsPagesController < Spree::StoreController
3
+ before_action :load_cms_page, only: [:show]
4
+
5
+ include Spree::FrontendHelper
6
+ include Spree::CacheHelper
7
+
8
+ def show
9
+ if @page&.visible?
10
+ @cms_page = @page
11
+ elsif @page&.draft_mode? && try_spree_current_user&.admin?
12
+ @cms_page = @page
13
+ @edit_mode = true
14
+ else
15
+ raise ActiveRecord::RecordNotFound
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def accurate_title
22
+ @page&.seo_title || super
23
+ end
24
+
25
+ def load_cms_page
26
+ @page = Spree::CmsPage.for_store(current_store).by_locale(I18n.locale).find_by(slug: params[:slug])
27
+ end
28
+ end
29
+ end
@@ -3,8 +3,6 @@ module Spree
3
3
  # Don't serve local files or static assets
4
4
  after_action :fire_visited_path, except: :cvv
5
5
 
6
- respond_to :html
7
-
8
6
  def test; end
9
7
 
10
8
  def cvv
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class ErrorsController < StoreController
3
+ def forbidden
4
+ render status: 403
5
+ end
6
+
7
+ def unauthorized
8
+ render status: 401
9
+ end
10
+ end
11
+ end
@@ -2,12 +2,45 @@ module Spree
2
2
  class HomeController < Spree::StoreController
3
3
  include Spree::CacheHelper
4
4
 
5
+ before_action :load_homepage, only: [:index]
6
+
5
7
  respond_to :html
6
8
 
7
9
  def index
10
+ if @cms_home_page&.visible?
11
+ @homepage = @cms_home_page
12
+ elsif try_spree_current_user&.admin?
13
+ @homepage = @cms_home_page
14
+ @edit_mode = true
15
+ end
16
+
8
17
  if http_cache_enabled?
9
- fresh_when etag: store_etag, last_modified: store_last_modified, public: true
18
+ fresh_when etag: store_etag, last_modified: last_modified_index, public: true
10
19
  end
11
20
  end
21
+
22
+ private
23
+
24
+ def etag_index
25
+ [
26
+ store_etag,
27
+ last_modified_index,
28
+ ]
29
+ end
30
+
31
+ def last_modified_index
32
+ page_last_modified = @cms_home_page&.maximum(:updated_at)&.utc if @cms_home_page.respond_to?(:maximum)
33
+ current_store_last_modified = current_store.updated_at.utc
34
+
35
+ [page_last_modified, current_store_last_modified].compact.max
36
+ end
37
+
38
+ def accurate_title
39
+ @cms_home_page&.seo_title || super
40
+ end
41
+
42
+ def load_homepage
43
+ @cms_home_page = current_store.homepage(I18n.locale)
44
+ end
12
45
  end
13
46
  end
@@ -1,5 +1,7 @@
1
1
  module Spree
2
2
  class LocaleController < Spree::StoreController
3
+ REDIRECT_TO_ROOT = /\/(#{Spree::Config[:storefront_pages_path]})\//.freeze
4
+
3
5
  def index
4
6
  render :index, layout: false
5
7
  end
@@ -25,7 +27,11 @@ module Spree
25
27
  private
26
28
 
27
29
  def should_build_new_url?
28
- request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
30
+ if request.env['HTTP_REFERER'].match(REDIRECT_TO_ROOT)
31
+ false
32
+ else
33
+ request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
34
+ end
29
35
  end
30
36
  end
31
37
  end
@@ -5,16 +5,14 @@ module Spree
5
5
 
6
6
  helper 'spree/products', 'spree/orders'
7
7
 
8
- respond_to :html
9
-
10
8
  before_action :assign_order_with_lock, only: :update
11
9
 
12
10
  def show
13
- @order = Order.includes(line_items: [variant: [:option_values, :images, :product]], bill_address: :state, ship_address: :state).find_by!(number: params[:id])
11
+ @order = current_store.orders.includes(line_items: [variant: [:option_values, :images, :product]], bill_address: :state, ship_address: :state).find_by!(number: params[:id])
14
12
  end
15
13
 
16
14
  def update
17
- @variant = Spree::Variant.find(params[:variant_id]) if params[:variant_id]
15
+ @variant = curret_store.variants.find(params[:variant_id]) if params[:variant_id]
18
16
  if Cart::Update.call(order: @order, params: order_params).success?
19
17
  respond_with(@order) do |format|
20
18
  format.html do
@@ -33,14 +31,14 @@ module Spree
33
31
 
34
32
  # Shows the current incomplete order from the session
35
33
  def edit
36
- @order = current_order || Order.incomplete.
34
+ @order = current_order || current_store.orders.incomplete.
37
35
  includes(line_items: [variant: [:images, :product, option_values: :option_type]]).
38
36
  find_or_initialize_by(token: cookies.signed[:token])
39
37
  associate_user
40
38
  end
41
39
 
42
40
  def empty
43
- current_order.try(:empty!)
41
+ cart_empty_service.call(order: current_order)
44
42
 
45
43
  redirect_to spree.cart_path
46
44
  end
@@ -56,7 +54,7 @@ module Spree
56
54
  end
57
55
 
58
56
  def check_authorization
59
- order = Spree::Order.find_by(number: params[:id]) if params[:id].present?
57
+ order = current_store.orders.find_by(number: params[:id]) if params[:id].present?
60
58
  order ||= current_order
61
59
 
62
60
  if order && action_name.to_sym == :show
@@ -87,5 +85,9 @@ module Spree
87
85
  def cart_add_item_service
88
86
  Spree::Dependencies.cart_add_item_service.constantize
89
87
  end
88
+
89
+ def cart_empty_service
90
+ Spree::Dependencies.cart_empty_service.constantize
91
+ end
90
92
  end
91
93
  end
@@ -7,10 +7,10 @@ module Spree
7
7
  before_action :load_product, only: [:show, :related]
8
8
  before_action :load_taxon, only: :index
9
9
 
10
- respond_to :html
10
+ before_action :can_show_product?, only: :show
11
11
 
12
12
  def index
13
- @searcher = build_searcher(params.merge(include_images: true, current_store_id: current_store.id))
13
+ @searcher = build_searcher(params.merge(include_images: true, current_store: current_store))
14
14
  @products = @searcher.retrieve_products
15
15
 
16
16
  if http_cache_enabled?
@@ -21,7 +21,8 @@ module Spree
21
21
  def show
22
22
  redirect_if_legacy_path
23
23
 
24
- @taxon = params[:taxon_id].present? ? Spree::Taxon.find(params[:taxon_id]) : @product.taxons.first
24
+ @taxon = params[:taxon_id].present? ? taxons_scope.find_by(id: params[:taxon_id]) : nil
25
+ @taxon = @product.taxons.first unless @taxon.present?
25
26
 
26
27
  if !http_cache_enabled? || stale?(etag: etag_show, last_modified: last_modified_show, public: true)
27
28
  @product_summary = Spree::ProductSummaryPresenter.new(@product).call
@@ -51,19 +52,15 @@ module Spree
51
52
  end
52
53
 
53
54
  def load_product
54
- @products = if try_spree_current_user.try(:has_spree_role?, 'admin')
55
- Product.with_deleted
56
- else
57
- Product.active(current_currency)
58
- end
59
-
60
- @product = @products.includes(:master).
61
- friendly.
62
- find(params[:id])
55
+ @product = current_store.products.for_user(try_spree_current_user).friendly.find(params[:id])
63
56
  end
64
57
 
65
58
  def load_taxon
66
- @taxon = Spree::Taxon.find(params[:taxon]) if params[:taxon].present?
59
+ @taxon = taxons_scope.find(params[:taxon]) if params[:taxon].present?
60
+ end
61
+
62
+ def can_show_product?
63
+ raise ActiveRecord::RecordNotFound if @product.stores.exclude?(current_store)
67
64
  end
68
65
 
69
66
  def load_variants
@@ -122,5 +119,9 @@ module Spree
122
119
 
123
120
  [product_last_modified, current_store_last_modified].compact.max
124
121
  end
122
+
123
+ def taxons_scope
124
+ current_store.taxons
125
+ end
125
126
  end
126
127
  end
@@ -1,8 +1,18 @@
1
1
  module Spree
2
- class StoreController < Spree::BaseController
2
+ class StoreController < ApplicationController
3
+ include Spree::Core::ControllerHelpers::Auth
4
+ include Spree::Core::ControllerHelpers::Common
5
+ include Spree::Core::ControllerHelpers::Search
6
+ include Spree::Core::ControllerHelpers::Store
7
+ include Spree::Core::ControllerHelpers::StrongParameters
8
+ include Spree::Core::ControllerHelpers::Locale
9
+ include Spree::Core::ControllerHelpers::Currency
3
10
  include Spree::Core::ControllerHelpers::Order
4
11
  include Spree::LocaleUrls
5
12
 
13
+ respond_to :html
14
+
15
+ helper 'spree/base'
6
16
  helper 'spree/locale'
7
17
  helper 'spree/currency'
8
18
 
@@ -50,5 +60,19 @@ module Spree
50
60
  def store_last_modified
51
61
  (current_store.updated_at || Time.current).utc
52
62
  end
63
+
64
+ def redirect_unauthorized_access
65
+ if try_spree_current_user
66
+ flash[:error] = Spree.t(:authorization_failure)
67
+ redirect_to spree.forbidden_path
68
+ else
69
+ store_location
70
+ if respond_to?(:spree_login_path)
71
+ redirect_to spree_login_path
72
+ else
73
+ redirect_to spree.root_path
74
+ end
75
+ end
76
+ end
53
77
  end
54
78
  end
@@ -6,8 +6,6 @@ module Spree
6
6
 
7
7
  before_action :load_taxon
8
8
 
9
- respond_to :html
10
-
11
9
  def show
12
10
  if !http_cache_enabled? || stale?(etag: etag, last_modified: last_modified, public: true)
13
11
  load_products
@@ -32,11 +30,17 @@ module Spree
32
30
  end
33
31
 
34
32
  def load_taxon
35
- @taxon = Spree::Taxon.friendly.find(params[:id])
33
+ @taxon = current_store.taxons.friendly.find(params[:id])
36
34
  end
37
35
 
38
36
  def load_products
39
- @searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
37
+ search_params = params.merge(
38
+ current_store: current_store,
39
+ taxon: @taxon,
40
+ include_images: true
41
+ )
42
+
43
+ @searcher = build_searcher(search_params)
40
44
  @products = @searcher.retrieve_products
41
45
  end
42
46
 
@@ -57,7 +61,10 @@ module Spree
57
61
  end
58
62
 
59
63
  def last_modified
60
- @taxon.updated_at&.utc
64
+ taxon_last_modified = @taxon&.updated_at&.utc
65
+ current_store_last_modified = current_store.updated_at.utc
66
+
67
+ [taxon_last_modified, current_store_last_modified].compact.max
61
68
  end
62
69
  end
63
70
  end