mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
Refresh products cache when taxons or classifications are changed or destroyed
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
Spree::Classification.class_eval do
|
||||
belongs_to :product, :class_name => "Spree::Product", touch: true
|
||||
after_save :refresh_products_cache
|
||||
before_destroy :dont_destroy_if_primary_taxon
|
||||
after_destroy :refresh_products_cache
|
||||
|
||||
|
||||
private
|
||||
|
||||
def refresh_products_cache
|
||||
product.refresh_products_cache
|
||||
end
|
||||
|
||||
def dont_destroy_if_primary_taxon
|
||||
if product.primary_taxon == taxon
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
Spree::Taxon.class_eval do
|
||||
has_many :classifications, :dependent => :destroy
|
||||
|
||||
|
||||
self.attachment_definitions[:icon][:path] = 'public/images/spree/taxons/:id/:style/:basename.:extension'
|
||||
self.attachment_definitions[:icon][:url] = '/images/spree/taxons/:id/:style/:basename.:extension'
|
||||
|
||||
after_save :refresh_products_cache
|
||||
|
||||
|
||||
# Indicate which filters should be used for this taxon
|
||||
def applicable_filters
|
||||
@@ -45,4 +50,11 @@ Spree::Taxon.class_eval do
|
||||
|
||||
taxons
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def refresh_products_cache
|
||||
products(:reload).each &:refresh_products_cache
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user