spree_waiting_list 2.3.2 → 2.3.3

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: b6428996ed78ef117f6e7b97f3199967bfe716a4
4
- data.tar.gz: 68d879b9d928998cb64337b474c6fe9befbe0d23
3
+ metadata.gz: c305dc7d9b374eed545dfb74cc2ec7b630bddea3
4
+ data.tar.gz: 31fd58246479ab7448db7f0ff48096b742efde37
5
5
  SHA512:
6
- metadata.gz: d5cff40a9ffbc90d2aa505b1ec3eb7378deb53abe165408223396406e2590ef555959ac3b35fb8103517abd6d72e1d61a131a60e589b83e44a305024acb14225
7
- data.tar.gz: 12b89d1444d8a21df61e1179d64dbc754c9b1383b18b55f13e0523c63a5d537a7ff02171fcc37fba1dcc26d554d20749df3e33d76e5f5df8a9585ea816d63618
6
+ metadata.gz: 47caac25c7b726b29deddc3579db3d19efd7e4154004c535790e7b18c57bdf48722fa1d71ad529512a670a07f5ea0eef9dd9a13a30b9481f00a802fa5d6cd7f9
7
+ data.tar.gz: 6270a821a131de2968679931ac39fcad60c3c1b7dd01313a8df99621b7e0393bfaa6a0a9d0531ca7c9167bccbfa87f9565aea602df38baabbb9ccba2a06e62c8
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ Spree Waiting List
2
+ ================
3
+ [![Build Status](https://travis-ci.org/DynamoMTL/spree_waiting_list.svg?branch=master)](https://travis-ci.org/DynamoMTL/spree_waiting_list) [![Code Climate](https://codeclimate.com/github/DynamoMTL/spree_waiting_list/badges/gpa.svg)](https://codeclimate.com/github/DynamoMTL/spree_waiting_list) [![Test Coverage](https://codeclimate.com/github/DynamoMTL/spree_waiting_list/badges/coverage.svg)](https://codeclimate.com/github/DynamoMTL/spree_waiting_list) [![Gem Version](https://badge.fury.io/rb/spree_waiting_list.svg)](http://badge.fury.io/rb/spree_waiting_list)
4
+
5
+ A waiting list extension for Spree.
6
+
7
+ Users and guests can request to be notified via email when a product/variant comes back in stock.
8
+
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Add spree_waiting_list to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'spree_waiting_list'
17
+ ```
18
+
19
+ Bundle your dependencies and run the installation generator:
20
+
21
+ ```shell
22
+ bundle
23
+ bundle exec rails g spree_waiting_list:install
24
+ ```
25
+
26
+ Testing
27
+ -------
28
+
29
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app should be regenerated by using `rake test_app`.
30
+
31
+ ```shell
32
+ bundle
33
+ bundle exec rake test_app
34
+ bundle exec rspec spec
35
+ ```
36
+
37
+ When testing your applications integration with this extension you may use it's factories.
38
+ Simply add this require statement to your spec_helper:
39
+
40
+ ```ruby
41
+ require 'spree_waiting_list/factories'
42
+ ```
43
+
44
+
45
+ Copyright (c) 2015 Joshua Nussbaum, released under the New BSD License
@@ -0,0 +1,8 @@
1
+ Spree::Admin::ReportsController.class_eval do
2
+ add_available_report! :stock_requests
3
+
4
+ def stock_requests
5
+ @search = Spree::StockRequest.ransack(params[:q])
6
+ @stock_requests = @search.result
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ class StockRequestsController < StoreController
3
+ layout false
4
+
5
+ def new
6
+ @stock_request = StockRequest.new(stock_request_params)
7
+ end
8
+
9
+ def create
10
+ @stock_request = StockRequest.new(stock_request_params)
11
+ @stock_request.email = try_spree_current_user.email if try_spree_current_user
12
+
13
+ respond_to do |format|
14
+ if @stock_request.save
15
+ format.html { redirect_to root_path, notice: Spree.t(:successful_stock_request) }
16
+ format.js
17
+ format.json { render json: { status: 201, message: Spree.t(:successful_stock_request) } }
18
+ else
19
+ format.html { render action: 'new'}
20
+ format.json { render json: @stock_request.errors, status: :unprocessable_entity }
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def stock_request_params
28
+ params.require(:stock_request).permit(permitted_attributes.stock_request_attributes)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ Spree::UserMailer.class_eval do
2
+ def back_in_stock(stock_request)
3
+ @request = stock_request
4
+ @product = stock_request.product
5
+ @variant = stock_request.variant
6
+
7
+ mail(:subject => Spree.t(:back_in_stock_subject, :product_name => @product.name),
8
+ :from => from_address,
9
+ :to => stock_request.email)
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ Spree::PermittedAttributes.class_eval do
2
+ @@stock_request_attributes = [:email, :variant_id]
3
+ end
4
+
5
+ module Spree
6
+ module PermittedAttributes
7
+ class << self
8
+ mattr_reader :stock_request_attributes
9
+
10
+ ATTRIBUTES << :stock_request_attributes
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ StockItem.class_eval do
3
+ around_save :notify_availability
4
+
5
+ private
6
+ def notify_availability
7
+ available = count_on_hand_was <= 0 && count_on_hand > 0 && count_on_hand_changed?
8
+
9
+ yield
10
+
11
+ if available
12
+ variant.notify_waiting_list
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ module Spree
2
+ class StockRequest < ActiveRecord::Base
3
+ belongs_to :variant
4
+ delegate :product, :to => :variant
5
+
6
+ validates :email, :presence => true,
7
+ :format => {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i}
8
+
9
+ default_scope { order('created_at desc') }
10
+
11
+ scope :notified, lambda { |is_notified| where(:status => is_notified ? 'notified' : 'new') }
12
+
13
+ state_machine :status, :initial => 'new' do
14
+ event :notify do
15
+ transition :from => 'new', :to => 'notified'
16
+ end
17
+
18
+ after_transition :to => 'notified', :do => :send_email
19
+ end
20
+
21
+ private
22
+
23
+ def send_email
24
+ UserMailer.back_in_stock(self).deliver
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ Variant.class_eval do
3
+ has_many :stock_requests
4
+
5
+ def waiting_list
6
+ stock_requests.notified(false)
7
+ end
8
+
9
+ def notify_waiting_list
10
+ waiting_list.each &:notify!
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ <%= %w(email sku product variant status requested).collect{|h| "\"#{t(h)}\""}.join(',').html_safe %>
2
+ <% @stock_requests.each do |request| %>
3
+ <%= [request.email,
4
+ request.variant.sku,
5
+ request.product.name,
6
+ request.variant.options_text,
7
+ request.status.titleize,
8
+ request.created_at.to_s(:short)].collect{|cell| "\"#{cell}\"" }.join(",").html_safe %>
9
+ <% end %>
@@ -0,0 +1,27 @@
1
+ - content_for :page_title do
2
+ = Spree.t(:stock_requests)
3
+ - content_for :page_actions do
4
+ %li= link_to_with_icon 'icon-arrow-left', Spree.t(:back_to_reports_list), spree.admin_reports_url, :class => 'button'
5
+ - content_for :table_filter_title do
6
+ = Spree.t(:date_range)
7
+ - content_for :table_filter do
8
+ = render :partial => 'spree/admin/shared/stock_report_criteria', :locals => {}
9
+ %table.admin-report{"data-hook" => "stock_requests"}
10
+ %thead
11
+ %tr
12
+ %th= sort_link @search, :email
13
+ %th= Spree.t(:product)
14
+ %th= Spree.t(:variant)
15
+ %th= sort_link @search, :status
16
+ %th= sort_link @search, :created_at, Spree.t(:requested)
17
+ %tbody
18
+ - @stock_requests.each do |stock_request|
19
+ - next if stock_request.product.nil?
20
+ %tr{:class => "cycle('even', 'odd')"}
21
+ %td= stock_request.email
22
+ %td= link_to stock_request.product.name, edit_admin_product_path(stock_request.product)
23
+ %td= stock_request.variant.options_text if stock_request.variant
24
+ %td= stock_request.status.titleize
25
+ %td
26
+ = time_ago_in_words(stock_request.created_at)
27
+ = Spree.t(:ago)
@@ -0,0 +1,10 @@
1
+ = search_form_for @search, :url => spree.stock_requests_admin_reports_path do |s|
2
+ .date-range-filter.field.align-center
3
+ = label_tag nil, Spree.t(:start), :class => 'inline'
4
+ = s.text_field :created_at_gt, :class => 'datepicker datepicker-from'
5
+ %span.range-divider
6
+ %i.icon-arrow-right
7
+ = s.text_field :created_at_lt, :class => 'datepicker datepicker-to'
8
+ = label_tag nil, Spree.t(:end), :class => 'inline'
9
+ .actions.filter-actions
10
+ = button Spree.t(:search), 'icon-search'
@@ -0,0 +1 @@
1
+ alert('You have been added to the waiting list!');
@@ -0,0 +1,11 @@
1
+ %h1= Spree.t(:new_stock_request)
2
+ = render "spree/shared/error_messages", :target => @stock_request
3
+ = form_for @stock_request do |f|
4
+ = f.hidden_field :variant_id
5
+ %p
6
+ = f.label :email
7
+ - if spree_current_user
8
+ = spree_current_user.email
9
+ - else
10
+ = f.text_field :email
11
+ = f.submit Spree.t(:submit_stock_request)
@@ -0,0 +1 @@
1
+ <%= link_to @product.name, @product %> is back in stock
@@ -0,0 +1,16 @@
1
+ ---
2
+ en:
3
+ out_of_stock_product_requests: Requests for out of stock products
4
+ spree:
5
+ stock_requests: Stock Requests
6
+ created_at: Created
7
+ ago: ago
8
+ show_all: Show all
9
+ download: Download
10
+ variant: Variant
11
+ back_in_stock_subject: Hey! %{product_name} is back in stock
12
+ successful_stock_request: Thanks! we will notify you as soon as the item is back in stock
13
+ stock_requests_description: 'Out of stock product requests'
14
+ new_stock_request: Request New Stock Notification
15
+ submit_stock_request: Send Request
16
+ requested: requested
@@ -0,0 +1,16 @@
1
+ ---
2
+ pt-BR:
3
+ out_of_stock_product_requests: Solicitações para produtos sem estoque
4
+ spree:
5
+ stock_requests: Solicitações de Produtos Indisponíveis
6
+ created_at: Criado
7
+ ago: atrás
8
+ show_all: Mostrar todos
9
+ download: Download
10
+ variant: Variante
11
+ back_in_stock_subject: Olá! %{product_name} está disponível novamente
12
+ successful_stock_request: Obrigado! Nós o notificaremos assim que o produto estiver disponível
13
+ stock_requests_description: Solicitações de Produtos não disponíveis
14
+ new_stock_request: Nova Solicitação de Produto Indisponível
15
+ submit_stock_request: Enviar Solicitação
16
+ requested: solicitado
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ resources :stock_requests
3
+
4
+ namespace :admin do
5
+ resources :reports, :only => [:index, :show] do
6
+ get 'stock_requests', :on => :collection
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ class CreateWaitingLists < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :waiting_lists do |t|
4
+ t.string :email
5
+ t.integer :product_id
6
+ t.integer :variant_id
7
+ t.string :status, :default => 'new'
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :waiting_lists
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class ChangeWaitingListsToStockRequests < ActiveRecord::Migration
2
+ def self.up
3
+ rename_table :waiting_lists, :stock_requests
4
+ end
5
+
6
+ def self.down
7
+ rename_table :stock_requests, :waiting_lists
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class ChangeWaitingListToSpreeWaitingList < ActiveRecord::Migration
2
+ def self.up
3
+ rename_table :stock_requests, :spree_stock_requests
4
+
5
+ add_index :spree_stock_requests, :variant_id
6
+ add_index :spree_stock_requests, :product_id
7
+ end
8
+
9
+ def self.down
10
+ remove_index :spree_stock_requests, column: :variant_id
11
+ remove_index :spree_stock_requests, column: :product_id
12
+
13
+ rename_table :spree_stock_requests, :stock_requests
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveProductFromStockRequest < ActiveRecord::Migration
2
+ def change
3
+ remove_column :spree_stock_requests, :product_id
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module SpreeWaitingList
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ class_option :auto_run_migrations, :type => :boolean, :default => false
6
+
7
+ def add_javascripts
8
+ # append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_waiting_list\n"
9
+ # append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_waiting_list\n"
10
+ end
11
+
12
+ def add_stylesheets
13
+ # inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_waiting_list\n", :before => /\*\//, :verbose => true
14
+ # inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_waiting_list\n", :before => /\*\//, :verbose => true
15
+ end
16
+
17
+ def add_migrations
18
+ run 'bundle exec rake railties:install:migrations FROM=spree_waiting_list'
19
+ end
20
+
21
+ def run_migrations
22
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
23
+ if run_migrations
24
+ run 'bundle exec rake db:migrate'
25
+ else
26
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module SpreeWaitingList
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_waiting_list'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+ end
17
+
18
+ config.to_prepare &method(:activate).to_proc
19
+
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :stock_request, class: Spree::StockRequest do
4
+ variant { |s| s.association(:base_variant) }
5
+ email 'test@home.org'
6
+ end
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'spree_core'
2
+ require 'spree_waiting_list/engine'
3
+ require 'haml'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_waiting_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Nussbaum
@@ -184,7 +184,33 @@ email: joshnuss@gmail.com
184
184
  executables: []
185
185
  extensions: []
186
186
  extra_rdoc_files: []
187
- files: []
187
+ files:
188
+ - LICENSE
189
+ - README.md
190
+ - app/controllers/spree/admin/reports_controller_decorator.rb
191
+ - app/controllers/spree/stock_requests_controller.rb
192
+ - app/mailers/spree/user_mailer_decorator.rb
193
+ - app/models/spree/permitted_attributes_decorator.rb
194
+ - app/models/spree/stock_item_decorator.rb
195
+ - app/models/spree/stock_request.rb
196
+ - app/models/spree/variant_decorator.rb
197
+ - app/views/spree/admin/reports/stock_requests.csv.erb
198
+ - app/views/spree/admin/reports/stock_requests.html.haml
199
+ - app/views/spree/admin/shared/_stock_report_criteria.html.haml
200
+ - app/views/spree/stock_requests/create.js.erb
201
+ - app/views/spree/stock_requests/new.html.haml
202
+ - app/views/spree/user_mailer/back_in_stock.text.erb
203
+ - config/locales/en.yml
204
+ - config/locales/pt-BR.yml
205
+ - config/routes.rb
206
+ - db/migrate/20091127192645_create_waiting_lists.rb
207
+ - db/migrate/20110406120000_change_waiting_lists_to_stock_requests.rb
208
+ - db/migrate/20141210144427_change_waiting_list_to_spree_waiting_list.rb
209
+ - db/migrate/20150131180156_remove_product_from_stock_request.rb
210
+ - lib/generators/spree_waiting_list/install/install_generator.rb
211
+ - lib/spree_waiting_list.rb
212
+ - lib/spree_waiting_list/engine.rb
213
+ - lib/spree_waiting_list/factories.rb
188
214
  homepage: http://www.godynamo.com
189
215
  licenses: []
190
216
  metadata: {}
@@ -205,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
231
  requirements:
206
232
  - none
207
233
  rubyforge_project:
208
- rubygems_version: 2.4.3
234
+ rubygems_version: 2.4.6
209
235
  signing_key:
210
236
  specification_version: 4
211
237
  summary: Add a waiting list to your spree store