diff --git a/.gitignore b/.gitignore index 75ebb57..7f34a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ spec/dummy/db/*.sqlite3 spec/dummy/db/schema.rb spec/dummy/db/migrate/*.rb spec/dummy/public/* +.idea +.generators diff --git a/Gemfile b/Gemfile index fa75df1..1714397 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,7 @@ source 'https://rubygems.org' gemspec + +group :development, :test do + gem 'spree_auth_devise' +end diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 857c413..e45c0b2 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -1,7 +1,20 @@ -Spree::Payment.class_eval do - scope :from_purchase_order, -> { where(source_type: 'Spree::PurchaseOrder') } +# frozen_string_literal: true - def po? - source_type == 'Spree::PurchaseOrder' +module Spree + module PaymentDecorator + def self.prepended(base) + base.scope( + :from_purchase_order, + -> { where(source_type: 'Spree::PurchaseOrder') } + ) + end + + def po? + source_type == 'Spree::PurchaseOrder' + end end end + +if ::Spree::Payment.included_modules.exclude?(::Spree::PaymentDecorator) + ::Spree::Payment.prepend ::Spree::PaymentDecorator +end diff --git a/app/models/spree/payment_method/purchase_order.rb b/app/models/spree/payment_method/purchase_order.rb index 4f1956d..ed7aa90 100644 --- a/app/models/spree/payment_method/purchase_order.rb +++ b/app/models/spree/payment_method/purchase_order.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class PaymentMethod::PurchaseOrder < PaymentMethod def payment_source_class diff --git a/app/models/spree/purchase_order.rb b/app/models/spree/purchase_order.rb index 7c3980f..77df302 100644 --- a/app/models/spree/purchase_order.rb +++ b/app/models/spree/purchase_order.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module Spree class PurchaseOrder < Spree::Base belongs_to :payment_method has_many :payments, as: :source - validates_presence_of :po_number, :organization_name + validates :po_number, :organization_name, presence: true def actions %w(complete void) diff --git a/app/views/spree/checkout/payment/_purchaseorder.html.erb b/app/views/spree/checkout/payment/_purchaseorder.html.erb index 9a17932..b990ded 100644 --- a/app/views/spree/checkout/payment/_purchaseorder.html.erb +++ b/app/views/spree/checkout/payment/_purchaseorder.html.erb @@ -1,15 +1,13 @@ -
- <%= label_tag :po_number do %> - <%= Spree.t(:po_number) %>* - <% end %> - <%= text_field_tag "#{param_prefix}[po_number]", '', id: :po_number, class: 'form-control required', size: 10, maxlength: 10, autocomplete: "off" %> -
-- <%= label_tag :organization_name do %> - <%= Spree.t(:organization_name) %>* - <% end %> - <%= text_field_tag "#{param_prefix}[organization_name]", '', id: :organization_name, class: 'form-control required'%> -
+ +