Added config to optionally disable deleting digitals on variant deletion

This commit is contained in:
Michael Bianco
2012-10-29 11:43:47 -04:00
parent c5b1b87617
commit d1536aa741
6 changed files with 47 additions and 16 deletions

View File

@@ -10,13 +10,12 @@ Spree::Order.class_eval do
false
end
# UPGRADE_CHECK
# TODO this works as of spree 1.1.1; make sure to check the original function on upgrade
# UPGRADE_CHECK this works as of spree 1.1.1; make sure to check the original function on upgrade
def available_shipping_methods(display_on = nil)
return [] unless ship_address
all_methods = Spree::ShippingMethod.all_available(self, display_on)
puts "ALL METHODS #{all_methods.count} #{display_on}"
if self.digital?
all_methods.detect { |m| m.calculator.class == Spree::Calculator::DigitalDelivery }.try { |d| [d] } || all_methods
else

View File

@@ -1,6 +1,5 @@
Spree::Variant.class_eval do
has_many :digitals, :dependent => :destroy
has_many :digitals
after_save :destroy_digital, :if => :deleted?
# Is this variant to be downloaded by the customer?
@@ -10,11 +9,11 @@ Spree::Variant.class_eval do
private
# Spree never deleted Digitals, that's why ":dependent => :destroy" won't work on Digital.
# We need to delete the Digital manually here as soon as the Variant is nullified.
# Otherwise you'll have orphan Digitals (and their attached files!) associated with unused Variants.
# :dependent => :destroy needs to be handled manually
# spree does not delete variants, just marks them as deleted?
# optionally keep digitals around for customers who require continued access to their purchases
def destroy_digital
digitals.map &:destroy
digitals.map &:destroy unless Spree::DigitalConfiguration[:keep_digitals]
end
end