Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use our namespace for decorator constant #115

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_product_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeProductDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeProduct", as: :related_object, dependent: :nullify
end

private

# Overwritten Solidus' default behavior
#
# The Solidus implementation did not trigger `touch` on taxons, but
# updated the `updated_at` timestamp in an `update_all`.
#
# Since we want to invalidate ingredient spree taxons cache as well
# we need to use `touch` here and use the `after_touch` callback of
# Spree::Taxon
#
def touch_taxons
taxons.each(&:touch)
end

::Spree::Product.prepend self
end
end
end
14 changes: 14 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_taxon_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeTaxonDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeTaxon", as: :related_object, dependent: :nullify
end

::Spree::Taxon.prepend self
end
end
end
14 changes: 14 additions & 0 deletions app/decorators/models/alchemy/solidus/spree_variant_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module SpreeVariantDecorator
def self.prepended(base)
base.include Alchemy::Solidus::TouchAlchemyIngredients
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeVariant", as: :related_object, dependent: :nullify
end

::Spree::Variant.prepend self
end
end
end
27 changes: 0 additions & 27 deletions app/decorators/models/spree/spree_product_decorator.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/decorators/models/spree/spree_taxon_decorator.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/decorators/models/spree/spree_variant_decorator.rb

This file was deleted.

20 changes: 20 additions & 0 deletions app/models/alchemy/solidus/touch_alchemy_ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Alchemy
module Solidus
module TouchAlchemyIngredients
extend ActiveSupport::Concern

included do
after_update :touch_alchemy_ingredients
after_touch :touch_alchemy_ingredients
end

private

def touch_alchemy_ingredients
alchemy_ingredients.each(&:touch)
end
end
end
end
18 changes: 0 additions & 18 deletions app/models/alchemy_solidus/touch_alchemy_ingredients.rb

This file was deleted.