Add module to set unused ship, bill address fields

This commit is contained in:
Nihal
2021-09-22 14:15:13 +05:30
committed by Nihal M. Kelanthodika
parent f72f182363
commit 7eb0c6c33c
4 changed files with 20 additions and 19 deletions

View File

@@ -0,0 +1,14 @@
require 'active_support/concern'
module SetUnusedAddressFields
extend ActiveSupport::Concern
included do
self.before_validation :set_unused_address_fields
end
def set_unused_address_fields
ship_address.company = 'Company' if ship_address.present?
bill_address.company = 'Company' if bill_address.present?
end
end

View File

@@ -10,6 +10,7 @@ module Spree
include OrderShipment
include Checkout
include Balance
include SetUnusedAddressFields
searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id,
:order_cycle_id, :email, :total
@@ -86,7 +87,7 @@ module Spree
before_validation :clone_billing_address, if: :use_billing?
before_validation :associate_customer, unless: :customer_id?
before_validation :ensure_customer, unless: :customer_is_valid?
before_validation :set_unused_address_fields
before_create :link_by_email
after_create :create_tax_charge!
@@ -612,11 +613,6 @@ module Spree
private
def set_unused_address_fields
ship_address.company = 'Company' if ship_address.present?
bill_address.company = 'Company' if bill_address.present?
end
def fee_handler
@fee_handler ||= OrderFeesHandler.new(self)
end

View File

@@ -2,6 +2,8 @@
module Spree
class User < ApplicationRecord
include SetUnusedAddressFields
searchable_attributes :email
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
@@ -20,7 +22,6 @@ module Spree
before_validation :set_login
before_destroy :check_completed_orders
before_validation :set_unused_address_fields
roles_table_name = Role.table_name
@@ -151,11 +152,6 @@ module Spree
private
def set_unused_address_fields
ship_address.company = 'Company' if ship_address.present?
bill_address.company = 'Company' if bill_address.present?
end
def check_completed_orders
raise DestroyWithOrdersError if orders.complete.present?
end

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
class Subscription < ApplicationRecord
include SetUnusedAddressFields
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check",
"Spree::Gateway::StripeConnect",
"Spree::Gateway::StripeSCA"].freeze
@@ -26,8 +28,6 @@ class Subscription < ApplicationRecord
accepts_nested_attributes_for :subscription_line_items, allow_destroy: true
accepts_nested_attributes_for :bill_address, :ship_address
before_validation :set_unused_address_fields
scope :not_ended, -> {
where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now)
@@ -77,11 +77,6 @@ class Subscription < ApplicationRecord
private
def set_unused_address_fields
ship_address.company = 'Company' if ship_address.present?
bill_address.company = 'Company' if bill_address.present?
end
def pending?
return true unless begins_at