Created
October 4, 2013 17:42
-
-
Save ricardokrieg/6829765 to your computer and use it in GitHub Desktop.
Monkey Patch to make Spree skips inventory check for only a kind of products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spree::Stock::Packer.class_eval do | |
def default_package | |
package = Spree::Stock::Package.new(stock_location, order) | |
order.line_items.each do |line_item| | |
# on_demand? will say if this kind of product has inventory | |
if Spree::Config.track_inventory_levels and not line_item.variant.product.on_demand? | |
next unless stock_location.stock_item(line_item.variant) | |
on_hand, backordered = stock_location.fill_status(line_item.variant, line_item.quantity) | |
package.add line_item.variant, on_hand, :on_hand if on_hand > 0 | |
package.add line_item.variant, backordered, :backordered if backordered > 0 | |
else | |
package.add line_item.variant, line_item.quantity, :on_hand | |
end | |
end | |
package | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spree::Stock::Quantifier.class_eval do | |
def total_on_hand | |
# this is needed because @variant stores only the variant id | |
variant = Spree::Variant.find(@variant) | |
# on_demand? will say if this kind of product has inventory | |
if Spree::Config.track_inventory_levels and not variant.product.on_demand? | |
stock_items.to_a.sum(&:count_on_hand) | |
else | |
Float::INFINITY | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment