Created
February 18, 2015 20:16
-
-
Save dcherman/2c22ab95be0cdba764e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function unfinishedOrderLookup( orderId ) { | |
return request.server.methods.callApi("/orders/" + orderId ).then(function(res ) { | |
return res.order; | |
}); | |
} | |
function lookupOrdersByUid( uid ) { | |
return request.server.methods.callApi("/users/" + uid + "/orders?status=0"); | |
} | |
function lookUpOrder() { | |
var user; | |
return fetchUser() | |
.then( function( _user) { | |
user = _user; | |
// Expose unfinished order | |
var unfOrder = { quantity: 0 }, | |
uid = user.id !== undefined ? user.id : 0; | |
if ( uid ) { | |
return lookupOrdersByUid( uid ).then( function(res) { | |
if ( res.orders.length ) { | |
return res.orders[ 0 ]; | |
} | |
return unfOrder; | |
}); | |
} | |
// Unfinished order lookup | |
// Legacy drupal cookie | |
if (request.state.hasOwnProperty('orderId')) { | |
return unfinishedOrderLookup( request.state.orderId ); | |
} | |
return unfOrder; | |
}).then(function( order ) { | |
return [ user, order ]; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment