spree_my_favourites 2.2.5 → 2.2.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e138eb08cb7bd31035ef5f66c10fe1fa061070ca
4
- data.tar.gz: 893f57b744021c6908bf3ea7f9de086bc5c6691f
3
+ metadata.gz: ca15c424578e7cce907fead66f437544466cf821
4
+ data.tar.gz: 204a968c3deee63617596830e0bf08da6474e840
5
5
  SHA512:
6
- metadata.gz: 6f31e7e6ae122d84cef74cac190435157b99afd677d19fdaf553ddc60f2205b3b0f072cc9b26b5fa151e7f5a093800d6c292eeef378acf222db4a84ad5856462
7
- data.tar.gz: c91c96335fc354810f6da2f6a078eebbde7c88f41e2f979607d54ddbf32f4746eb8d082dab6f0b2cf6dedbea2b82ce378f2c5a14f0d962c32db02e3ad692e6e4
6
+ metadata.gz: 2f94190ef6e7ed0f5837952a004cc69820a31e92df789a873d274c52f284a00cd3ffe5c654bd53118fd15e530a78bba68defc690d549c1a862a525fe1bf19c86
7
+ data.tar.gz: 3a4092c53fb95329f20595d518fe9280d067354d0b72e178b5550e4d5742f6bd8690c4817441ef29dfb5fe261e10a1843ac9978755cedbc81f44ae17319e808b
data/README.md CHANGED
@@ -4,6 +4,8 @@ SpreeMyFavourites
4
4
  Adds a My Favourites page to the My Account section of spree frontend. At the moment, the favourites list is
5
5
  just all the items a customer has ordered, sorted by the number of times they have been ordered.
6
6
 
7
+ This gem can also be used with the Spree Quick Cart gem (https://github.com/frankmt/spree_quick_cart), so that an Add to Cart button is added to the favourites table
8
+
7
9
  Installation
8
10
  ------------
9
11
 
@@ -22,16 +22,29 @@
22
22
 
23
23
  .account-my-favourites {
24
24
 
25
+ nav.pagination {
26
+ margin-top: 10px;
27
+ }
28
+
25
29
  table {
26
30
 
27
31
  width: 100%;
28
32
 
33
+ th.favourite-image, td.favourite-image {
34
+ width: 20%;
35
+ }
36
+
29
37
  th.favourite-description, td.favourite-description {
30
- width: 70%;
38
+ width: 35%;
39
+ }
40
+
41
+ th.favourite-price, td.favourite-price {
42
+ width: 15%;
43
+ text-align: center;
31
44
  }
32
45
 
33
- th.favourite-number-orders, td.favourite-number-orders {
34
- width: 30%;
46
+ th.favourite-add-to-cart, td.favourite-add-to-cart {
47
+ width: 40%;
35
48
  text-align: center;
36
49
  }
37
50
  }
@@ -7,16 +7,7 @@ module Spree
7
7
  def index
8
8
  @user = try_spree_current_user
9
9
  if @user
10
- @line_items_by_variant = Spree::Variant.includes(line_items: [:order])
11
- .where(['spree_orders.email = ?', @user.email])
12
- .where(['spree_orders.completed_at IS NOT NULL'])
13
- .references(:orders).group('spree_variants.id')
14
- .order('COUNT(spree_line_items.id) DESC').page(params[:page] || 1).per(15)
15
-
16
- @favourites = []
17
- @line_items_by_variant.count('spree_line_items.id').each do |variant_id, number_of_orders|
18
- @favourites << {variant: Spree::Variant.find(variant_id), number_of_orders: number_of_orders}
19
- end
10
+ @favourites = Spree::Variant.favourites_by_user(@user).page(params[:page] ||= 1).per(15)
20
11
  else
21
12
  unauthorized
22
13
  end
@@ -0,0 +1,13 @@
1
+ Spree::Variant.class_eval do
2
+
3
+ def self.favourites_by_user(user)
4
+ Spree::Variant.joins(line_items: [order: [:user]])
5
+ .where(['spree_users.id = ?', user.id])
6
+ .where(['spree_orders.completed_at IS NOT NULL'])
7
+ .references(:orders)
8
+ .group('spree_variants.id')
9
+ .order('COUNT(spree_line_items.id) DESC')
10
+ .select('spree_variants.*')
11
+ end
12
+
13
+ end
@@ -3,8 +3,8 @@
3
3
 
4
4
  .account-my-favourites(data-hook="account_my_favourites")
5
5
  - if @favourites.present?
6
- = render partial: "spree/account/favourites/table", locals: {favourites: @favourites}
6
+ = render partial: "spree/shared/user_favourites_table", locals: {favourites: @favourites}
7
7
 
8
- = paginate(@line_items_by_variant)
8
+ = paginate(@favourites)
9
9
  - else
10
10
  %p= Spree.t(:you_have_no_orders_yet)
@@ -0,0 +1,21 @@
1
+ %table.favourites-summary
2
+ %thead
3
+ %tr
4
+ %th.favourite-image
5
+ %th.favourite-description= Spree.t(:name)
6
+ %th.favourite-price= Spree.t(:price)
7
+ - if SpreeMyFavourites::Config.use_quick_add_to_cart_form
8
+ %th.favourite-add-to-cart
9
+ %tbody
10
+ - favourites.each do |favourite|
11
+ %tr
12
+ %td.favourite-image
13
+ - if favourite.images.length == 0
14
+ = link_to mini_image(favourite.product), favourite.product
15
+ - else
16
+ = link_to image_tag(favourite.images.first.attachment.url(:mini)), favourite.product
17
+ %td.favourite-description(data-hook='favourite_name')= favourite.name
18
+ %td.favourite-price= display_price(favourite)
19
+ - if SpreeMyFavourites::Config.use_quick_add_to_cart_form
20
+ %td.favourite-add-to-cart
21
+ = render partial: "spree/shared/quick_cart_add_button", locals: {product: favourite.product}
@@ -0,0 +1,5 @@
1
+ module SpreeMyFavourites
2
+ class Configuration < Spree::Preferences::Configuration
3
+ preference :use_quick_add_to_cart_form, :boolean, default: false
4
+ end
5
+ end
@@ -6,6 +6,10 @@ module SpreeMyFavourites
6
6
 
7
7
  config.autoload_paths += %W(#{config.root}/lib)
8
8
 
9
+ initializer "spree.spree_my_favourites.preferences", :after => "spree.environment" do |app|
10
+ SpreeMyFavourites::Config = SpreeMyFavourites::Configuration.new
11
+ end
12
+
9
13
  # use rspec for tests
10
14
  config.generators do |g|
11
15
  g.test_framework :rspec
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_my_favourites'
5
- s.version = '2.2.5'
5
+ s.version = '2.2.6'
6
6
  s.summary = 'Adds My Favourites tab to My Account section of the website'
7
7
  s.required_ruby_version = '>= 2.0.0'
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_my_favourites
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.5
4
+ version: 2.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Trindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -239,10 +239,11 @@ files:
239
239
  - app/assets/stylesheets/spree/frontend/spree_my_favourites.css
240
240
  - app/controllers/spree/account/favourites_controller.rb
241
241
  - app/controllers/spree/account/orders_controller.rb
242
- - app/views/spree/account/favourites/_table.haml
242
+ - app/models/spree/variant_decorator.rb
243
243
  - app/views/spree/account/favourites/index.haml
244
244
  - app/views/spree/account/orders/index.haml
245
245
  - app/views/spree/shared/_account_header.haml
246
+ - app/views/spree/shared/_user_favourites_table.haml
246
247
  - app/views/spree/shared/_user_orders.haml
247
248
  - app/views/spree/users/show.haml
248
249
  - bin/rails
@@ -250,6 +251,7 @@ files:
250
251
  - config/routes.rb
251
252
  - lib/generators/spree_my_favourites/install/install_generator.rb
252
253
  - lib/spree_my_favourites.rb
254
+ - lib/spree_my_favourites/configuration.rb
253
255
  - lib/spree_my_favourites/engine.rb
254
256
  - lib/spree_my_favourites/factories.rb
255
257
  - spec/controllers/spree/account/favourites_controller_spec.rb
@@ -1,15 +0,0 @@
1
- %table.favourites-summary
2
- %thead
3
- %tr
4
- %th.favourite-description= Spree.t(:name)
5
- %th.favourite-number-orders= Spree.t(:number_of_orders)
6
- %tbody
7
- - favourites.each do |favourite|
8
- %tr
9
- %td.favourite-image
10
- - if variant.images.length == 0
11
- = link_to mini_image(variant.product), variant.product
12
- - else
13
- = link_to image_tag(variant.images.first.attachment.url(:small)), variant.product
14
- %td.favourite-description= favourite[:variant].name
15
- %td.favourite-number-orders= favourite[:number_of_orders]