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

Move patches to app/patches #76

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
lint-code:
executor:
name: solidusio_extensions/sqlite
ruby_version: "3.0"
ruby_version: "3.1"
steps:
- solidusio_extensions/lint-code

Expand All @@ -43,15 +43,15 @@ workflows:
- run-specs:
name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
matrix:
parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
parameters: { solidus: ["main"], ruby: ["3.3"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
parameters: { solidus: ["current"], ruby: ["3.2"], db: ["mysql"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] }
parameters: { solidus: ["older"], ruby: ["3.1"], db: ["sqlite"] }
- lint-code

"Weekly run specs against main":
Expand All @@ -66,8 +66,8 @@ workflows:
- run-specs:
name: *name
matrix:
parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
parameters: { solidus: ["main"], ruby: ["3.3"], db: ["postgres"] }
- run-specs:
name: *name
matrix:
parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
parameters: { solidus: ["current"], ruby: ["3.2"], db: ["mysql"] }

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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
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 app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb
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 app/patches/models/solidus_volume_pricing/spree_variant_patch.rb
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
1 change: 1 addition & 0 deletions lib/solidus_volume_pricing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'deface'
require 'solidus_core'
require 'solidus_support'
require 'flickwerk'
require 'solidus_volume_pricing/engine'
require 'solidus_volume_pricing/version'
require 'solidus_volume_pricing/range_from_string'
Expand Down
1 change: 1 addition & 0 deletions lib/solidus_volume_pricing/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module SolidusVolumePricing
class Engine < Rails::Engine
include SolidusSupport::EngineExtensions
include Flickwerk

isolate_namespace ::Spree

Expand Down
1 change: 1 addition & 0 deletions solidus_volume_pricing.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'solidus_backend', ['>= 2.4.0', '< 5']
spec.add_dependency 'coffee-rails'
spec.add_dependency 'deface'
spec.add_dependency 'flickwerk', '~> 0.3.1'
spec.add_dependency 'sassc-rails'
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
spec.add_dependency 'solidus_support', '~> 0.8'
Expand Down