piggybak 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- piggybak (0.6.8)
4
+ piggybak (0.6.9)
5
5
  activemerchant
6
6
  countries
7
7
  devise
@@ -13,11 +13,18 @@ module Piggybak
13
13
  @order.create_payment_shipment
14
14
 
15
15
  if Piggybak.config.logging
16
- # TODO: Reimplement on correctly filtered params
17
- #clean_params = params[:piggybak_order].clone
18
- #clean_params["payments_attributes"]["0"]["number"] = clean_params["payments_attributes"]["0"]["number"].mask_cc_number
19
- #clean_params["payments_attributes"]["0"]["verification_value"] = clean_params["payments_attributes"]["0"]["verification_value"].mask_csv
20
- #logger.info "#{request.remote_ip}:#{Time.now.strftime("%Y-%m-%d %H:%M")} Order received with params #{clean_params.inspect}"
16
+ clean_params = params[:piggybak_order].clone
17
+ clean_params[:line_items_attributes].each do |k, li_attr|
18
+ if li_attr[:line_item_type] == "payment" && li_attr.has_key?(:payment_attributes)
19
+ if li_attr[:payment_attributes].has_key?(:number)
20
+ li_attr[:payment_attributes][:number] = li_attr[:payment_attributes][:number].mask_cc_number
21
+ end
22
+ if li_attr[:payment_attributes].has_key?(:verification_value)
23
+ li_attr[:payment_attributes][:verification_value] = li_attr[:payment_attributes][:verification_value].mask_csv
24
+ end
25
+ end
26
+ end
27
+ logger.info "#{request.remote_ip}:#{Time.now.strftime("%Y-%m-%d %H:%M")} Order received with params #{clean_params.inspect}"
21
28
  end
22
29
  @order.initialize_user(current_user, true)
23
30
 
@@ -17,7 +17,9 @@ module Piggybak
17
17
  after_save :document_address_changes
18
18
 
19
19
  attr_accessible :firstname, :lastname, :address1, :location,
20
- :address2, :city, :state_id, :zip, :country_id
20
+ :address2, :city, :state_id, :zip, :country_id,
21
+ :copy_from_billing
22
+ attr_accessor :is_shipping
21
23
 
22
24
  def set_default_country
23
25
  self.country ||= Country.find_by_abbr(Piggybak.config.default_country)
@@ -1,6 +1,6 @@
1
1
  module Piggybak
2
2
  class Country < ActiveRecord::Base
3
- attr_accessible :name, :abbr
3
+ attr_accessible :name, :abbr, :active_shipping, :active_billing
4
4
  has_many :states
5
5
 
6
6
  scope :shipping, where(:active_shipping => true)
@@ -50,6 +50,18 @@ module Piggybak
50
50
 
51
51
  return if sellable.nil?
52
52
 
53
+ # Inventory check
54
+ quantity_change = 0
55
+ if self.new_record?
56
+ quantity_change = self.quantity.to_i
57
+ elsif self.changes.keys.include?("quantity") && self.quantity > self.quantity_was
58
+ quantity_change = self.quantity - self.quantity_was
59
+ end
60
+ if sellable.quantity < quantity_change
61
+ self.errors.add(:sellable_id, "Insufficient inventory by #{quantity_change - sellable.quantity} unit(s).")
62
+ return
63
+ end
64
+
53
65
  self.description = sellable.description
54
66
  self.unit_price = sellable.price
55
67
  self.price = self.unit_price*self.quantity.to_i
@@ -33,6 +33,7 @@ module Piggybak
33
33
 
34
34
  self.billing_address ||= Piggybak::Address.new
35
35
  self.shipping_address ||= Piggybak::Address.new
36
+ self.shipping_address.is_shipping = true
36
37
 
37
38
  self.ip_address ||= 'admin'
38
39
  self.user_agent ||= 'admin'
@@ -4,7 +4,7 @@ module Piggybak
4
4
  validates_presence_of :key
5
5
  validates_presence_of :value
6
6
 
7
- attr_accessible :key, :value
7
+ attr_accessible :key, :value, :payment_method_id
8
8
 
9
9
  def admin_label
10
10
  "#{self.key} - #{self.value}"
@@ -8,6 +8,9 @@ module Piggybak
8
8
 
9
9
  accepts_nested_attributes_for :shipping_method_values, :allow_destroy => true
10
10
 
11
+ attr_accessible :active, :shipment_method_values_attributes, :description,
12
+ :klass
13
+
11
14
  validates_each :shipping_method_values do |record, attr, value|
12
15
  if record.klass.present?
13
16
  calculator = record.klass.constantize
@@ -3,6 +3,7 @@ module Piggybak
3
3
  belongs_to :shipping_method
4
4
  validates_presence_of :key
5
5
  validates_presence_of :value
6
+ attr_accessible :key, :value, :shipping_method_id
6
7
 
7
8
  def admin_label
8
9
  "#{self.key} - #{self.value}"
@@ -7,7 +7,8 @@ module Piggybak
7
7
  validates_presence_of :klass
8
8
 
9
9
  accepts_nested_attributes_for :tax_method_values, :allow_destroy => true
10
-
10
+ attr_accessible :active, :tax_method_values_attributes, :description,
11
+ :klass
11
12
  validates_each :tax_method_values do |record, attr, value|
12
13
  if record.klass
13
14
  calculator = record.klass.constantize
@@ -3,7 +3,8 @@ module Piggybak
3
3
  belongs_to :tax_method
4
4
  validates_presence_of :key
5
5
  validates_presence_of :value
6
-
6
+ attr_accessible :key, :value, :tax_method_id
7
+
7
8
  def admin_label
8
9
  "#{self.key} - #{self.value}"
9
10
  end
@@ -0,0 +1,15 @@
1
+ <a href="#" id="copy_from_billing">copy from billing</a>
2
+
3
+ %script
4
+ $('#copy_from_billing').click(function() {
5
+ $.each($('#piggybak_order_billing_address_attributes_field input'), function(i, el) {
6
+ if($(el).attr('id') != 'piggybak_order_billing_address_attributes_id') {
7
+ var shipping_id = $(el).attr('id').replace('billing', 'shipping');
8
+ $('#' + shipping_id).val($(el).val());
9
+ }
10
+ });
11
+ $('#piggybak_order_shipping_address_attributes_country_id').val($('#piggybak_order_billing_address_attributes_country_id').val());
12
+ piggybak_states.update_state_option('shipping');
13
+ $('#piggybak_order_shipping_address_attributes_state_id').val($('#piggybak_order_billing_address_attributes_state_id').val());
14
+ return false;
15
+ });
@@ -1,5 +1,5 @@
1
1
  :ruby
2
- type = form.jquery_namespace(field).match("billing") ? "billing" : "shipping"
2
+ type = form.object.is_shipping ? "shipping" : "billing"
3
3
 
4
4
  = form.collection_select "country_id", Piggybak::Country.send(type), :id, :name, { :selected => form.object.country_id.to_s }
5
5
 
@@ -266,6 +266,14 @@ module Piggybak
266
266
  visible false
267
267
 
268
268
  edit do
269
+ field :copy_from_billing do
270
+ visible do
271
+ bindings[:object].is_shipping
272
+ end
273
+ partial "copy_from_billing"
274
+ label "Help"
275
+ help "Copies address from billing to shipping."
276
+ end
269
277
  field :firstname
270
278
  field :lastname
271
279
  field :address1
@@ -36,7 +36,7 @@ module Piggybak
36
36
  desc "inject_devise", "add devise"
37
37
  def inject_devise
38
38
  puts 'add reference to devise in GEMFILE'
39
- insert_into_file "GEMFILE", "gem 'devise'\n", :after => "source 'https://rubygems.org'\n"
39
+ insert_into_file "Gemfile", "gem 'devise'\n", :after => "source 'https://rubygems.org'\n"
40
40
  end
41
41
 
42
42
 
@@ -1,3 +1,3 @@
1
1
  module Piggybak
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piggybak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-25 00:00:00.000000000 Z
14
+ date: 2012-10-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -134,6 +134,7 @@ files:
134
134
  - app/helpers/piggybak_helper.rb
135
135
  - app/views/rails_admin/main/_recorded_changer.html.erb
136
136
  - app/views/rails_admin/main/_polymorphic_nested.html.haml
137
+ - app/views/rails_admin/main/_copy_from_billing.html.haml
137
138
  - app/views/rails_admin/main/_location_select.html.haml
138
139
  - app/views/rails_admin/main/_order_details.html.erb
139
140
  - app/views/rails_admin/main/_ip_address.html.erb
@@ -211,7 +212,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
212
  version: '0'
212
213
  segments:
213
214
  - 0
214
- hash: 3697325078829363009
215
+ hash: -716439778691107520
215
216
  required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  none: false
217
218
  requirements:
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
221
  version: '0'
221
222
  segments:
222
223
  - 0
223
- hash: 3697325078829363009
224
+ hash: -716439778691107520
224
225
  requirements: []
225
226
  rubyforge_project:
226
227
  rubygems_version: 1.8.23