rightnow_oms 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGELOG +12 -0
  2. data/README.md +145 -66
  3. data/app/assets/javascripts/rightnow_oms/app/app.js.coffee +12 -4
  4. data/app/assets/javascripts/rightnow_oms/app/controllers/cart.js.coffee +17 -32
  5. data/app/assets/javascripts/rightnow_oms/app/models/cart.js.coffee +50 -28
  6. data/app/assets/javascripts/rightnow_oms/app/models/cart_item.js.coffee +28 -49
  7. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.handlebars +30 -0
  8. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/{show_in_detail.hjs → show_in_detail.handlebars} +3 -3
  9. data/app/assets/javascripts/rightnow_oms/app/templates/carts/{show.hjs → show.handlebars} +4 -3
  10. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_cartable_count.handlebars +2 -0
  11. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.handlebars +30 -0
  12. data/app/assets/javascripts/rightnow_oms/app/views/cart_items/show_in_detail.js.coffee +4 -1
  13. data/app/assets/javascripts/rightnow_oms/application.js.coffee +10 -0
  14. data/app/assets/javascripts/rightnow_oms/cart_items.js +10 -0
  15. data/app/assets/javascripts/rightnow_oms/config/app.js.coffee +5 -0
  16. data/app/assets/javascripts/rightnow_oms/config/locales/en.js.coffee +24 -0
  17. data/app/assets/javascripts/rightnow_oms/config/locales/zh_CN.js.coffee +24 -0
  18. data/app/assets/javascripts/rightnow_oms/lib/ember/data/my_rest_adapter.js.coffee +2 -167
  19. data/app/assets/javascripts/rightnow_oms/vendor/cldr.js +240 -0
  20. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.js +1530 -587
  21. data/app/assets/javascripts/rightnow_oms/vendor/ember-data.min.js +1 -1
  22. data/app/assets/javascripts/rightnow_oms/vendor/ember-i18n.js +123 -0
  23. data/app/assets/javascripts/rightnow_oms/vendor/{ember-0.9.5.js → ember.js} +1584 -928
  24. data/app/assets/javascripts/rightnow_oms/vendor/ember.min.js +5 -5
  25. data/app/assets/stylesheets/rightnow_oms/carts.css.scss +93 -85
  26. data/app/controllers/rightnow_oms/cart_items_controller.rb +2 -2
  27. data/app/controllers/rightnow_oms/orders_controller.rb +27 -5
  28. data/app/models/rightnow_oms/cart.rb +1 -0
  29. data/app/models/rightnow_oms/cart_item.rb +1 -0
  30. data/app/models/rightnow_oms/order.rb +26 -2
  31. data/app/views/rightnow_oms/cart_items/_list.html.haml +24 -0
  32. data/app/views/rightnow_oms/orders/show.html.haml +2 -0
  33. data/config/initializers/rightnow_oms.rb +4 -0
  34. data/config/initializers/validates_timeliness.rb +40 -0
  35. data/config/locales/validates_timeliness.en.yml +16 -0
  36. data/config/locales/validates_timeliness.zh-CN.yml +16 -0
  37. data/db/migrate/20120224051751_add_required_arrival_time_to_rightnow_oms_orders.rb +6 -0
  38. data/db/migrate/20120302085200_add_tastes_to_rightnow_oms_order_items.rb +6 -0
  39. data/lib/rightnow_oms.rb +5 -1
  40. data/lib/rightnow_oms/controller_extension.rb +33 -0
  41. data/lib/rightnow_oms/controller_helpers.rb +4 -21
  42. data/lib/rightnow_oms/version.rb +1 -1
  43. metadata +71 -35
  44. data/app/assets/javascripts/rightnow_oms/app/templates/cart_items/show.hjs +0 -23
  45. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_cartable_count.hjs +0 -1
  46. data/app/assets/javascripts/rightnow_oms/app/templates/carts/show_in_detail.hjs +0 -27
  47. data/app/assets/javascripts/rightnow_oms/application.js +0 -8
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ *Rightnow OMS 0.1.6 (Mon 01:43, Mar 05, 2012)*
2
+
3
+ * Fixed 0.1.5 release error
4
+
5
+ *Rightnow OMS 0.1.5 (Mon 01:43, Mar 05, 2012)*
6
+
7
+ * Upgraded ember and ember-data
8
+ * Fixed lots of bugs
9
+ * Support I18n
10
+ * Created associations between models
11
+ * Added a few unit tests for javascript
12
+
1
13
  *Rightnow OMS 0.1.4 (Wed 11:57, Feb 22, 2012)*
2
14
 
3
15
  * Upgraded Ember.JS to 0.9.5
data/README.md CHANGED
@@ -14,6 +14,7 @@ Add the following gems to your Gemfile:
14
14
  gem 'acts_as_api'
15
15
  gem 'haml-rails'
16
16
  gem 'confstruct'
17
+ gem 'ransack'
17
18
 
18
19
  group :assets do
19
20
  gem 'uglifier'
@@ -32,89 +33,73 @@ Make sure that all requirements are met and add RightnowOms to your Gemfile.
32
33
 
33
34
  and run `bundle install`
34
35
 
35
- ## Usage
36
+ ## Setup
36
37
 
37
- Mount RightnowOms to your application.
38
+ Mount `rightnow_oms` to your application.
38
39
 
39
40
  ```ruby
40
41
  # config/routes.rb
41
- mount RightnowOms::Engine => "rightnow_oms"
42
+ mount RightnowOms::Engine => "rightnow_oms", as: :rightnow_oms
42
43
  ```
43
44
 
44
- Create the migrations with:
45
+ Install the migrations of `rightnow_oms`:
45
46
 
46
47
  ```bash
47
48
  rake rightnow_oms:install:migrations
48
49
  rake db:migrate
49
50
  ```
50
51
 
51
- Run `bundle install` and require ember and ember-data in your `app/assets/javascripts/application.js`:
52
+ `rightnow_oms` is built based on ember, ember-data and ember-i18n, so you need to
53
+ install these libs first. Or you can use the files in
54
+ `rightnow_oms`. So you need to add the following lines to your `app/assets/javascripts/application.js`:
52
55
 
53
56
  ```
54
- = require rightnow_oms/vendor/ember-0.9.5
57
+ = require rightnow_oms/vendor/ember
55
58
  = require rightnow_oms/vendor/ember-data
59
+ = require rightnow_oms/vendor/ember-i18n
56
60
  ```
57
61
 
58
- Add the following line to your `app/assets/javascripts/application.js`:
62
+ After ember libs installed, you need to add `rightnow_oms/application`
63
+ to your `app/assets/javascripts/application.js`:
59
64
 
60
65
  ```
61
66
  = require rightnow_oms/application
62
67
  ```
63
68
 
64
- Add the stylesheets to your `app/assets/stylesheets/application.css`:
69
+ To enable the default theme of `rightnow_oms`, you need to link the
70
+ default stylesheet into your `app/assets/stylesheets/application.css`:
65
71
 
66
72
  ```
67
73
  = require rightnow_oms/application
68
74
  ```
69
75
 
70
- Create a layout for your detailed cart view like:
76
+ The configurations of `rightnow_oms` ember application are saved in key-value
77
+ pairs. To override the default configurations, you only need to call
78
+ `RightnowOms.configure` and reset the values of the configurations.
71
79
 
72
- ```haml
73
- # app/views/layouts/rightnow_oms/cart.html.haml
74
- !!!
75
- %html
76
- %head
77
- %title RightnowOms
78
- = stylesheet_link_tag "application"
79
- = javascript_include_tag "application"
80
- = csrf_meta_tags
80
+ ```javascript
81
+ RightnowOms.configure(function(config) {
82
+ // Disable autoCommit
83
+ config.set('autoCommit', false);
81
84
 
82
- %body
83
- = yield
85
+ // Set the default locale to zh_CN
86
+ config.set('defaultLocale', 'zh_CN');
87
+ });
84
88
  ```
85
89
 
86
- You need to configure your new order url in RightnowOms:
90
+ ## Usage
87
91
 
88
- ```ruby
89
- # config/initializers/rightnow_oms.rb
90
- RightnowOms.configure do
91
- new_order_url '/orders/new'
92
- end
93
- ```
92
+ ### Add a Float Cart to Your Pages
94
93
 
95
- Add before filters to your controllers which need to use the cart:
94
+ First, you need to load/create a cart for your pages. By adding a before
95
+ filter `load_or_create_cart` to your controllers, you can get the cart.
96
96
 
97
97
  ```ruby
98
98
  # This before filter will create an instance variable @cart
99
99
  before_filter :load_or_create_cart
100
100
  ```
101
101
 
102
- Create cartable models in your application:
103
-
104
- ```ruby
105
- class Product < ActiveRecord::Base
106
- acts_as_cartable
107
- end
108
- ```
109
-
110
- By default, Cart loads the name and price of cartable models by
111
- attributes named name and price. You can customize these attributes:
112
-
113
- ```ruby
114
- acts_as_cartable { name: :your_name_attr, price: :your_price_attr }
115
- ```
116
-
117
- Add a place holder for your cart in your views:
102
+ Secondly, you need to add a place holder for your cart in your views:
118
103
 
119
104
  ```html
120
105
  <div id="rightnow-oms">
@@ -124,7 +109,7 @@ Add a place holder for your cart in your views:
124
109
  </div>
125
110
  ```
126
111
 
127
- and load your cart in the view:
112
+ And then you can load the cart:
128
113
 
129
114
  ```javascript
130
115
  $(function() {
@@ -132,43 +117,133 @@ and load your cart in the view:
132
117
  });
133
118
  ```
134
119
 
135
- You can add cartables to the cart by:
120
+ ### Add Cartable Things to Your Cart
121
+
122
+ `rightnow_oms` can only accept cartable model, so the things you added
123
+ to the cart must be a cartable model. To define a cartable model, you
124
+ just need to call the extended method `acts_as_cartable` in the model
125
+ class.
126
+
127
+ ``` ruby
128
+ class Product < ActiveRecord::Base
129
+ acts_as_cartable
130
+ end
131
+ ```
132
+
133
+ By default, Cart loads the name and price of cartable models by
134
+ attributes named name and price. But you can define your own name and
135
+ price attributes as follows:
136
+
137
+ ```ruby
138
+ class Product < ActiveRecord::Base
139
+ acts_as_cartable name: :your_name_attr, price: :your_price_attr
140
+ end
141
+ ```
142
+
143
+ Now you can add cartables to the cart.
136
144
 
137
145
  ```javascript
138
146
  RightnowOms.cartController.addCartItem({
139
147
  cartable_id: 1, // required
140
148
  cartable_type: 'Product', // required
141
149
  price: '10.00', // required
142
-
143
- // optional, indicating this is a child node of another one
144
- parent_id: 2,
145
-
150
+ name: 'Parent Product', // optional
151
+ quantity: 1, // optional
146
152
  // optional, grouping cart items
147
- group: 'booking'
148
- }, function(cartItem) {
149
- // Do something after the cart item is created
153
+ group: 'booking',
154
+ // optional
155
+ children: [{
156
+ cartable_id: 2, // required
157
+ cartable_type: 'Product', // required
158
+ price: '5.00', // required
159
+ name: 'Child Product', // optional
160
+ quantity: 1, // optional
161
+ // optional, grouping cart items
162
+ group: 'booking',
163
+ })
150
164
  })
151
165
  ```
152
166
 
153
- ### Strategy to sync data with remote
167
+ ### Manage Your Cart
154
168
 
155
- By default, RightnowOms sync the data immediately when you change the
156
- data objects in the store. But by setting `autoCommit` to `false`, you
157
- can change the default behavior.
169
+ Create a layout for your detailed cart view like:
170
+
171
+ ```haml
172
+ # app/views/layouts/rightnow_oms/cart.html.haml
173
+ !!!
174
+ %html
175
+ %head
176
+ %title RightnowOms
177
+ = stylesheet_link_tag "application"
178
+ = javascript_include_tag "application"
179
+ = csrf_meta_tags
180
+
181
+ %body
182
+ = yield
183
+ ```
184
+
185
+ ### Create an Order with the Cart
186
+
187
+ To create an order, you need to specify the url of the page which the
188
+ customer will add more detailed information on it. After you click the
189
+ submit button on the detailed cart page, you will be redirected to the
190
+ url which you have set.
191
+
192
+ ```ruby
193
+ # config/initializers/rightnow_oms.rb
194
+ RightnowOms.configure do
195
+ new_order_url '/orders/new'
196
+ end
197
+ ```
198
+
199
+ ### Checkout
200
+
201
+ WIP
202
+
203
+ ## I18n
204
+
205
+ `rightnow_oms` supports I18n now. By default it only includes two
206
+ locales: en and zh_CN, but you can create your own locales easily.
207
+ First, you need to define your translations, for example:
158
208
 
159
209
  ```javascript
160
- RightnowOms.config.set('autoCommit', false)
210
+ var zh_CN = {
211
+ 'cart.cartable.counter': '购物车'
212
+ 'cart.total': '总计'
213
+
214
+ 'cart_item.name': '名称'
215
+ 'cart_item.price': '价格'
216
+ 'cart_item.quantity': '数量'
217
+ 'cart_item.total': '小计'
218
+
219
+ 'currency.unit': '¥'
220
+
221
+ 'buttons.check_cart': '查看我的购物车'
222
+ 'buttons.delete': '删除'
223
+ 'buttons.clean_cart': '清空购物车'
224
+ 'buttons.continue_to_shop': '继续购物'
225
+ 'buttons.new_order': '提交订单'
226
+
227
+ 'titles.cart': '我的购物车'
228
+
229
+ 'alerts.saving_cart': '正在保存购物车,请稍后。。。'
230
+
231
+ 'confirmations.delete_cart_item': '您确定要删除该商品吗?'
232
+ 'confirmations.clean_up_cart': '您确定要清空您的购物车吗?'
233
+ };
161
234
  ```
162
235
 
163
- If you turn off auto-commit, you need to sync the data explicitly. When
164
- you have created, updated and deleted any data object in the client
165
- side, you ought to commit these changes by yourself.
236
+ And then add your translations to `rightnow_oms` and set it as the
237
+ default locale:
166
238
 
167
239
  ```javascript
168
- RightnowOms.commit(true)
240
+ RightnowOms.configure(function(config) {
241
+ config.set('locales.zh_CN', zh_CN);
242
+ config.set('defaultLocale', 'zh_CN');
243
+ });
169
244
  ```
170
245
 
171
- Now you have all things done. Wish you have a good day.
246
+ It's welcome to create a pull request for your locale.
172
247
 
173
248
  ## Development
174
249
 
@@ -176,9 +251,9 @@ RightnowOms is developed with Ruby 1.9.3-p0 and Rails 3.1.3
176
251
 
177
252
  First of all, you need to create a database config for RightnowOms.
178
253
  There are already some useful templates for you under
179
- `spec/dummy/config/`. RightnowOms use PostgreSQL by default. If you want
180
- to setup other databases, for example mysql, you need to modify the
181
- Gemfile by yourself.
254
+ `spec/dummy/config/`. RightnowOms use MySQL by default. If you want
255
+ to setup to use other databases, for example PostgreSQL, you need to modify the
256
+ Gemfile and add the adapters by yourself.
182
257
 
183
258
  ```bash
184
259
  bundle install
@@ -193,5 +268,9 @@ Gemfile by yourself.
193
268
  rails s
194
269
  ```
195
270
 
271
+ For the javascript unit tests, you need to start the dummy application
272
+ first, and then open your browser and visit
273
+ [http://localhost:3000/test/qunit](http://localhost:3000/test/qunit)
274
+
196
275
  ## Copyright
197
276
  Copyright 2011-2012 Beijing Menglifang Network Technology and Science Co.,Ltd. All rights reserved.
@@ -9,11 +9,19 @@ window.RightnowOms = Ember.Application.create
9
9
 
10
10
  _commitTimer: null
11
11
 
12
- window.RightnowOms.store = DS.Store.create
12
+ config: Em.Object.create()
13
+
14
+ configure: (reconfigure) ->
15
+ reconfigure(RightnowOms.config) if reconfigure
16
+
17
+ defaultLocale = RightnowOms.config.get('defaultLocale') || 'en'
18
+ locale = 'locales.' + defaultLocale
19
+ Em.I18n.translations = RightnowOms.config.get(locale)
20
+
21
+
22
+ RightnowOms.store = DS.Store.create
23
+ revision: 2
13
24
  adapter:
14
25
  DS.MyRESTAdapter.create
15
26
  bulkCommit: false
16
27
  namespace: 'rightnow_oms'
17
-
18
- window.RightnowOms.config = Em.Object.create()
19
- window.RightnowOms.config.set('autoCommit', true)
@@ -1,6 +1,10 @@
1
1
  RightnowOms.cartController = Ember.Object.create
2
2
  store: RightnowOms.store
3
3
 
4
+ #find: (id) ->
5
+ #cart = @store.find(RightnowOms.Cart, id)
6
+ #@set('content', cart)
7
+
4
8
  load: (cart) ->
5
9
  RightnowOms.store.load(RightnowOms.Cart, cart.id, cart)
6
10
  @set('content', RightnowOms.store.find(RightnowOms.Cart, cart.id))
@@ -10,29 +14,13 @@ RightnowOms.cartController = Ember.Object.create
10
14
 
11
15
  # item: a hash
12
16
  addCartItem: (item) ->
17
+ cartItem = @get('content').findCartItemByCartable(item.cartable_id, item.cartable_type)
18
+ if cartItem && cartItem.isProcessing()
19
+ return alert(Em.I18n.t('alerts.saving_cart'))
20
+
13
21
  cartItem = @get('content').addCartItem(item)
14
22
  RightnowOms.commit()
15
-
16
- return if !(item.children && item.children.length > 0)
17
-
18
- self = @
19
-
20
- addChildren = (parent, children) ->
21
- children.forEach((c) ->
22
- c.parent_id = parent.get('id')
23
- self.addCartItem(c)
24
- )
25
-
26
- return addChildren(cartItem, item.children) if cartItem.get('id')?
27
-
28
- afterCartItemCreated = ->
29
- if (!cartItem.get('isDirty')) && (!cartItem.get('isDeleted'))
30
- addChildren(cartItem, item.children)
31
- cartItem.removeObserver('isDirty', afterCartItemCreated)
32
- RightnowOms.commit(true) unless RightnowOms.config.get('autoCommit')
33
-
34
- cartItem.addObserver('isDirty', afterCartItemCreated)
35
-
23
+
36
24
  # @id: id of the cart item to be updated
37
25
  # @properties: a hash which is the new properties of the cart item.
38
26
  #
@@ -43,27 +31,24 @@ RightnowOms.cartController = Ember.Object.create
43
31
  # 'quantity': 2
44
32
  # })
45
33
  updateCartItem: (id, properties) ->
46
- if RightnowOms.CartItem.findById(id).isProcessing()
47
- alert('正在保存购物车,请稍后。。。')
48
- return
34
+ if @get('content').findCartItemById(id).isProcessing()
35
+ return alert(Em.I18n.t('alerts.saving_cart'))
49
36
 
50
37
  @get('content').updateCartItem(id, properties)
51
38
  RightnowOms.commit()
52
39
 
53
40
  increaseCartItem: (id) ->
54
- if RightnowOms.CartItem.findById(id).isProcessing()
55
- alert('正在保存购物车,请稍后。。。')
56
- return
41
+ if @get('content').findCartItemById(id).isProcessing()
42
+ return alert(Em.I18n.t('alerts.saving_cart'))
57
43
 
58
44
  cartItem = @get('content').increaseCartItem(id)
59
45
  RightnowOms.commit(true)
60
46
 
61
47
  decreaseCartItem: (id) ->
62
- cartItem = RightnowOms.CartItem.findById(id)
48
+ cartItem = @get('content').findCartItemById(id)
63
49
 
64
50
  if cartItem.isProcessing()
65
- alert('正在保存购物车,请稍后。。。')
66
- return
51
+ return alert(Em.I18n.t('alerts.saving_cart'))
67
52
 
68
53
  if cartItem.get('isDecreasable')
69
54
  @get('content').decreaseCartItem(id)
@@ -73,14 +58,14 @@ RightnowOms.cartController = Ember.Object.create
73
58
 
74
59
  removeCartItem: (id, silent) ->
75
60
  remove = true
76
- remove = confirm('您确定要删除该商品吗?') unless silent
61
+ remove = confirm(Em.I18n.t('confirmations.delete_cart_item')) unless silent
77
62
 
78
63
  if remove
79
64
  @get('content').removeCartItem(id)
80
65
  RightnowOms.commit(true)
81
66
 
82
67
  cleanUp: ->
83
- if confirm('您确定要清空您的购物车吗?')
68
+ if confirm(Em.I18n.t('confirmations.clean_up_cart'))
84
69
  @get('content').cleanUp()
85
70
  RightnowOms.commit(true)
86
71
 
@@ -1,80 +1,102 @@
1
1
  RightnowOms.Cart = DS.Model.extend
2
- cartItems: (->
3
- RightnowOms.CartItem.all()
4
- ).property()
2
+ cart_items: DS.hasMany('RightnowOms.CartItem', { embedded: true })
5
3
 
6
- cartableCount: (->
4
+ # TODO Use cart_items instead
5
+ cartItems: Ember.computed(->
6
+ @get('cart_items')
7
+ ).property("cart_items")
8
+
9
+ cartableCount: Ember.computed(->
7
10
  count = 0
8
- @get('cartItems').forEach (item) ->
11
+ @get('cart_items').forEach (item) ->
9
12
  count += item.get('quantity') unless item.get('hasParent')
10
13
 
11
14
  count
12
- ).property("cartItems.@each.quantity")
15
+ ).property("cart_items.@each.quantity")
13
16
 
14
- total: (->
17
+ total: Ember.computed(->
15
18
  total = 0
16
- @get('cartItems').forEach (item) ->
19
+ @get('cart_items').forEach (item) ->
17
20
  total += item.get('price') * item.get('quantity') unless item.get('hasParent')
18
21
 
19
22
  round(total, 2)
20
- ).property("cartItems.@each.quantity", "cartItems.@each.price")
23
+ ).property("cart_items.@each.quantity", "cart_items.@each.price")
21
24
 
22
25
  addCartItem: (item) ->
23
26
  return @createCartItem(item) if item.mergable == false
24
27
 
25
- cartItem = RightnowOms.CartItem.findByCartableAndParentId(item.cartable_id, item.cartable_type, item.parent_id)
28
+ cartItem = @findCartItemByCartable(item.cartable_id, item.cartable_type)
26
29
 
27
- if cartItem?
28
- cartItem.increase() unless cartItem.get('parent')?
30
+ if cartItem? && !cartItem.get('hasParent')
31
+ cartItem.increase()
29
32
  else
30
33
  cartItem = @createCartItem(item)
31
34
 
32
35
  cartItem
33
36
 
34
37
  createCartItem: (item)->
35
- cartItem = RightnowOms.store.createRecord(RightnowOms.CartItem, item)
38
+ cartItem = RightnowOms.CartItem.createRecord(item)
39
+ @get('cart_items').pushObject(cartItem)
40
+
41
+ return cartItem if !(item.children && item.children.length > 0)
42
+
43
+ return cartItem.addChild(c) for c in item.children if cartItem.get('id')?
36
44
 
37
- if cartItem.get('hasParent')
38
- cartItem.get('parent').set('children', RightnowOms.CartItem.findByParentId(cartItem.get('id')))
45
+ afterCartItemCreated = ->
46
+ if (!cartItem.get('isDirty')) && (!cartItem.get('isDeleted'))
47
+ cartItem.addChild(c) for c in item.children
48
+ cartItem.removeObserver('isDirty', afterCartItemCreated)
49
+ RightnowOms.commit(true) if RightnowOms.config.get('autoCommit')
50
+
51
+ cartItem.addObserver('isDirty', afterCartItemCreated)
39
52
 
40
53
  cartItem
41
54
 
42
55
  updateCartItem: (id, properties) ->
43
- cartItem = RightnowOms.CartItem.findById(id)
56
+ cartItem = @findCartItemById(id)
44
57
  cartItem.setProperties(properties) if cartItem?
45
58
 
46
59
  cleanUp: ->
47
- cartItemIds = @get('cartItems').map (item) ->
60
+ cartItemIds = @get('cart_items').map (item) ->
48
61
  return item.get('id')
49
62
 
63
+ self = @
50
64
  cartItemIds.forEach (id) ->
51
- item = RightnowOms.CartItem.findById(id)
52
-
53
- # INFO Children will be deleted when the parent is deleted
54
- item.deleteRecord() if item && !item.get('hasParent')
65
+ self.removeCartItem(id)
55
66
 
56
67
  removeCartItem: (id) ->
57
- cartItem = RightnowOms.CartItem.findById(id)
58
-
68
+ cartItem = @findCartItemById(id)
69
+ @get('cart_items').removeObject(cartItem)
59
70
  cartItem.deleteRecord() if cartItem?
60
71
 
61
72
  cartItem
62
73
 
63
74
  increaseCartItem: (id) ->
64
- cartItem = RightnowOms.CartItem.findById(id)
65
-
75
+ cartItem = @findCartItemById(id)
66
76
  cartItem.increase()
77
+
67
78
  cartItem
68
79
 
69
80
  decreaseCartItem: (id) ->
70
- cartItem = RightnowOms.CartItem.findById(id)
71
-
81
+ cartItem = @findCartItemById(id)
72
82
  cartItem.decrease()
83
+
73
84
  cartItem
74
85
 
86
+ # TODO Rename to findAllCartItemsInGroup()
75
87
  findCartItemsByGroup: (group) ->
76
- @get('cartItems').filter (item) ->
88
+ @get('cart_items').filter (item) ->
77
89
  return true if item.get('group') == group
78
90
 
91
+ # @private
92
+ findCartItemById: (id) ->
93
+ @get('cart_items').filterProperty('id', id)[0]
94
+
95
+ # @private
96
+ findCartItemByCartable: (cartableId, cartableType) ->
97
+ @get('cart_items').filter((item) ->
98
+ return true if item.get('cartable_id') == cartableId && item.get('cartable_type') == cartableType
99
+ ).get('firstObject')
100
+
79
101
  RightnowOms.Cart.reopenClass
80
102
  isSingleton: true