Custom digital products & email delivery

I’d probably not restrict yourself to a pre-built module if you already have all the information in a custom database. The Digital Product extension is useful for simple use cases, but has some drawbacks.

The biggest drawback right now is that files must be available on a publicly accessible URL to allow them to be downloadable after purchase. It sounds like your client is likely some kind of publisher or distributor, and I don’t think they’d appreciate their entire library being public downloadable if people figure out the URL.

You can, however, take some inspiration from the Digital Product module, such as the custom shipment type (rather than custom product) approach to processing purchases.

If you’re dynamically rendering product views, you’ll probably want a custom add to cart snippet to add them dynamically too. You don’t necessarily need to create products on-demand for that, though that could be useful

Adding information to the emails is pretty straightforward:

  1. Listen to the event
  2. Add placeholder data
  3. Use placeholders in the email templates, e.g. like this code sample.

Adding an attachment directly is a little more work. The easiest way to do that would be to wait for Commerce 1.3, which adds a new event that fires right before an email is sent. That allows you to attach any file to an email. Doing it in 1.2 would require a custom comOrderEmailMessage class with additional logic; that requires a lot of duplication right now and is why we added the new event. Hopefully 1.3 will be in prerelease in about 4-6 weeks – it’s a massive release with tons of new goodies.

Given your no-account requirement, you’d likely save a record of who (email/order id) bought what ebook, assign it some really long secret hash, and create an endpoint on the site, provide it that hash, and use that to offer download options.