-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should make the patches in line with the Flickwerk conventions.
- Loading branch information
Showing
8 changed files
with
104 additions
and
114 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
...ecorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusVolumePricing | ||
module SpreeAdminVariantsControllerPatch | ||
def edit | ||
@variant.volume_prices.build if @variant.volume_prices.empty? | ||
super | ||
end | ||
|
||
def volume_prices | ||
@product = @variant.product | ||
@variant.volume_prices.build if @variant.volume_prices.empty? | ||
end | ||
|
||
private | ||
|
||
# this loads the variant for the master variant volume price editing | ||
def load_resource_instance | ||
parent | ||
|
||
if new_actions.include?(params[:action].to_sym) | ||
build_resource | ||
elsif params[:id] | ||
::Spree::Variant.find(params[:id]) | ||
end | ||
end | ||
|
||
def location_after_save | ||
if @product.master.id == @variant.id && params[:variant].key?(:volume_prices_attributes) | ||
return volume_prices_admin_product_variant_url(@product, @variant) | ||
end | ||
|
||
super | ||
end | ||
|
||
::Spree::Admin::VariantsController.prepend self | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusVolumePricing | ||
module SpreeBaseHelperPatch | ||
def self.prepended(base) | ||
base.module_eval do | ||
def display_volume_price(variant, quantity = 1, user = nil) | ||
price_display(variant, quantity: quantity, user: user).price_string | ||
end | ||
|
||
def display_volume_price_earning_percent(variant, quantity = 1, user = nil) | ||
price_display(variant, quantity: quantity, user: user).earning_percent_string | ||
end | ||
|
||
def display_volume_price_earning_amount(variant, quantity = 1, user = nil) | ||
price_display(variant, quantity: quantity, user: user).earning_amount_string | ||
end | ||
|
||
private | ||
|
||
def price_display(variant, quantity:, user:) | ||
SolidusVolumePricing::PriceDisplay.new(variant, quantity: quantity, user: user) | ||
end | ||
end | ||
end | ||
|
||
::Spree::BaseHelper.prepend self | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusVolumePricing | ||
module SpreeLineItemPatch | ||
def set_pricing_attributes | ||
if quantity_changed? | ||
options = SolidusVolumePricing::PricingOptions.from_line_item(self) | ||
self.money_price = SolidusVolumePricing::Pricer.new(variant).price_for(options) | ||
end | ||
|
||
super | ||
end | ||
|
||
::Spree::LineItem.prepend self | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
app/patches/models/solidus_volume_pricing/spree_variant_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusVolumePricing | ||
module SpreeVariantPatch | ||
def self.prepended(base) | ||
base.class_eval do | ||
has_and_belongs_to_many :volume_price_models | ||
has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy | ||
has_many :model_volume_prices, -> { | ||
order(position: :asc) | ||
}, class_name: '::Spree::VolumePrice', through: :volume_price_models, source: :volume_prices | ||
accepts_nested_attributes_for :volume_prices, allow_destroy: true, | ||
reject_if: proc { |volume_price| | ||
volume_price[:amount].blank? && volume_price[:range].blank? | ||
} | ||
end | ||
end | ||
|
||
::Spree::Variant.prepend self | ||
end | ||
end |