Class: SpreeLimitOrderQuantity::MasterVariantQuantityChecker
- Inherits:
-
Object
- Object
- SpreeLimitOrderQuantity::MasterVariantQuantityChecker
- Defined in:
- lib/spree_limit_order_quantity/master_variant_quantity_checker.rb
Instance Attribute Summary collapse
-
#product ⇒ Object
Returns the value of attribute product.
-
#total_quantity ⇒ Object
Returns the value of attribute total_quantity.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(product, total_quantity) ⇒ MasterVariantQuantityChecker
constructor
A new instance of MasterVariantQuantityChecker.
- #max_quantity_valid? ⇒ Boolean
- #min_quantity_valid? ⇒ Boolean
- #should_check_limits? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(product, total_quantity) ⇒ MasterVariantQuantityChecker
Returns a new instance of MasterVariantQuantityChecker.
5 6 7 8 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 5 def initialize(product, total_quantity) @product = product @total_quantity = total_quantity end |
Instance Attribute Details
#product ⇒ Object
Returns the value of attribute product.
3 4 5 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 3 def product @product end |
#total_quantity ⇒ Object
Returns the value of attribute total_quantity.
3 4 5 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 3 def total_quantity @total_quantity end |
Instance Method Details
#error_message ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 30 def return nil if valid? product_name = @product.name if !max_quantity_valid? Spree.t( "storefront.line_item.master_max_order_quantity_error", product_name: product_name, max_quantity: master_variant.max_order_quantity ) elsif !min_quantity_valid? Spree.t( "storefront.line_item.master_min_order_quantity_error", product_name: product_name, min_quantity: master_variant.min_order_quantity ) end end |
#max_quantity_valid? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 14 def max_quantity_valid? return true if master_variant.max_order_quantity.nil? @total_quantity <= master_variant.max_order_quantity end |
#min_quantity_valid? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 20 def min_quantity_valid? return true if master_variant.min_order_quantity.nil? @total_quantity >= master_variant.min_order_quantity end |
#should_check_limits? ⇒ Boolean
26 27 28 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 26 def should_check_limits? master_variant.min_order_quantity.present? || master_variant.max_order_quantity.present? end |
#valid? ⇒ Boolean
10 11 12 |
# File 'lib/spree_limit_order_quantity/master_variant_quantity_checker.rb', line 10 def valid? max_quantity_valid? && min_quantity_valid? end |