Merge branch 'delete-protection' into funkensturm/master
* delete-protection: Added config to optionally disable deleting digitals on variant deletion Revert "Remove delete digitals on soft delete of variant" Adding failing variant spec Fixed broken Digital#destroy spec Remove delete digitals on soft delete of variant
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user