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 @@ -
+
<% param_prefix = "payment_source[#{payment_method.id}]" %> -

- <%= 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'%> -

+ +
+
+ <%= text_field_tag "#{param_prefix}[po_number]", '', id: 'po_number', class: 'spree-flat-input', placeholder: Spree.t(:po_number), required: true %> +
+ +
+ <%= text_field_tag "#{param_prefix}[organization_name]", '', id: 'organization_name', class: 'spree-flat-input', placeholder: Spree.t(:organization_name), required: true %> +
+
diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 92edec9..d54e193 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -21,6 +21,8 @@ class Application < Rails::Application Rails.configuration.cache_classes ? require(c) : load(c) end end + + config.load_defaults 6.0 end end diff --git a/spec/factories/purchase_orders.rb b/spec/factories/purchase_orders.rb index 2d8f8a8..46b9d60 100644 --- a/spec/factories/purchase_orders.rb +++ b/spec/factories/purchase_orders.rb @@ -37,6 +37,7 @@ name { 'Spree Test Store' } url { 'www.example.com' } mail_from_address { 'spree@example.org' } + default_currency { 'USD' } end # factory :user, class: Spree.user_class do diff --git a/spree_purchase_order.gemspec b/spree_purchase_order.gemspec index 769b3ef..1ae6637 100644 --- a/spree_purchase_order.gemspec +++ b/spree_purchase_order.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.requirements << 'none' - s.add_dependency 'spree_core', '~> 3.7.0' + s.add_dependency 'spree_core', '~> 4.0' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec-rails'