Permalink
Browse files

Modified Sku dropdown on storefront product pages to push out of stoc…

…k Sku's to the bottom of the list. Fixed first_available_sku method to disregard out of stock Sku's.
  • Loading branch information...
1 parent 01b7aeb commit ae12285be662648f9e7cac6b183527281a416cc5 @Jellyfishboy committed Jan 7, 2017
@@ -17,7 +17,7 @@ def set_product
end
def set_skus
- @skus = @product.active_skus
+ @skus = @product.active_skus.sort_by{|s| s.in_stock? ? 0 : 1}
end
def set_variant_types
View
@@ -58,14 +58,14 @@ class Product < ActiveRecord::Base
validates :name, :sku, :part_number, presence: true
validates :meta_description, :description,
- :weighting, :category_id, :page_title, presence: true, :if => :published?
+ :weighting, :category_id, :page_title, presence: true, if: :published?
validates :part_number, :sku, :name, uniqueness: { scope: :active }
validates :page_title, length: { maximum: 70, message: :too_long }
- validates :meta_description, length: { maximum: 150, message: :too_long }, :if => :published?
- validates :name, length: { minimum: 10, message: :too_short }, :if => :published?
- validates :description, length: { minimum: 20, message: :too_short }, :if => :published?
- validates :short_description, length: { maximum: 300, message: :too_long }, :if => :published?
- validates :part_number, numericality: { only_integer: true }, :if => :published?
+ validates :meta_description, length: { maximum: 150, message: :too_long }, if: :published?
+ validates :name, length: { minimum: 10, message: :too_short }, if: :published?
+ validates :description, length: { minimum: 20, message: :too_short }, if: :published?
+ validates :short_description, length: { maximum: 300, message: :too_long }, if: :published?
+ validates :part_number, numericality: { only_integer: true }, if: :published?
accepts_nested_attributes_for :skus
accepts_nested_attributes_for :tags
@@ -111,6 +111,6 @@ def in_stock?
#
# @return [Object] sku record
def first_available_sku
- skus.active.order(price: :asc).first
+ skus.active.in_stock.order(price: :asc).first
end
end
View
@@ -55,6 +55,7 @@ class Sku < ActiveRecord::Base
accepts_nested_attributes_for :variants, :stock_adjustments
scope :complete, -> { where('stock IS NOT NULL') }
+ scope :in_stock, -> { where('stock > ?', 0) }
include ActiveScope
View
@@ -1,7 +1,7 @@
development:
adapter: postgresql
encoding: unicode
- database: trado_live
+ database: trado_dev
pool: 5
username: tomdallimore
password:
@@ -47,7 +47,7 @@
# Expands the lines which load the assets
config.assets.debug = true
- config.serve_static_files = false
+ config.serve_static_files = true
config.action_mailer.asset_host = Rails.application.secrets.mailer_asset_url
config.action_controller.asset_host = Rails.application.secrets.asset_url

0 comments on commit ae12285

Please sign in to comment.