Log errors in sync_loan instead of crashing.

updating ebook is sometimes causing document update error. Possibly because
some of the calls made inside the function may change the ebook. Moved all
such calls to top so that the ebook in the db won't be changed before doing
save.
Add type="ebook" for all ebook documents in store.

Lack of that was causing return cart on the home page to break.