Skip to content

Commit e788a90

Browse files
committed
Use Alchemy::RelatableResource
Alchemy has a relatable resource module that we include in Spree:Product, Spree::Taxon and Spree::Variant. Since RelatableResource now also has cache invalidation built in, we can use that.
1 parent e85988c commit e788a90

3 files changed

Lines changed: 5 additions & 28 deletions

File tree

app/patches/models/alchemy/solidus/spree_product_patch.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ module Alchemy
44
module Solidus
55
module SpreeProductPatch
66
def self.prepended(base)
7-
# Solidus runs touch callbacks on product after_save
8-
base.after_touch :touch_alchemy_ingredients
97
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeProduct", as: :related_object, dependent: :nullify
108
end
119

@@ -24,13 +22,9 @@ def touch_taxons
2422
taxons.each(&:touch)
2523
end
2624

27-
# Touch all elements that have this product assigned to one of its ingredients.
28-
# This cascades to all parent elements and pages as well.
29-
def touch_alchemy_ingredients
30-
InvalidateElementsCacheJob.perform_later("SpreeProduct", id)
31-
end
32-
3325
::Spree::Product.prepend self
3426
end
3527
end
28+
29+
::Spree::Product.include RelatableResource
3630
end

app/patches/models/alchemy/solidus/spree_taxon_patch.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,11 @@ module Alchemy
44
module Solidus
55
module SpreeTaxonPatch
66
def self.prepended(base)
7-
base.after_update :touch_alchemy_ingredients
8-
base.after_touch :touch_alchemy_ingredients
97
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeTaxon", as: :related_object, dependent: :nullify
108
end
119

1210
::Spree::Taxon.prepend self
13-
14-
private
15-
16-
# Touch all elements that have this taxon assigned to one of its ingredients.
17-
# This cascades to all parent elements and pages as well.
18-
def touch_alchemy_ingredients
19-
InvalidateElementsCacheJob.perform_later("SpreeTaxon", id)
20-
end
2111
end
2212
end
13+
::Spree::Taxon.include RelatableResource
2314
end

app/patches/models/alchemy/solidus/spree_variant_patch.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ module Alchemy
44
module Solidus
55
module SpreeVariantPatch
66
def self.prepended(base)
7-
base.after_update :touch_alchemy_ingredients
8-
base.after_touch :touch_alchemy_ingredients
97
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeVariant", as: :related_object, dependent: :nullify
108
end
119

1210
::Spree::Variant.prepend self
13-
14-
private
15-
16-
# Touch all elements that have this variant assigned to one of its ingredients.
17-
# This cascades to all parent elements and pages as well.
18-
def touch_alchemy_ingredients
19-
InvalidateElementsCacheJob.perform_later("SpreeVariant", id)
20-
end
2111
end
2212
end
13+
14+
::Spree::Variant.include RelatableResource
2315
end

0 commit comments

Comments
 (0)