piggybak_coupons 0.0.14 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d229ad8ddeaf499695c9c236414a35c205bb9570
4
+ data.tar.gz: 7a2606ff77dd460c25d467c2b67830f17852b074
5
+ SHA512:
6
+ metadata.gz: eca994ed21c81059a2b6232a0a07e6818ed23f0634419f0b77130624223035f391d8acf179c22171e3e151a3eb8a918f3313ae5221b57edef82f55315d52f78c
7
+ data.tar.gz: b92ce30c5e070e6296f9b221d14f310ad46b9ec529a3a576123748c05bb5c3c0a230d57617301b4f358a7b7fa53f4ab1879a71e43e5e623869a0e87603769a29
data/README.md CHANGED
@@ -17,4 +17,4 @@ TODO
17
17
  Copyright
18
18
  ========
19
19
 
20
- Copyright (c) 2011 End Point & Steph Skardal. See LICENSE for further details.
20
+ Copyright (c) 2014 End Point & Steph Skardal. See LICENSE for further details.
data/Rakefile CHANGED
@@ -21,7 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
21
21
  end
22
22
 
23
23
  APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
- load 'rails/tasks/engine.rake'
25
24
 
26
25
 
27
26
 
@@ -0,0 +1 @@
1
+ //= require piggybak_coupons/piggybak_coupons
@@ -1,4 +1,7 @@
1
1
  $(function() {
2
+ if($('form#new_order').size() == 0) {
3
+ return;
4
+ }
2
5
  $('#coupon_code').change(function() {
3
6
  piggybak_coupons.apply_coupon();
4
7
  });
@@ -34,8 +37,8 @@ var piggybak_coupons = {
34
37
  dataType: "JSON",
35
38
  success: function(data) {
36
39
  if(data.valid_coupon) {
37
- var el1 = $('<input>').attr('type', 'hidden').attr('name', 'piggybak_order[line_items_attributes][2][line_item_type]').val('coupon_application');
38
- var el2 = $('<input>').attr('type', 'hidden').attr('name', 'piggybak_order[line_items_attributes][2][coupon_application_attributes][code]').val($('#coupon_code').val());
40
+ var el1 = $('<input>').attr('type', 'hidden').attr('name', 'order[line_items_attributes][2][line_item_type]').val('coupon_application');
41
+ var el2 = $('<input>').attr('type', 'hidden').attr('name', 'order[line_items_attributes][2][coupon_application_attributes][code]').val($('#coupon_code').val());
39
42
  $('#coupon').append(el1);
40
43
  $('#coupon').append(el2);
41
44
  $('#coupon_response').html('Coupon successfully applied to order.').show();
@@ -1,11 +1,9 @@
1
1
  module PiggybakCoupons
2
2
  class Coupon < ActiveRecord::Base
3
- self.table_name = 'coupons'
4
-
5
3
  has_many :coupon_applications
6
4
 
7
5
  attr_accessor :coupon_type, :application_detail
8
- attr_accessible :code, :amount, :discount_type, :min_cart_total, :expiration_date, :allowed_applications
6
+ # attr_accessible :code, :amount, :discount_type, :min_cart_total, :expiration_date, :allowed_applications
9
7
 
10
8
  validates_presence_of :code, :amount, :discount_type, :min_cart_total, :expiration_date, :allowed_applications
11
9
  validates_uniqueness_of :code
@@ -61,7 +59,8 @@ module PiggybakCoupons
61
59
  if object.is_a?(Piggybak::Order) && coupon.discount_type == "ship"
62
60
  ship_line_item = object.line_items.detect { |li| li.line_item_type == "shipment" }
63
61
  return "No shipping on this order." if !ship_line_item
64
- end
62
+ end
63
+
65
64
  coupon
66
65
  end
67
66
 
@@ -69,11 +68,11 @@ module PiggybakCoupons
69
68
  coupon = Coupon.find_by_code(code)
70
69
  return 0 if coupon.nil?
71
70
 
72
- # $ or % discount_type discount
73
71
  if coupon.discount_type == "$"
74
72
  return -1*coupon.amount
75
73
  elsif coupon.discount_type == "%"
76
- return (-1.to_f*(coupon.amount/100)*object.subtotal).to_c
74
+ coupon_amount = (-1.to_f*(coupon.amount.to_f/100.to_f)*object.subtotal)
75
+ return ((coupon_amount*100).to_i).to_f/100
77
76
  elsif coupon.discount_type == "ship"
78
77
  if object.is_a?(Piggybak::Order)
79
78
  ship_line_item = object.line_items.detect { |li| li.line_item_type == "shipment" }
@@ -1,20 +1,19 @@
1
1
  module PiggybakCoupons
2
2
  class CouponApplication < ActiveRecord::Base
3
- # TODO: figure out how to avoid this
4
- self.table_name = 'coupon_applications'
5
-
6
3
  belongs_to :coupon
7
4
  belongs_to :line_item, :class_name => "::Piggybak::LineItem", :dependent => :destroy
8
5
 
9
6
  attr_accessor :code, :order
10
- attr_accessible :line_item_id, :coupon_id, :code
7
+ # attr_accessible :line_item_id, :coupon_id, :code
11
8
 
12
9
  validate :validate_coupon
13
10
  def validate_coupon
11
+ Rails.logger.warn"stephie inside validate coupon #{self.code} #{self.order.inspect}"
14
12
  if self.new_record?
15
13
  valid_coupon = Coupon.valid_coupon(self.code, self.order, false)
16
14
  if valid_coupon.is_a?(::PiggybakCoupons::Coupon)
17
15
  self.coupon_id = valid_coupon.id
16
+ Rails.logger.warn "stephie: #{self.inspect}"
18
17
  else
19
18
  self.errors.add(:code, valid_coupon)
20
19
  end
@@ -1,5 +1,3 @@
1
- <%= javascript_include_tag "piggybak_coupons/piggybak_coupons" %>
2
-
3
1
  <div id="piggybak_coupon_apply_box">
4
2
  <div id="coupon_response" style="display:none;"></div>
5
3
  <input type="text" name="piggybak_coupon_code" id="coupon_code" value="<%= params.has_key?(:piggybak_coupon_code) ? params[:piggybak_coupon_code] : '' %>" />
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  PiggybakCoupons::Engine.routes.draw do
2
- match "/apply_coupon" => "coupon#apply"
2
+ get "/apply_coupon" => "coupon#apply"
3
3
  end
@@ -0,0 +1,6 @@
1
+ class UpdatePiggybakCouponsTables < ActiveRecord::Migration
2
+ def change
3
+ rename_table :coupons, :piggybak_coupons_coupons
4
+ rename_table :coupon_applications, :piggybak_coupons_coupon_applications
5
+ end
6
+ end
@@ -22,11 +22,12 @@ module PiggybakCoupons
22
22
  :sort => config.line_item_types[:payment][:sort]
23
23
  }
24
24
  config.line_item_types[:payment][:sort] += 1
25
+ config.additional_line_item_attributes[:coupon_application_attributes] = [:code]
25
26
  end
26
27
  end
27
28
 
28
- initializer "piggybak_coupons.precompile_hook", :group => :all do |app|
29
- app.config.assets.precompile += ['piggybak_coupons/piggybak_coupons.js']
29
+ initializer "piggybak_coupons.assets.precompile" do |app|
30
+ app.config.assets.precompile += ['piggybak_coupons/piggybak_coupons-application.js']
30
31
  end
31
32
 
32
33
  initializer "piggybak_coupons.rails_admin_config" do |app|
@@ -1,3 +1,3 @@
1
1
  module PiggybakCoupons
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,32 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piggybak_coupons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steph Skardal
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-20 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 3.2.8
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 3.2.8
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
+ dependencies: []
30
13
  description: Coupon support for Piggybak.
31
14
  email:
32
15
  - steph@endpoint.com
@@ -34,82 +17,77 @@ executables: []
34
17
  extensions: []
35
18
  extra_rdoc_files: []
36
19
  files:
37
- - app/controllers/piggybak_coupons/coupon_controller.rb
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - app/assets/javascripts/piggybak_coupons/piggybak_coupons-application.js
38
24
  - app/assets/javascripts/piggybak_coupons/piggybak_coupons.js
39
- - app/models/piggybak_coupons/coupon_application.rb
25
+ - app/controllers/piggybak_coupons/coupon_controller.rb
40
26
  - app/models/piggybak_coupons/coupon.rb
27
+ - app/models/piggybak_coupons/coupon_application.rb
41
28
  - app/views/piggybak_coupons/_apply_coupon.html.erb
42
29
  - config/routes.rb
43
30
  - db/migrate/20121012220537_piggybak_coupons_setup.rb
44
31
  - db/migrate/20121022165051_coupon_decimal_field_update.rb
45
- - lib/piggybak_coupons/line_item_decorator.rb
32
+ - db/migrate/20140325200807_update_piggybak_coupons_tables.rb
33
+ - lib/piggybak_coupons.rb
46
34
  - lib/piggybak_coupons/engine.rb
35
+ - lib/piggybak_coupons/line_item_decorator.rb
47
36
  - lib/piggybak_coupons/version.rb
48
- - lib/piggybak_coupons.rb
49
37
  - lib/tasks/piggybak_coupons_tasks.rake
50
- - LICENSE
51
- - Rakefile
52
- - README.md
53
- - test/integration/navigation_test.rb
54
- - test/test_helper.rb
55
- - test/dummy/script/rails
56
- - test/dummy/Rakefile
57
38
  - test/dummy/README.rdoc
58
- - test/dummy/app/controllers/application_controller.rb
59
- - test/dummy/app/assets/stylesheets/application.css
39
+ - test/dummy/Rakefile
60
40
  - test/dummy/app/assets/javascripts/application.js
41
+ - test/dummy/app/assets/stylesheets/application.css
42
+ - test/dummy/app/controllers/application_controller.rb
61
43
  - test/dummy/app/helpers/application_helper.rb
62
44
  - test/dummy/app/views/layouts/application.html.erb
63
- - test/dummy/config/locales/en.yml
45
+ - test/dummy/config.ru
46
+ - test/dummy/config/application.rb
47
+ - test/dummy/config/boot.rb
48
+ - test/dummy/config/database.yml
64
49
  - test/dummy/config/environment.rb
65
- - test/dummy/config/routes.rb
50
+ - test/dummy/config/environments/development.rb
66
51
  - test/dummy/config/environments/production.rb
67
52
  - test/dummy/config/environments/test.rb
68
- - test/dummy/config/environments/development.rb
69
- - test/dummy/config/initializers/wrap_parameters.rb
70
- - test/dummy/config/initializers/secret_token.rb
71
- - test/dummy/config/initializers/mime_types.rb
72
- - test/dummy/config/initializers/session_store.rb
73
53
  - test/dummy/config/initializers/backtrace_silencers.rb
74
54
  - test/dummy/config/initializers/inflections.rb
75
- - test/dummy/config/boot.rb
76
- - test/dummy/config/application.rb
77
- - test/dummy/config/database.yml
78
- - test/dummy/public/500.html
55
+ - test/dummy/config/initializers/mime_types.rb
56
+ - test/dummy/config/initializers/secret_token.rb
57
+ - test/dummy/config/initializers/session_store.rb
58
+ - test/dummy/config/initializers/wrap_parameters.rb
59
+ - test/dummy/config/locales/en.yml
60
+ - test/dummy/config/routes.rb
61
+ - test/dummy/public/404.html
79
62
  - test/dummy/public/422.html
63
+ - test/dummy/public/500.html
80
64
  - test/dummy/public/favicon.ico
81
- - test/dummy/public/404.html
82
- - test/dummy/config.ru
65
+ - test/dummy/script/rails
66
+ - test/integration/navigation_test.rb
83
67
  - test/piggybak_coupons_test.rb
68
+ - test/test_helper.rb
84
69
  homepage: http://www.piggybak.org/
85
70
  licenses: []
71
+ metadata: {}
86
72
  post_install_message:
87
73
  rdoc_options: []
88
74
  require_paths:
89
75
  - lib
90
76
  required_ruby_version: !ruby/object:Gem::Requirement
91
- none: false
92
77
  requirements:
93
- - - ! '>='
78
+ - - ">="
94
79
  - !ruby/object:Gem::Version
95
80
  version: '0'
96
- segments:
97
- - 0
98
- hash: 4523658976649586592
99
81
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
82
  requirements:
102
- - - ! '>='
83
+ - - ">="
103
84
  - !ruby/object:Gem::Version
104
85
  version: '0'
105
- segments:
106
- - 0
107
- hash: 4523658976649586592
108
86
  requirements: []
109
87
  rubyforge_project:
110
- rubygems_version: 1.8.23
88
+ rubygems_version: 2.2.2
111
89
  signing_key:
112
- specification_version: 3
90
+ specification_version: 4
113
91
  summary: Coupon support for Piggybak.
114
92
  test_files:
115
93
  - test/integration/navigation_test.rb