Permalink
Browse files

adding support for wholesalers to avoid paying each time (net 10 net …

…20 etc)
  • Loading branch information...
citrus committed Apr 20, 2011
1 parent e55e595 commit 7c8b2c3da4ca5dd8e445ddb2a3d2a8a8ce36d21c
View
@@ -95,6 +95,7 @@ GEM
activerecord (>= 3.0.0)
rd_unobtrusive_date_picker (0.1.0)
shoulda (2.11.3)
+ spork (0.8.4)
spree (0.40.2)
spree_api (= 0.40.2)
spree_auth (= 0.40.2)
@@ -147,6 +148,7 @@ PLATFORMS
DEPENDENCIES
shoulda (>= 2.11.3)
+ spork (>= 0.8.4)
spree (>= 0.40.2)
spree_wholesale!
sqlite3-ruby (>= 1.3.2)
@@ -11,5 +11,65 @@ def get_addresses
@order.bill_address = current_user.wholesaler.bill_address
@order.ship_address = current_user.wholesaler.ship_address
end
+
+
+
+ # Updates the order and advances to the next state (when possible.)
+ def update
+
+
+
+ #v = object_params[:source_attributes][:verification_value].to_s rescue ""
+
+
+ puts "---------"
+ puts @order.state
+
+ if @order.is_wholesale? && @order.state == "payment" && @order.wholesaler.terms != "Credit Card" && params[:order_pay_at] == "later"
+
+ puts "OH YA WHOLESALE BABY"
+ puts @order.inspect
+
+ puts @order.next
+ puts "0000000000000000"
+ puts @order.errors.inspect
+
+ #cear
+ puts @order.state
+
+ return redirect_to(checkout_state_path(@order.state))
+ end
+
+
+
+ if @order.update_attributes(object_params)
+
+ puts "---------"
+ puts @order.state
+
+ if @order.next
+ state_callback(:after)
+ else
+ flash[:error] = I18n.t(:payment_processing_failed)
+ redirect_to checkout_state_path(@order.state) and return
+ end
+
+ puts @order.state
+
+
+ if @order.state == "complete" || @order.completed?
+ flash[:notice] = I18n.t(:order_processed_successfully)
+ flash[:commerce_tracking] = "nothing special"
+ redirect_to completion_route
+ else
+ redirect_to checkout_state_path(@order.state)
+ end
+
+ else
+ render :edit
+ end
+ end
+
+
end
@@ -1,7 +1,15 @@
Order.class_eval do
+ def wholesale
+ read_attribute(:wholesale) && !wholesaler.nil?
+ end
+
+ def wholesaler
+ user && user.wholesaler
+ end
+
def is_wholesale?
- wholesale == true
+ wholesale
end
def set_line_item_prices(use_price=:price)
@@ -58,7 +58,7 @@
<%= f.field_container :terms do %>
<%= f.label :terms, t(".terms") %><br />
- <%= f.text_field :terms %>
+ <%= f.select :terms, Wholesaler.term_options %>
<%= error_message_on :wholesaler, :terms %>
<% end %>
@@ -0,0 +1,44 @@
+<% order = (@order || order) %>
+<% if order.is_wholesale? %>
+
+ <div class="wholesaler-payment" style="padding: 10px; border: 1px solid #ccc; background-color: rgba(255,255,255,0.1);">
+ <h3>Hello Wholesaler!</h3>
+ <p>Your wholesale terms are <b><%= @order.user.wholesaler.terms %></b> which means
+ <% if @order.user.wholesaler.terms == "Credit Card" %>
+ that you'll have to pay for this order now.</p>
+ <% else %>
+ that you can pay for this order now or
+ <% if @order.user.wholesaler.terms == "COD" %>
+ when it arrives.
+ <% else %>
+ at the end of your <b><%= @order.user.wholesaler.terms.sub("Net ", "") %> day</b> cycle.
+ <% end %>
+ </p>
+ <p>
+ <%= radio_button_tag "order_pay_at", "now" %>
+ <%= label_tag "order_pay_at_now", "Pay Now" %>
+ &nbsp;
+ <%= radio_button_tag "order_pay_at", "later" %>
+ <%= label_tag "order_pay_at_later", "Pay Later" %>
+ </p>
+ <% content_for :head do %>
+ <script type="text/javascript">
+ //<![CDATA[
+ var show_form = <%= params[:order_pay_at] == "now" %>;
+ $(document).ready(function() {
+ $('input[name=order_pay_at]').change(function(evt) {
+ evt.preventDefault();
+ $('#payment-methods, #payment > p').toggle(this.value == "now");
+ });
+ if (show_form) $('#order_pay_at_now').attr('checked', true).change();
+ else $('#order_pay_at_later').attr('checked', true).change();
+ });
+ //]]>
+ </script>
+ <% end %>
+ <% end %>
+ </div>
+
+ <br/>
+
+<% end %>
@@ -4,5 +4,4 @@
<%= render 'fields', :form => form %>
-
<% end %>
View
@@ -1,4 +1,5 @@
if ENV["RAILS_ENV"] != "production"
+ require 'spree'
require 'spree_core'
require 'spree_auth'
end
@@ -5,10 +5,12 @@ class SpreeWholesaleHooks < Spree::ThemeSupport::HookListener
replace :cart_item_price, 'hooks/cart_item_price'
replace :cart_item_total, 'hooks/cart_item_total'
- insert_before :inside_cart_form, 'hooks/wholesale_customer_id'
-
+ insert_before :inside_cart_form, 'hooks/wholesale_customer_id'
+ insert_before :checkout_payment_step, 'hooks/wholesale_payment_options'
+ insert_before :account_my_orders, 'hooks/wholesale_customer_id'
insert_after :admin_order_show_buttons, 'hooks/wholesale_customer_id'
+
insert_after :admin_orders_index_headers, 'admin/hooks/admin_orders_index_headers'
insert_after :admin_orders_index_rows, 'admin/hooks/admin_orders_index_rows'
insert_after :admin_orders_index_search, 'admin/hooks/admin_orders_index_search'
View
@@ -17,13 +17,12 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
- s.has_rdoc = false
-
s.add_dependency('spree_core', '>= 0.30.1')
s.add_dependency('spree_auth', '>= 0.30.1')
- s.add_development_dependency('spree', '>= 0.40.2')
- s.add_development_dependency('shoulda', '>= 2.11.3')
+ s.add_development_dependency('spree', '>= 0.40.2')
+ s.add_development_dependency('shoulda', '>= 2.11.3')
s.add_development_dependency('sqlite3-ruby', '>= 1.3.2')
+ s.add_development_dependency('spork', '>= 0.8.4')
end
View
@@ -1,3 +1,5 @@
+
+
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"
@@ -8,8 +10,27 @@
raise LoadError, "Please create the dummy app before running tests."
end
-require "rails/test_help"
-require "shoulda"
+require 'rails/test_help'
+require 'shoulda'
+require 'spork'
+
+
+
+
+Spork.prefork do
+ # Loading more in this block will cause your tests to run faster. However,
+ # if you change any configuration or code from libraries loaded here, you'll
+ # need to restart spork for it take effect.
+
+end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+
+end
+
+
+
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
@@ -45,4 +66,4 @@ class ActiveSupport::TestCase
class ActionController::IntegrationTest
self.fixture_path = File.expand_path('../fixtures', __FILE__)
-end
+end

0 comments on commit 7c8b2c3

Please sign in to comment.