mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-24 01:13:21 +00:00
Perform variant override scoping on product/variant by external class. Centralise this so we can load everything in one go.
This commit is contained in:
@@ -4,9 +4,10 @@ module Spree
|
||||
return [] unless order.completed?
|
||||
|
||||
#increase inventory to meet initial requirements
|
||||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor)
|
||||
order.line_items.each do |line_item|
|
||||
# Scope variant to hub so that stock levels may be subtracted from VariantOverride.
|
||||
line_item.variant.scope_to_hub order.distributor
|
||||
scoper.scope(line_item.variant)
|
||||
|
||||
increase(order, line_item.variant, line_item.quantity)
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ Spree::OrderPopulator.class_eval do
|
||||
errors.add(:base, "That distributor or order cycle can't supply all the products in your cart. Please choose another.")
|
||||
end
|
||||
|
||||
if valid?
|
||||
if valid?
|
||||
@order.with_lock do
|
||||
@order.empty! if overwrite
|
||||
|
||||
@@ -33,7 +33,7 @@ Spree::OrderPopulator.class_eval do
|
||||
def attempt_cart_add(variant_id, quantity, max_quantity = nil)
|
||||
quantity = quantity.to_i
|
||||
variant = Spree::Variant.find(variant_id)
|
||||
variant.scope_to_hub @distributor
|
||||
OpenFoodNetwork::ScopeVariantToHub.new(@distributor).scope(variant)
|
||||
if quantity > 0
|
||||
if check_stock_levels(variant, quantity) &&
|
||||
check_order_cycle_provided_for(variant) &&
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
require 'open_food_network/scope_product_to_hub'
|
||||
|
||||
Spree::Product.class_eval do
|
||||
include OpenFoodNetwork::ProductScopableToHub
|
||||
|
||||
# We have an after_destroy callback on Spree::ProductOptionType. However, if we
|
||||
# don't specify dependent => destroy on this association, it is not called. See:
|
||||
# https://github.com/rails/rails/issues/7618
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
require 'open_food_network/scope_variant_to_hub'
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
require 'open_food_network/option_value_namer'
|
||||
|
||||
Spree::Variant.class_eval do
|
||||
include OpenFoodNetwork::VariantScopableToHub
|
||||
|
||||
has_many :exchange_variants, dependent: :destroy
|
||||
has_many :exchanges, through: :exchange_variants
|
||||
has_many :variant_overrides
|
||||
|
||||
Reference in New Issue
Block a user