Skip to content
This repository
  • 7 commits
  • 14 files changed
  • 0 comments
  • 1 contributor
6  app/controllers/shopping/orders_controller.rb
@@ -63,17 +63,17 @@ def update
63 63
           redirect_to myaccount_order_path(@order)
64 64
         else
65 65
           form_info
66  
-          flash[:error] =  [I18n.t('could_not_process'), I18n.t('the_order')].join(' ')
  66
+          flash[:alert] =  [I18n.t('could_not_process'), I18n.t('the_order')].join(' ')
67 67
           render :action => "index"
68 68
         end
69 69
       else
70 70
         form_info
71  
-        flash[:error] = [I18n.t('could_not_process'), I18n.t('the_credit_card')].join(' ')
  71
+        flash[:alert] = [I18n.t('could_not_process'), I18n.t('the_credit_card')].join(' ')
72 72
         render :action => 'index'
73 73
       end
74 74
     else
75 75
       form_info
76  
-      flash[:error] = [I18n.t('credit_card'), I18n.t('is_not_valid')].join(' ')
  76
+      flash[:alert] = [I18n.t('credit_card'), I18n.t('is_not_valid')].join(' ')
77 77
       render :action => 'index'
78 78
     end
79 79
   end
7  app/models/order.rb
@@ -56,6 +56,7 @@ class Order < ActiveRecord::Base
56 56
   CHARACTERS_SEED = 21
57 57
 
58 58
   state_machine :initial => 'in_progress' do
  59
+    after_transition :to => 'paid', :do => [:mark_items_paid]
59 60
 
60 61
     event :complete do
61 62
       transition :to => 'complete', :from => 'in_progress'
@@ -78,6 +79,10 @@ class Order < ActiveRecord::Base
78 79
   #    :order_items => {}# the key is variant_id , a hash of {variant, shipping_rate, quantity, tax_rate, total, shipping_category_id}
79 80
   #  }
80 81
 
  82
+  def mark_items_paid
  83
+    order_items.map(&:pay!)
  84
+  end
  85
+
81 86
   # user name on the order
82 87
   #
83 88
   # @param [none]
@@ -165,6 +170,8 @@ def self.new_admin_cart(admin_cart, args = {})
165 170
   # @return [Payment] payment object
166 171
   def capture_invoice(invoice)
167 172
     payment = invoice.capture_payment({})
  173
+    self.pay! if payment.success
  174
+    payment
168 175
   end
169 176
 
170 177
 
12  app/models/order_item.rb
@@ -37,11 +37,17 @@ def set_beginning_values
37 37
     @beginning_total            = self.total            rescue @beginning_total = nil # this stores the initial value of the total
38 38
   end
39 39
 
40  
- state_machine :initial => 'unpaid' do
  40
+  state_machine :initial => 'unpaid' do
41 41
 
  42
+    event :pay do
  43
+      transition :to => 'paid', :from => ['unpaid']
  44
+    end
42 45
 
43  
-   #after_transition :to => 'complete', :do => [:update_inventory]
44  
- end
  46
+    event :return do
  47
+      transition :to => 'returned', :from => ['paid']
  48
+    end
  49
+    #after_transition :to => 'complete', :do => [:update_inventory]
  50
+  end
45 51
 
46 52
  # if the order item has been shipped it will return true
47 53
  #
41  app/models/phone.rb
@@ -13,33 +13,36 @@
13 13
 #
14 14
 
15 15
 class Phone < ActiveRecord::Base
16  
-
  16
+  include ActionView::Helpers::NumberHelper
17 17
   belongs_to :phone_type
18 18
   #belongs_to :phone_priority
19 19
   belongs_to :phoneable, :polymorphic => true
20 20
 
21  
-  validates :number,  :presence => true,
  21
+  validates :phone_type_id,  :presence => true
  22
+  validates :number,  :presence => true, :numericality => true,
22 23
                       :format   => { :with => CustomValidators::Numbers.phone_number_validator },
23 24
                       :length   => { :maximum => 255 }
24 25
 
  26
+  before_validation :sanitize_data
  27
+  after_save        :default_phone_check
25 28
 
26  
-  # Use this method to create a phone
27  
-  # * This method will create a new phone object and if the phone is a default phone it
28  
-  # * will make all other phones that belong to the user non-default
29  
-  #
30  
-  # @param [object] object associated to the phone (user or possibly a company in the future)
31  
-  # @param [Hash] hash of attributes for the new phone
32  
-  # @ return [Boolean] true or nil
33  
-  def save_default_phone(object, params)
34  
-    Phone.transaction do
35  
-      if params[:default] && params[:default] != '0'
36  
-        Address.update_all(["phones.primary = ?", false],
37  
-                            ["phones.phoneable_id = ? AND phones.phoneable_type = ? ", object.id, object.class.to_s]) if object
38  
-        self.default = true
39  
-      end
40  
-      self.phoneable = object
41  
-      self.save
  29
+  def display_number=(val)
  30
+    self.number = val
  31
+  end
  32
+  def display_number
  33
+    number_to_phone( self.number )
  34
+  end
  35
+  private
42 36
 
  37
+    def default_phone_check
  38
+        Phone.update_all(["phones.primary = ?", false],
  39
+                          ["phones.phoneable_id = ? AND phones.phoneable_type = ? AND id <> ?",
  40
+                            phoneable_id, phoneable_type, id]) if self.primary
43 41
     end
44  
-  end
  42
+
  43
+    def sanitize_data
  44
+      #  remove non-digits
  45
+      self.number.gsub!(/\W+/, '') if number
  46
+    end
  47
+
45 48
 end
8  app/models/return_authorization.rb
@@ -49,7 +49,7 @@ class ReturnAuthorization < ActiveRecord::Base
49 49
   state_machine :initial => 'authorized' do
50 50
     #after_transition :to => 'received', :do => :process_receive
51 51
     #after_transition :to => 'cancelled', :do => :process_canceled
52  
-    before_transition :to => 'complete', :do => :process_ledger_transactions
  52
+    before_transition :to => 'complete', :do => [:process_ledger_transactions, :mark_items_returned]
53 53
 
54 54
     event :receive do
55 55
       transition :to => 'received', :from => 'authorized'
@@ -58,7 +58,7 @@ class ReturnAuthorization < ActiveRecord::Base
58 58
       transition :to => 'cancelled', :from => 'authorized'
59 59
     end
60 60
     event :complete do # do this after a payment was returned to the customer
61  
-      transition :to => 'complete', :from => 'authorized'
  61
+      transition :to => 'complete', :from => ['authorized', 'received']
62 62
     end
63 63
   end
64 64
 
@@ -73,6 +73,10 @@ def process_ledger_transactions
73 73
     Invoice.process_rma(amount - restocking_fee, order )
74 74
   end
75 75
 
  76
+  def mark_items_returned
  77
+    return_items.map(&:mark_returned!)
  78
+  end
  79
+
76 80
   # number of the order that is returning the item
77 81
   #
78 82
   # @param [none]
5  app/models/return_item.rb
@@ -28,4 +28,9 @@ class ReturnItem < ActiveRecord::Base
28 28
   validates :return_reason_id,        :presence => true
29 29
   #validates :return_authorization_id, :presence => true
30 30
 
  31
+  def mark_returned!
  32
+    self.returned = true
  33
+    self.order_item.return!
  34
+    save
  35
+  end
31 36
 end
5  app/models/user.rb
@@ -57,7 +57,7 @@ class User < ActiveRecord::Base
57 57
                   :birth_date,
58 58
                   :form_birth_date,
59 59
                   :address_attributes,
60  
-                  :phone_attributes
  60
+                  :phones_attributes
61 61
 
62 62
   belongs_to :account
63 63
 
@@ -133,7 +133,8 @@ class User < ActiveRecord::Base
133 133
   validate :validate_age
134 134
   #validates :password,    :presence => { :if => :password_required? }, :confirmation => true
135 135
 
136  
-  accepts_nested_attributes_for :addresses, :phones, :user_roles
  136
+  accepts_nested_attributes_for :addresses, :user_roles
  137
+  accepts_nested_attributes_for :phones, :reject_if => lambda { |t| ( t['display_number'].gsub(/\D+/, '').blank?) }
137 138
 
138 139
   state_machine :state, :initial => :active do
139 140
     state :inactive
2  app/views/admin/config/shipping_zones/edit.html.erb
@@ -2,7 +2,7 @@
2 2
 <h1>Editing Shipping Zone</h1>
3 3
 
4 4
 
5  
-<%= form_for(@shipping_zone, :as => :shipping_zone, :url => admin_config_shipping_zone_path(@shipping_zone)) do |f| %>
  5
+<%= form_for(@shipping_zone, :url => admin_config_shipping_zone_path(@shipping_zone)) do |f| %>
6 6
   <%= render :partial =>  'form', :locals => {:f => f} %>
7 7
 <% end %>
8 8
 
2  app/views/admin/config/shipping_zones/new.html.erb
@@ -2,7 +2,7 @@
2 2
 <h1>New Shipping Zone</h1>
3 3
 
4 4
 
5  
-<%= form_for(@shipping_zone, :as => :shipping_zone, :url => admin_config_shipping_zones_path()) do |f| %>
  5
+<%= form_for(@shipping_zone, :url => admin_config_shipping_zones_path()) do |f| %>
6 6
   <%= render :partial =>  'form', :locals => {:f => f} %>
7 7
 <% end %>
8 8
 
2  app/views/admin/config/tax_rates/edit.html.erb
@@ -2,7 +2,7 @@
2 2
 
3 3
 <h1>Editing (<%= @tax_rate.state.abbreviation %> <%= @tax_rate.tax_status.name %>) Tax Rate</h1>
4 4
 
5  
-<%= form_for(@tax_rate, :as => :tax_rate, :url => admin_config_tax_rate_path(@tax_rate)) do |f| %>
  5
+<%= form_for(@tax_rate, :url => admin_config_tax_rate_path(@tax_rate)) do |f| %>
6 6
   <%= render :partial =>  'form', :locals => {:f => f} %>
7 7
 <% end %>
8 8
 
2  app/views/admin/config/tax_rates/new.html.erb
... ...
@@ -1,7 +1,7 @@
1 1
 <%= render :partial => '/admin/config/sub_header'%>
2 2
 <h1>New tax_rate</h1>
3 3
 
4  
-<%= form_for(@tax_rate, :as => :tax_rate, :url => admin_config_tax_rates_path()) do |f| %>
  4
+<%= form_for(@tax_rate, :url => admin_config_tax_rates_path()) do |f| %>
5 5
   <%= render :partial =>  'form', :locals => {:f => f} %>
6 6
 <% end %>
7 7
 
2  app/views/shared/admin/_header_bar.html.erb
@@ -3,7 +3,7 @@
3 3
     <div id='header_bar' class='float-left span-24'>
4 4
       <%= render :partial => '/shared/admin/header_buttons'  %>
5 5
       <div class="admin-login">
6  
-        <span><%= current_user.name %></span>
  6
+        <span><%= current_user.name %></span><br/>
7 7
         <%= link_to 'Logout', logout_path, :id => 'admin-logout-button' %>
8 8
       </div>
9 9
     </div>
1  config/environments/production.rb
@@ -76,6 +76,7 @@
76 76
   # Enable serving of images, stylesheets, and javascripts from an asset server
77 77
   # config.action_controller.asset_host = "http://assets.example.com"
78 78
 
  79
+  config.action_mailer.default_url_options = { :host => 'rore.example.com' }
79 80
   # Disable delivery errors, bad email addresses will be ignored
80 81
   # config.action_mailer.raise_delivery_errors = false
81 82
 
11  spec/models/return_authorization_spec.rb
@@ -7,6 +7,17 @@
7 7
     @return_authorization = Factory(:return_authorization, :order => @order, :user => @user)
8 8
   end
9 9
 
  10
+  context '.mark_items_returned' do
  11
+    it 'should mark items returned' do
  12
+      order_item                = Factory.build(:order_item, :order => @order)
  13
+      order_item.state = 'paid'
  14
+      order_item.save
  15
+      return_item               = Factory(:return_item, :order_item => order_item, :return_authorization => @return_authorization)
  16
+      @return_authorization.mark_items_returned
  17
+      order_item.reload.state.should == 'returned'
  18
+      return_item.reload.returned.should be_true
  19
+    end
  20
+  end
10 21
   context '.process_ledger_transactions' do
11 22
     it 'should call process rma' do
12 23
       Invoice.expects(:process_rma).once

No commit comments for this range

Something went wrong with that request. Please try again.