Skip to content

Instantly share code, notes, and snippets.

@sescobb27
Last active August 29, 2015 14:24
Show Gist options
  • Save sescobb27/842143cfce41c8e132a7 to your computer and use it in GitHub Desktop.
Save sescobb27/842143cfce41c8e132a7 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
var debug = Ember.Logger.debug;
// store/checkout/success
// ember-data 1.0.0-beta.19.1
// ember 1.11.3
export default Ember.Route.extend({
setupController: function (controller) {
debug('finding last successful order');
// this.store.all('order') => [{SUCCESSFUL_ORDER}, {NEW_ORDER(NO_ID)}]
// we need to reverse the orders and get the first one with ID (the last order)
// so we can get the last successful checkout.
// why? because this way we ensure that if the customers make some simultaneous
// checkouts they would see the last order and not the firstone.
// this.store.all('order').toArray().reverseObjects()
// this.store.all('order').reverseObjects()
// this.store.all('order’).get('reverseObjects')
// => internalModel.getRecord is not a function
var order = _.find(this.store.all('order').toArray().reverseObjects(), function (storeOrder) {
return storeOrder.get('id');
});
controller.set('order', order);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment