rees46_spree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +15 -0
  4. data/Rakefile +21 -0
  5. data/app/controllers/rees46_spree/recommendations_controller.rb +14 -0
  6. data/app/controllers/spree/checkout_controller_decorator.rb +8 -0
  7. data/app/models/spree/product_decorator.rb +5 -0
  8. data/app/overrides/events.rb +33 -0
  9. data/app/overrides/recommenders.rb +27 -0
  10. data/app/views/rees46_spree/recommendations/_block.html.erb +9 -0
  11. data/app/views/rees46_spree/recommendations/_product.html.erb +7 -0
  12. data/app/views/rees46_spree/recommendations/show.html.erb +1 -0
  13. data/app/views/rees46_spree/recommenders/_cart.html.erb +13 -0
  14. data/app/views/rees46_spree/recommenders/_category.html.erb +27 -0
  15. data/app/views/rees46_spree/recommenders/_home.html.erb +13 -0
  16. data/app/views/rees46_spree/recommenders/_product.html.erb +27 -0
  17. data/app/views/spree/rees46/_init.html.erb +6 -0
  18. data/app/views/spree/rees46/events/_cart.html.erb +14 -0
  19. data/app/views/spree/rees46/events/_purchase.html.erb +13 -0
  20. data/app/views/spree/rees46/events/_remove_from_cart.html.erb +14 -0
  21. data/app/views/spree/rees46/events/_view.html.erb +12 -0
  22. data/config/locales/rees46.en.yml +9 -0
  23. data/config/routes.rb +3 -0
  24. data/lib/generators/rees46_spree/rees46_spree_generator.rb +25 -0
  25. data/lib/generators/rees46_spree/templates/initializer.rb +7 -0
  26. data/lib/rees46_spree.rb +15 -0
  27. data/lib/rees46_spree/configuration.rb +6 -0
  28. data/lib/rees46_spree/engine.rb +17 -0
  29. data/lib/rees46_spree/params_extractor.rb +7 -0
  30. data/lib/rees46_spree/version.rb +3 -0
  31. data/lib/tasks/rees46_spree_tasks.rake +4 -0
  32. data/spec/dummy/README.rdoc +28 -0
  33. data/spec/dummy/Rakefile +6 -0
  34. data/spec/dummy/app/assets/javascripts/admin/all.js +12 -0
  35. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  36. data/spec/dummy/app/assets/javascripts/store/all.js +12 -0
  37. data/spec/dummy/app/assets/stylesheets/admin/all.css +11 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/spec/dummy/app/assets/stylesheets/store/all.css +11 -0
  40. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  41. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  42. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/spec/dummy/bin/bundle +3 -0
  44. data/spec/dummy/bin/rails +4 -0
  45. data/spec/dummy/bin/rake +4 -0
  46. data/spec/dummy/config.ru +4 -0
  47. data/spec/dummy/config/application.rb +36 -0
  48. data/spec/dummy/config/boot.rb +5 -0
  49. data/spec/dummy/config/database.yml +25 -0
  50. data/spec/dummy/config/environment.rb +5 -0
  51. data/spec/dummy/config/environments/development.rb +29 -0
  52. data/spec/dummy/config/environments/production.rb +80 -0
  53. data/spec/dummy/config/environments/test.rb +36 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/devise.rb +1 -0
  56. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/spec/dummy/config/initializers/inflections.rb +16 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  59. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  60. data/spec/dummy/config/initializers/session_store.rb +3 -0
  61. data/spec/dummy/config/initializers/spree.rb +14 -0
  62. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/spec/dummy/config/locales/en.yml +23 -0
  64. data/spec/dummy/config/routes.rb +4 -0
  65. data/spec/dummy/config/spree.yml +2 -0
  66. data/spec/dummy/db/schema.rb +702 -0
  67. data/spec/dummy/db/seeds.rb +4 -0
  68. data/spec/dummy/log/development.log +7015 -0
  69. data/spec/dummy/log/test.log +30207 -0
  70. data/spec/dummy/public/404.html +58 -0
  71. data/spec/dummy/public/422.html +58 -0
  72. data/spec/dummy/public/500.html +57 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/features/init_script_addition_spec.rb +9 -0
  75. data/spec/features/push_events_spec.rb +13 -0
  76. data/spec/generators/rees46_spree/rees46_spree_generator_spec.rb +13 -0
  77. data/spec/rees46_spree/params_extractor.rb +13 -0
  78. data/spec/rees46_spree_spec.rb +10 -0
  79. data/spec/spec_helper.rb +39 -0
  80. metadata +311 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54ce0827d034b7de918bc79ef1f5227725a0d932
4
+ data.tar.gz: e7857c6174605ae960945ad7f13f84ba62b2460a
5
+ SHA512:
6
+ metadata.gz: 8f3573aec156943d10fb7ce0d8f0f2dbded533e71f92241e503b8f1dcbb57198ae597322a180b27a4552d3d0f936793b012eec6d70bef1550e35661d011769cd
7
+ data.tar.gz: 13716e9661c86a56dda3abb3e59e726ed0b237288ba2af6fea547e6bb9cb0ba978afc0c3f1154e95445980322838c7ef8912100c22785ed09416484e3c85fa4f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ rees46_spree
2
+ ================
3
+ REES46 plugin for Spree
4
+
5
+ Installation
6
+ ----------------
7
+ TODO
8
+
9
+ Usage
10
+ ----------------
11
+ TODO
12
+
13
+ Additional notes
14
+ ----------------
15
+ TODO
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+
9
+ load 'rails/tasks/engine.rake'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
14
+
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ desc "Run all specs in spec directory (excluding plugin specs)"
19
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
20
+
21
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ module Rees46Spree
2
+ class RecommendationsController < Spree::StoreController
3
+ layout false
4
+
5
+ def show
6
+ raise(ArgumentError, 'Recommender name is not provided') if params[:recommended_by].blank?
7
+
8
+ @products = Spree::Product.where(id: params[:ids].split(','))
9
+ @recommended_by = params[:recommended_by]
10
+
11
+ render nothing: true if @products.none?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ Spree::CheckoutController.class_eval do
2
+ private
3
+ def completion_route
4
+ session[:just_purchased] = true
5
+
6
+ spree.order_path(@order)
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ Spree::Product.class_eval do
2
+ def rees46_category_id
3
+ self.classifications.map{|c| c.taxon.taxonomy_id }.sort.first
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ [
2
+ {
3
+ :virtual_path => 'spree/layouts/spree_application',
4
+ :insert_bottom => 'body',
5
+ :partial => 'spree/rees46/init'
6
+ },
7
+
8
+ {
9
+ :virtual_path => 'spree/products/show',
10
+ :insert_bottom => '[data-hook="product_show"]',
11
+ :partial => 'spree/rees46/events/view'
12
+ },
13
+
14
+ {
15
+ :virtual_path => 'spree/products/show',
16
+ :insert_bottom => '[data-hook="product_show"]',
17
+ :partial => 'spree/rees46/events/cart'
18
+ },
19
+
20
+ {
21
+ :virtual_path => 'spree/orders/_line_item',
22
+ :insert_bottom => '[data-hook="cart_item_delete"]',
23
+ :partial => 'spree/rees46/events/remove_from_cart'
24
+ },
25
+
26
+ {
27
+ :virtual_path => 'spree/orders/show',
28
+ :insert_bottom => 'div#order',
29
+ :partial => 'spree/rees46/events/purchase'
30
+ },
31
+ ].each do |o|
32
+ Deface::Override.new(o.merge({name: "add_#{o[:partial].gsub('/', '_')}"}))
33
+ end
@@ -0,0 +1,27 @@
1
+ [
2
+ {
3
+ :virtual_path => 'spree/home/index',
4
+ :insert_after => '[data-hook="homepage_products"]',
5
+ :partial => 'rees46_spree/recommenders/home'
6
+ },
7
+
8
+ {
9
+ :virtual_path => 'spree/taxons/show',
10
+ :insert_after => '[data-hook="taxon_children"]',
11
+ :partial => 'rees46_spree/recommenders/category'
12
+ },
13
+
14
+ {
15
+ :virtual_path => 'spree/products/show',
16
+ :insert_bottom => '[data-hook="product_right_part"]',
17
+ :partial => 'rees46_spree/recommenders/product'
18
+ },
19
+
20
+ {
21
+ :virtual_path => 'spree/orders/edit',
22
+ :insert_bottom => '[data-hook="cart_container"]',
23
+ :partial => 'rees46_spree/recommenders/cart'
24
+ }
25
+ ].each do |o|
26
+ Deface::Override.new(o.merge({name: "add_#{o[:partial].gsub('/', '_')}"}))
27
+ end
@@ -0,0 +1,9 @@
1
+ <div class='recommendations-container'>
2
+ <h1><%= t("rees46.titles.#{recommended_by}") %></h1>
3
+
4
+ <ul id="products" class="inline product-listing" data-hook>
5
+ <% products.each do |product| %>
6
+ <%= render(partial: 'product', locals: { product: product, recommended_by: recommended_by }) %>
7
+ <% end %>
8
+ </ul>
9
+ </div>
@@ -0,0 +1,7 @@
1
+ <li id="product_<%= product.id %>" class="columns three <%= cycle("alpha", "secondary", "", "omega secondary", :name => "classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product">
2
+ <div class="product-image">
3
+ <%= link_to small_image(product, :itemprop => "image"), spree.product_path(product, recommended_by: recommended_by), :itemprop => 'url' %>
4
+ </div>
5
+ <%= link_to truncate(product.name, :length => 50), spree.product_path(product, recommended_by: recommended_by), :class => 'info', :itemprop => "name", :title => product.name %>
6
+ <span class="price selling" itemprop="price"><%= display_price(product) %></span>
7
+ </li>
@@ -0,0 +1 @@
1
+ <%= render(partial: 'block', locals: { products: @products, recommended_by: @recommended_by, title: 'Recommended' }) %>
@@ -0,0 +1,13 @@
1
+ <div id="rees46_see_also"></div>
2
+
3
+ <script type="text/javascript">
4
+ $(function () {
5
+ REES46.addReadyListener(function () {
6
+ REES46.recommend('see_also', function(response) {
7
+ $.get('rees46/recommendations?recommended_by=' + 'see_also' + '&ids=' + response.join(','), function(data) {
8
+ $('#rees46_see_also').html(data);
9
+ });
10
+ }, <%= current_order.line_items.map{|li| li.product.id } %>);
11
+ });
12
+ });
13
+ </script>
@@ -0,0 +1,27 @@
1
+ <div id="rees46_category_popular"></div>
2
+ <div id="rees46_recently_viewed"></div>
3
+ <div id="rees46_interesting"></div>
4
+
5
+ <script type="text/javascript">
6
+ $(function () {
7
+ REES46.addReadyListener(function () {
8
+ REES46.recommend('popular', function(response) {
9
+ $.get('/rees46/recommendations?recommended_by=' + 'popular' + '&ids=' + response.join(','), function(data) {
10
+ $('#rees46_category_popular').html(data);
11
+ });
12
+ }, <%= @taxon.taxonomy_id %>);
13
+
14
+ REES46.recommend('recently_viewed', function(response) {
15
+ $.get('/rees46/recommendations?recommended_by=' + 'recently_viewed' + '&ids=' + response.join(','), function(data) {
16
+ $('#rees46_recently_viewed').html(data);
17
+ });
18
+ });
19
+
20
+ REES46.recommend('interesting', function(response) {
21
+ $.get('/rees46/recommendations?recommended_by=' + 'interesting' + '&ids=' + response.join(','), function(data) {
22
+ $('#rees46_interesting').html(data);
23
+ });
24
+ });
25
+ });
26
+ });
27
+ </script>
@@ -0,0 +1,13 @@
1
+ <div id="rees46_home_recommener"></div>
2
+
3
+ <script type="text/javascript">
4
+ $(function () {
5
+ REES46.addReadyListener(function () {
6
+ REES46.recommend('popular', function(response) {
7
+ $.get('rees46/recommendations?recommended_by=' + 'popular' + '&ids=' + response.join(','), function(data) {
8
+ $('#rees46_home_recommener').html(data);
9
+ });
10
+ });
11
+ });
12
+ });
13
+ </script>
@@ -0,0 +1,27 @@
1
+ <div id="rees46_also_bought"></div>
2
+ <div id="rees46_similar"></div>
3
+ <div id="rees46_interesting"></div>
4
+
5
+ <script type="text/javascript">
6
+ $(function () {
7
+ REES46.addReadyListener(function () {
8
+ REES46.recommend('also_bought', function(response) {
9
+ $.get('/rees46/recommendations?recommended_by=' + 'also_bought' + '&ids=' + response.join(','), function(data) {
10
+ $('#rees46_also_bought').html(data);
11
+ });
12
+ }, <%= @product.id %>);
13
+
14
+ REES46.recommend('similar', function(response) {
15
+ $.get('/rees46/recommendations?recommended_by=' + 'similar' + '&ids=' + response.join(','), function(data) {
16
+ $('#rees46_similar').html(data);
17
+ });
18
+ }, <%= @product.id %>, <%= current_order.line_items.map{|li| li.product.id } %>);
19
+
20
+ REES46.recommend('interesting', function(response) {
21
+ $.get('/rees46/recommendations?recommended_by=' + 'interesting' + '&ids=' + response.join(','), function(data) {
22
+ $('#rees46_interesting').html(data);
23
+ });
24
+ });
25
+ });
26
+ });
27
+ </script>
@@ -0,0 +1,6 @@
1
+ <script src="//cdn.rees46.com/rees46_script.js"></script>
2
+ <script type="text/javascript">
3
+ $(function () {
4
+ REES46.init('<%= Rees46Spree.configuration.shop_token %>', <%= spree_user_signed_in? ? current_spree_user.id : 'null' %>);
5
+ })
6
+ </script>
@@ -0,0 +1,14 @@
1
+ <script type='text/javascript'>
2
+ $(function () {
3
+ REES46.addReadyListener(function () {
4
+ $('#add-to-cart-button').click(function () {
5
+ REES46.pushData('cart', {
6
+ item_id: '<%= @product.id %>',
7
+ price: '<%= @product.price %>',
8
+ is_available: '<%= @product.available? ? '1' : '0' %>',
9
+ category_id: '<%= @product.rees46_category_id %>'
10
+ });
11
+ });
12
+ });
13
+ });
14
+ </script>
@@ -0,0 +1,13 @@
1
+ <script type='text/javascript'>
2
+ <% if session[:just_purchased] == true %>
3
+ $(function () {
4
+ REES46.addReadyListener(function () {
5
+ <% line_items = @order.line_items.map{|li| { item_id: li.product.id, price: li.product.price, is_available: (li.product.available? ? '1' : '0'), category_id: li.product.rees46_category_id, amount: li.quantity } } %>
6
+
7
+ REES46.pushData('purchase', <%= line_items.to_json.html_safe %>, '<%= @order.id %>');
8
+ });
9
+ });
10
+
11
+ <% session.delete(:just_purchased) %>
12
+ <% end %>
13
+ </script>
@@ -0,0 +1,14 @@
1
+ <script type='text/javascript'>
2
+ $(function () {
3
+ REES46.addReadyListener(function () {
4
+ $('#delete_<%= dom_id(line_item) %>').click(function () {
5
+ REES46.pushData('remove_from_cart', {
6
+ item_id: '<%= line_item.product.id %>',
7
+ price: '<%= line_item.product.price %>',
8
+ is_available: '<%= line_item.product.available? ? '1' : '0' %>',
9
+ category_id: '<%= line_item.product.rees46_category_id %>'
10
+ });
11
+ });
12
+ });
13
+ });
14
+ </script>
@@ -0,0 +1,12 @@
1
+ <script type='text/javascript'>
2
+ $(function () {
3
+ REES46.addReadyListener(function () {
4
+ REES46.pushData('view', {
5
+ item_id: '<%= @product.id %>',
6
+ price: '<%= @product.price %>',
7
+ is_available: '<%= @product.available? ? '1' : '0' %>',
8
+ category_id: '<%= @product.rees46_category_id %>'
9
+ });
10
+ });
11
+ });
12
+ </script>
@@ -0,0 +1,9 @@
1
+ en:
2
+ rees46:
3
+ titles:
4
+ interesting: May Be Interesting To You
5
+ also_bought: With This Also Bought
6
+ similar: Similar Products
7
+ popular: Popular
8
+ see_also: See Also
9
+ recently_viewed: Recently Viewed
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rees46Spree::Engine.routes.draw do
2
+ get 'recommendations', to: 'recommendations#show'
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/named_base'
3
+
4
+ module Rees46Spree
5
+ module Generators
6
+ class Rees46SpreeGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
8
+
9
+ argument :shop_token, :type => :string, :banner => 'shop_token', :default => 'YOUR_SHOP_TOKEN_HERE'
10
+
11
+ def create_initializer
12
+ exit if already_configured?
13
+
14
+ route "mount Rees46Spree::Engine, at: '/rees46'"
15
+
16
+ template 'initializer.rb', 'config/initializers/rees46_spree.rb',
17
+ :assigns => { :shop_token => shop_token }
18
+ end
19
+
20
+ def already_configured?
21
+ File.exists?('config/initializers/rees46_spree.rb')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ Rees46Spree.configure do |config|
2
+ config.shop_token = '<%= shop_token %>'
3
+
4
+ if Rails.env.test? or Rails.env.development?
5
+ config.enabled = false
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'rees46_spree/engine'
2
+ require 'rees46_spree/configuration'
3
+ require 'rees46_spree/params_extractor'
4
+
5
+ module Rees46Spree
6
+ class << self
7
+ def configure
8
+ yield configuration
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Rees46Spree
2
+ class Configuration
3
+ attr_accessor :shop_token
4
+ attr_accessor :enabled
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Rees46Spree
2
+ class Engine < ::Rails::Engine
3
+ require 'spree/core'
4
+ require 'spree/frontend'
5
+ isolate_namespace Rees46Spree
6
+ engine_name 'rees46_spree'
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
12
+ Rails.configuration.cache_classes ? require(c) : load(c)
13
+ end
14
+ end
15
+ config.to_prepare &method(:activate).to_proc
16
+ end
17
+ end