refinerycms-stores 0.0.16 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/Gemfile +2 -0
  2. data/VERSION +1 -1
  3. data/app/assets/images/Excel.png +0 -0
  4. data/app/assets/images/PowerPoint.png +0 -0
  5. data/app/assets/images/Word.png +0 -0
  6. data/app/assets/images/audio-icon.png +0 -0
  7. data/app/assets/images/camera-icon.png +0 -0
  8. data/app/assets/images/html-icon.png +0 -0
  9. data/app/assets/images/muku-doc-font-128.png +0 -0
  10. data/app/assets/images/pdf-icon.png +0 -0
  11. data/app/assets/images/print-icon.png +0 -0
  12. data/app/assets/images/video-icon.png +0 -0
  13. data/app/assets/images/warning-icon.png +0 -0
  14. data/app/assets/images/zip_thumb.png +0 -0
  15. data/app/assets/stylesheets/refinery/refinerycms-stores.sass +66 -0
  16. data/app/controllers/refinery/customers/customers_controller.rb +35 -17
  17. data/app/controllers/refinery/orders/admin/orders_controller.rb +2 -1
  18. data/app/controllers/refinery/orders/orders_controller.rb +14 -9
  19. data/app/controllers/refinery/products/admin/digidownloads_controller.rb +39 -0
  20. data/app/controllers/refinery/products/admin/products_controller.rb +54 -4
  21. data/app/controllers/refinery/products/digidownloads_controller.rb +32 -0
  22. data/app/controllers/refinery/products/products_controller.rb +3 -0
  23. data/app/controllers/refinery/stores/stores_controller.rb +3 -2
  24. data/app/controllers/refinery/stores_application_controller.rb +6 -1
  25. data/app/helpers/refinery/stores/stores_helper.rb +4 -3
  26. data/app/models/refinery/addresses/address.rb +42 -0
  27. data/app/models/refinery/customers/customer.rb +7 -1
  28. data/app/models/refinery/orders/line_item.rb +10 -0
  29. data/app/models/refinery/orders/order.rb +59 -47
  30. data/app/models/refinery/products/digidownload.rb +181 -0
  31. data/app/models/refinery/products/product.rb +21 -1
  32. data/app/views/refinery/customers/customers/edit.html.haml +54 -0
  33. data/app/views/refinery/customers/{new.html.haml → customers/new.html.haml} +10 -3
  34. data/app/views/refinery/orders/admin/orders/_actions.html.haml +4 -0
  35. data/app/views/refinery/orders/admin/orders/_order.html.haml +13 -0
  36. data/app/views/refinery/orders/admin/orders/_orders.html.haml +2 -0
  37. data/app/views/refinery/orders/admin/orders/_records.html.haml +12 -0
  38. data/app/views/refinery/orders/admin/orders/_sortable_list.html.haml +4 -0
  39. data/app/views/refinery/orders/admin/orders/index.html.haml +5 -0
  40. data/app/views/refinery/orders/admin/orders/show.html.haml +80 -0
  41. data/app/views/refinery/orders/orders/edit.html.haml +2 -2
  42. data/app/views/refinery/orders/orders/index.html.haml +19 -4
  43. data/app/views/refinery/orders/orders/show.html.haml +68 -25
  44. data/app/views/refinery/products/admin/digidownloads/_actions.html.haml +19 -0
  45. data/app/views/refinery/products/admin/digidownloads/_digidownload.html.haml +13 -0
  46. data/app/views/refinery/products/admin/digidownloads/_digidownloads.html.haml +2 -0
  47. data/app/views/refinery/products/admin/digidownloads/_form.html.haml +41 -0
  48. data/app/views/refinery/products/admin/digidownloads/_records.html.haml +12 -0
  49. data/app/views/refinery/products/admin/digidownloads/_sortable_list.html.haml +4 -0
  50. data/app/views/refinery/products/admin/digidownloads/edit.html.haml +2 -0
  51. data/app/views/refinery/products/admin/digidownloads/index.html.haml +6 -0
  52. data/app/views/refinery/products/admin/digidownloads/new.html.haml +2 -0
  53. data/app/views/refinery/products/admin/products/_form.html.haml +98 -0
  54. data/app/views/refinery/products/digidownloads/index.html.haml +28 -0
  55. data/app/views/refinery/products/digidownloads/show.html.haml +39 -0
  56. data/app/views/refinery/products/products/show.html.haml +10 -9
  57. data/app/views/refinery/shared/_address.html.haml +18 -0
  58. data/app/views/refinery/{orders/orders → shared}/_address_form.html.haml +0 -0
  59. data/app/views/refinery/{stores/stores → shared}/_cart.html.haml +2 -2
  60. data/app/views/refinery/{stores/stores → shared}/_cart_item.html.haml +0 -0
  61. data/app/views/refinery/shared/_customer_head.html.haml +20 -0
  62. data/app/views/refinery/stores/admin/stores/_actions.html.haml +46 -0
  63. data/app/views/refinery/stores/stores/show.html.haml +1 -1
  64. data/config/locales/en.yml +17 -0
  65. data/config/routes.rb +24 -9
  66. data/db/migrate/3_create_orders_orders.rb +2 -0
  67. data/db/migrate/7_create_products_digidownloads.rb +33 -0
  68. data/lib/refinery/addresses.rb +11 -11
  69. data/lib/refinery/addresses/engine.rb +3 -3
  70. data/lib/refinery/auth_key.rb +44 -0
  71. data/lib/refinery/customers.rb +11 -11
  72. data/lib/refinery/customers/engine.rb +3 -3
  73. data/lib/refinery/orders.rb +1 -1
  74. data/lib/refinery/products.rb +2 -2
  75. data/lib/refinery/products/engine.rb +2 -2
  76. data/lib/refinery/stores.rb +1 -0
  77. data/lib/refinery/stores/authenticated_system.rb +25 -0
  78. data/lib/refinery/stores/engine.rb +19 -0
  79. data/lib/refinerycms-stores.rb +5 -2
  80. data/readme.md +32 -1
  81. data/refinerycms-stores.gemspec +54 -20
  82. metadata +87 -37
  83. data/app/views/refinery/customers/edit.html.haml +0 -17
  84. data/app/views/refinery/orders/admin/orders/_actions.html.erb +0 -25
  85. data/app/views/refinery/orders/admin/orders/_form.html.erb +0 -122
  86. data/app/views/refinery/orders/admin/orders/_order.html.erb +0 -20
  87. data/app/views/refinery/orders/admin/orders/_orders.html.erb +0 -2
  88. data/app/views/refinery/orders/admin/orders/_records.html.erb +0 -18
  89. data/app/views/refinery/orders/admin/orders/_sortable_list.html.erb +0 -5
  90. data/app/views/refinery/orders/admin/orders/edit.html.erb +0 -1
  91. data/app/views/refinery/orders/admin/orders/index.html.erb +0 -7
  92. data/app/views/refinery/orders/admin/orders/new.html.erb +0 -1
  93. data/app/views/refinery/products/admin/products/_form.html.erb +0 -127
  94. data/app/views/refinery/stores/admin/stores/_actions.html.erb +0 -57
  95. data/app/views/refinery/stores/stores/_customer_head.html.haml +0 -12
data/Gemfile CHANGED
@@ -24,4 +24,6 @@ gem 'hpricot'
24
24
  gem 'ruby_parser'
25
25
  gem 'haml-rails'
26
26
  gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
27
+ gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
28
+ gem 'aws-sdk'
27
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.16
1
+ 0.1.0
@@ -81,10 +81,76 @@ table.product-header
81
81
  font-size: small
82
82
 
83
83
  .customer-actions
84
+ p
85
+ color: gray
86
+ padding-bottom: 1em
87
+ font-style: italic
84
88
  a
85
89
  font-color: blue
90
+ font-style: normal
86
91
 
87
92
  a:hover
88
93
  background: #c3c3c3
89
94
  text-decoration: underline
90
95
 
96
+ .download-documents
97
+ dl
98
+ float: left
99
+ text-align: center
100
+ font-size: small
101
+ dt, dd
102
+ width: 110px
103
+ float: left
104
+ dt
105
+ margin-bottom: 4em
106
+ // vertical space between the images
107
+ dd
108
+ text-align: center
109
+ margin: 65px 0 0 -110px
110
+ img.icon_image
111
+ height: 62px
112
+ width: 67px
113
+ vertical-align: bottom
114
+ margin-left: 20px
115
+ border: 0
116
+
117
+ #orders
118
+ th.date-col, td.date-col
119
+
120
+ th.order-no-col, td.order-no-col
121
+ text-align: left
122
+
123
+ th.item-col, td.item-col
124
+ text-align: left
125
+
126
+ th.amount-col, td.amount-col
127
+ text-align: right
128
+
129
+ th.status-col, td.status-col
130
+ text-align: center
131
+
132
+ .address-block
133
+ font-size: smaller
134
+ width: 40%
135
+ float: left
136
+ border: solid 1px #c3c3c3
137
+ padding: 1em
138
+
139
+ h3
140
+ color: #6a6a6a
141
+
142
+ .order-content
143
+ padding: 1em
144
+ float: none
145
+ clear: both
146
+
147
+ td.sub-total-type
148
+ text-align: right
149
+
150
+ td.item-unit-price
151
+ text-align: right
152
+
153
+ td.right-just
154
+ text-align: right
155
+
156
+
@@ -1,10 +1,13 @@
1
1
  module Refinery
2
2
  module Customers
3
- class CustomersController < ApplicationController
3
+ class CustomersController < ::ApplicationController
4
4
 
5
- crudify :customer
5
+ # crudify ::Refinery::Customers::Customer
6
6
 
7
7
  before_filter :authenticate_refinery_user!, :get_customer, :except => [:new, :create]
8
+
9
+ layout 'refinery/layouts/login', :only => :new
10
+
8
11
 
9
12
  def new
10
13
  @customer = Customer.new
@@ -12,22 +15,40 @@ module Refinery
12
15
 
13
16
  # GET /customers/:id/edit
14
17
  def edit
18
+ @billing_address =
19
+ ( @customer.billing_address.nil? ?
20
+ ::Refinery::Addresses::Address.new( :email => @customer.email ) :
21
+ @customer.billing_address
22
+ )
23
+ @shipping_address =
24
+ ( @customer.shipping_address.nil? ?
25
+ ::Refinery::Addresses::Address.new( :email => @customer.email ) :
26
+ @customer.shipping_address
27
+ )
15
28
  end
16
29
 
17
30
  # PUT /customers/:id
18
31
  def update
19
32
 
20
- if params[:customer][:password].blank? and params[:customer][:password_confirmation].blank?
21
- params[:customer].delete(:password)
22
- params[:customer].delete(:password_confirmation)
33
+ @billing_address, @shipping_address =
34
+ ::Refinery::Addresses::Address.update_addresses( @customer, params )
35
+
36
+ fields = ( params[:user].nil? ? :customers_customer : :user )
37
+
38
+ if params[fields][:password].blank? and params[fields][:password_confirmation].blank?
39
+ params[fields].delete(:password)
40
+ params[fields].delete(:password_confirmation)
23
41
  end
24
42
 
25
43
  # keep these the same
26
- params[:customer][:username] = params[:customer][:email]
44
+ params[fields][:username] = @customer.email
45
+
46
+ if @customer.update_attributes(params[fields]) &&
47
+ @billing_address.errors.empty? &&
48
+ @shipping_address.errors.empty?
27
49
 
28
- if @customer.update_attributes(params[:customer])
29
50
  flash[:notice] = t('successful', :scope => 'customers.update', :email => @customer.email)
30
- redirect_to root_path
51
+ redirect_to refinery.stores_root_path
31
52
 
32
53
  else
33
54
  render :action => 'edit'
@@ -36,13 +57,13 @@ module Refinery
36
57
  end
37
58
 
38
59
  def create
39
- @customer = Customer.new(params[:customer])
60
+ @customer = Customer.new(params[:customers_customer])
40
61
  @customer.username = @customer.email
41
62
 
42
63
  if @customer.save
43
64
  @customer.roles << ::Refinery::Role[:customer] # remember as a customer role
44
-
45
- redirect_to root_path
65
+ sign_in( @customer) # forces devise to login this user
66
+ redirect_to refinery.stores_root_path
46
67
 
47
68
  else
48
69
  @customer.errors.delete(:username) # this is set to email
@@ -55,7 +76,7 @@ module Refinery
55
76
  protected
56
77
 
57
78
  def redirect?
58
- if refinery_current_user.nil?
79
+ if current_refinery_user.nil?
59
80
  redirect_to new_refinery_user_session_path
60
81
  end
61
82
  end
@@ -64,11 +85,8 @@ module Refinery
64
85
  # get_customer -- returns @customer else error if cur_user mismatch
65
86
  # ----------------------------------------------------------------------
66
87
  def get_customer()
67
- if params[:id] != refinery_current_user.id
68
- error_404
69
- else
70
- @customer = Customer.find(params[:id])
71
- end
88
+ @customer = current_refinery_user
89
+ error_404 unless params[:id] == @customer.to_param
72
90
  end
73
91
 
74
92
  end # class
@@ -4,7 +4,8 @@ module Refinery
4
4
  class OrdersController < ::Refinery::AdminController
5
5
 
6
6
  crudify :'refinery/orders/order',
7
- :title_attribute => 'order_status', :xhr_paging => true
7
+ :title_attribute => 'order_status',
8
+ :xhr_paging => true
8
9
 
9
10
  end
10
11
  end
@@ -7,9 +7,12 @@ module Refinery
7
7
  # ensure state machine transitions
8
8
 
9
9
  before_filter :authenticate_refinery_user!
10
+
10
11
  before_filter :find_all_orders, :only => :index
11
12
  before_filter :find_order, :except => :index
12
- before_filter :setup_payment_gateway, :only => [:edit, :update, :purchase, :re_edit]
13
+ before_filter :setup_payment_gateway, :only => [:show, :edit, :update, :purchase, :re_edit]
14
+
15
+ helper 'refinery/stores/stores'
13
16
 
14
17
  def index
15
18
  # you can use meta fields from your model instead (e.g. browser_title)
@@ -18,9 +21,12 @@ module Refinery
18
21
  end
19
22
 
20
23
  def show
21
- # you can use meta fields from your model instead (e.g. browser_title)
22
- # by swapping @page for @order in the line below:
23
- present(@order)
24
+ if (@action = @order.get_render_template).nil?
25
+ present(@order)
26
+ else
27
+ prep_edit_view
28
+ render :action => @action
29
+ end # if..then..else no action
24
30
  end
25
31
 
26
32
  # update must proceed within confines of order state machine
@@ -70,12 +76,13 @@ module Refinery
70
76
  protected
71
77
 
72
78
  def find_all_orders
73
- @orders = Order.order('position ASC')
79
+ @orders = current_refinery_user.orders
74
80
  end
75
81
 
76
82
  def find_order
77
83
  @order = Order.find(params[:id])
78
- end
84
+ return false unless refinery_user_signed_in? && current_refinery_user == @order.user
85
+ end
79
86
 
80
87
  def find_page
81
88
  @page = ::Refinery::Page.where(:link_url => "/orders").first
@@ -86,9 +93,7 @@ module Refinery
86
93
  end
87
94
 
88
95
  def prep_edit_view
89
- if @billing_address.nil?
90
- @billing_address, @shipping_address = @order.get_billship_addresses
91
- end
96
+ @billing_address, @shipping_address = @order.get_billship_addresses( current_refinery_user )
92
97
  end
93
98
 
94
99
  end # class OrdersController
@@ -0,0 +1,39 @@
1
+ # #########################################################################
2
+ #
3
+ # ------------------------------------------------------------------------------
4
+ # ------------------------------------------------------------------------------
5
+ #
6
+ # #########################################################################
7
+ module Refinery
8
+ module Products
9
+ module Admin
10
+ class DigidownloadsController < ::Refinery::AdminController
11
+
12
+ # #########################################################################
13
+ crudify :'refinery/products/digidownload',
14
+ :title_attribute => 'doc_file_name', :xhr_paging => true
15
+
16
+
17
+ # #########################################################################
18
+
19
+ # ------------------------------------------------------------------------------
20
+ # ------------------------------------------------------------------------------
21
+
22
+ # #########################################################################
23
+ private
24
+ # #########################################################################
25
+
26
+
27
+ # ------------------------------------------------------------------------------
28
+ # ------------------------------------------------------------------------------
29
+
30
+ # ------------------------------------------------------------------------------
31
+ # ------------------------------------------------------------------------------
32
+ #
33
+ # #########################################################################
34
+
35
+
36
+ end # class DigidownloadsController
37
+ end # mod admin
38
+ end # mod products
39
+ end # mod refinery
@@ -6,7 +6,57 @@ module Refinery
6
6
  crudify :'refinery/products/product',
7
7
  :title_attribute => 'name', :xhr_paging => true
8
8
 
9
- end
10
- end
11
- end
12
- end
9
+
10
+ # ----------------------------------------------------------------------
11
+ # override crudify create
12
+ # ----------------------------------------------------------------------
13
+ def create
14
+ # set this object as last object, given the conditions of this class.
15
+ params[:product].merge!({
16
+ :position => ((::Refinery::Products::Product.maximum(:position, :conditions => "")||-1) + 1)
17
+ })
18
+
19
+ @product = ::Refinery::Products::Product.new(params[:product])
20
+
21
+ if @product.valid? && @product.save
22
+ flash.notice = t( 'refinery.crudify.created', :what => "#{@product.name}")
23
+
24
+ # successful creation
25
+ if params[:digi_download] == '1' # .. is digi_download needed too?
26
+ redirect_to refinery.new_products_admin_digidownload_path( :product_id => @product.id )
27
+ else #..straightforward create;
28
+ redirect_to :back
29
+ end
30
+
31
+ else # unsuccesful create
32
+ render :action => :new
33
+ end
34
+
35
+ end
36
+
37
+
38
+ # ----------------------------------------------------------------------
39
+ # override crudify update
40
+ # ----------------------------------------------------------------------
41
+ def update
42
+ if @product.update_attributes(params[:product])
43
+ # successful update
44
+ flash.notice = t( 'refinery.crudify.updated', :what => "#{@product.name}")
45
+
46
+ if params[:digi_download] == '1' # .. is digi_download needed too?
47
+ redirect_to refinery.new_products_admin_digidownload_path( :product_id => @product.id )
48
+ else #..straightforward update
49
+ redirect_to :back
50
+ end
51
+
52
+ else # ... failed update
53
+ render :action => :edit
54
+ end
55
+ end
56
+
57
+ # ----------------------------------------------------------------------
58
+ # ----------------------------------------------------------------------
59
+ end # class
60
+ end # mod
61
+ end # mod
62
+ end # mod
@@ -0,0 +1,32 @@
1
+ module Refinery
2
+ module Products
3
+ class DigidownloadsController < ::Refinery::StoresApplicationController
4
+
5
+ helper 'refinery/stores/stores'
6
+ before_filter :find_digidownload, :only => [:show, :download, :preview]
7
+
8
+ def index
9
+ @digidownloads = current_refinery_user.digidownloads
10
+ present(@page)
11
+ end
12
+
13
+ def show
14
+ present(@page)
15
+ end
16
+
17
+ def download
18
+ redirect_to @digidownload.doc.expiring_url(60) # temp authenticated url expires in 60 sec
19
+ end
20
+
21
+ protected
22
+
23
+ def find_digidownload
24
+ # TODO: verify that digid belongs to current user
25
+ @digidownload = ::Refinery::Products::Digidownload.find( params[:id] )
26
+ return false unless refinery_user_signed_in? && current_refinery_user == @digidownload.user
27
+ end
28
+
29
+
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,11 @@
1
1
  module Refinery
2
2
  module Products
3
3
  class ProductsController < ::Refinery::StoresApplicationController
4
+
4
5
  before_filter :find_cart
5
6
 
7
+ helper 'refinery/stores/stores'
8
+
6
9
  def show
7
10
  @product = Product.find(params[:id])
8
11
 
@@ -3,6 +3,7 @@ module Refinery
3
3
  class StoresController < ::Refinery::StoresApplicationController
4
4
 
5
5
  before_filter :authenticate_refinery_user!, :only => :checkout
6
+
6
7
  before_filter :find_first_store, :only => :index
7
8
  before_filter :find_store, :only => :show
8
9
  before_filter :find_page, :except => [:index, :add_to_cart, :empty_cart, :checkout]
@@ -48,7 +49,7 @@ module Refinery
48
49
  if @cart.items.empty?
49
50
  redirect_to_index("Your cart is empty")
50
51
  else
51
- @order = ::Refinery::Orders::Order.checkout!( @cart )
52
+ @order = ::Refinery::Orders::Order.checkout!( @cart, current_refinery_user )
52
53
  session[:cart] = nil
53
54
  redirect_to refinery.edit_orders_order_path( @order )
54
55
  end
@@ -60,7 +61,7 @@ module Refinery
60
61
  flash[:notice] = msg if msg
61
62
  redirect_to refinery.stores_store_path( find_first_store )
62
63
  end
63
-
64
+
64
65
 
65
66
  protected
66
67