Skip to content

Commit

Permalink
Merge pull request #35 from shiftdsm/upgrade-spree
Browse files Browse the repository at this point in the history
Upgrade to Spree 4.0
  • Loading branch information
deepakmahakale authored Dec 24, 2021
2 parents 6aea30f + b4b8b1f commit c076402
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ spec/dummy/db/*.sqlite3
spec/dummy/db/schema.rb
spec/dummy/db/migrate/*.rb
spec/dummy/public/*
.idea
.generators
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
source 'https://rubygems.org'

gemspec

group :development, :test do
gem 'spree_auth_devise'
end
21 changes: 17 additions & 4 deletions app/models/spree/payment_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/models/spree/payment_method/purchase_order.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Spree
class PaymentMethod::PurchaseOrder < PaymentMethod
def payment_source_class
Expand Down
4 changes: 3 additions & 1 deletion app/models/spree/purchase_order.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
24 changes: 11 additions & 13 deletions app/views/spree/checkout/payment/_purchaseorder.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<div class='well clearfix'>
<div class="payment-gateway">
<% param_prefix = "payment_source[#{payment_method.id}]" %>
<p class='field'>
<%= label_tag :po_number do %>
<%= Spree.t(:po_number) %><abbr class='required' title='required'>*</abbr>
<% end %>
<%= text_field_tag "#{param_prefix}[po_number]", '', id: :po_number, class: 'form-control required', size: 10, maxlength: 10, autocomplete: "off" %>
</p>
<p class='field'>
<%= label_tag :organization_name do %>
<%= Spree.t(:organization_name) %><abbr class='required' title='required'>*</abbr>
<% end %>
<%= text_field_tag "#{param_prefix}[organization_name]", '', id: :organization_name, class: 'form-control required'%>
</p>

<div class="payment-gateway-fields">
<div class="mb-4 payment-gateway-field checkout-content-inner-field">
<%= text_field_tag "#{param_prefix}[po_number]", '', id: 'po_number', class: 'spree-flat-input', placeholder: Spree.t(:po_number), required: true %>
</div>

<div class="payment-gateway-field checkout-content-inner-field">
<%= text_field_tag "#{param_prefix}[organization_name]", '', id: 'organization_name', class: 'spree-flat-input', placeholder: Spree.t(:organization_name), required: true %>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions spec/factories/purchase_orders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
name { 'Spree Test Store' }
url { 'www.example.com' }
mail_from_address { '[email protected]' }
default_currency { 'USD' }
end

# factory :user, class: Spree.user_class do
Expand Down
2 changes: 1 addition & 1 deletion spree_purchase_order.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c076402

Please sign in to comment.