diff --git a/Gemfile.lock b/Gemfile.lock index 36c6695..1d340a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,7 +145,7 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) - colorize (0.7.3) + colorize (0.7.4) database_cleaner (1.3.0) deface (1.0.1) colorize (>= 0.5.8) diff --git a/README.md b/README.md index ea1a71c..7bb2566 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Spree Waiting List ================ +[![Code Climate](https://codeclimate.com/github/ddomingues/spree_waiting_list/badges/gpa.svg)](https://codeclimate.com/github/ddomingues/spree_waiting_list) A waiting list extension for Spree. diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 565b06c..2cd5b82 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -1,3 +1,7 @@ Spree::Product.class_eval do has_many :stock_requests + + def notify_waiting_list + stock_requests.without_variant.notified(false).each &:notify! + end end diff --git a/app/models/spree/stock_item_decorator.rb b/app/models/spree/stock_item_decorator.rb index e25437a..4fc6b63 100644 --- a/app/models/spree/stock_item_decorator.rb +++ b/app/models/spree/stock_item_decorator.rb @@ -11,8 +11,7 @@ def notify_availability yield if available - variant.stock_requests.notified(false).each &:notify! - variant.product.stock_requests.without_variant.notified(false).each &:notify! + variant.notify_waiting_list end end diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index a248b71..1f794da 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -2,6 +2,11 @@ module Spree Variant.class_eval do has_many :stock_requests + + def notify_waiting_list + stock_requests.notified(false).each &:notify! + product.notify_waiting_list + end end end