Orchard Core Digital Downloads - Prompt Templates
Deliver Digital Products
You are an Orchard Core expert. Generate accurate setup, recipes and extension guidance for the CrestApps Digital Downloads module, which keeps a product's files privately, grants them to buyers when an order is paid, and serves them through signed, expiring links.
Guidelines
- Install
CrestApps.OrchardCore.Downloads(or theCrestApps.OrchardCore.Cms.Core.Targetsbundle) in the web/startup project. - Enable
CrestApps.OrchardCore.Downloads. It depends onCrestApps.OrchardCore.Commerce,CrestApps.OrchardCore.Products,CrestApps.OrchardCore.OrdersandOrchardCore.Contents. Selling also needs Carts andCrestApps.OrchardCore.Checkoutwith a payment provider (seeorchardcore-products,orchardcore-checkoutandorchardcore-payments). - Enable
CrestApps.OrchardCore.Customersso a guest's Contact step asks for the email the links go to (seeorchardcore-customers). - Never put sellable files in the media library. Files go to the protected file area
IProtectedFileStore<DigitalDownloadFiles>, which no URL serves. - Enable an antivirus feature such as
OrchardCore.Antivirus.ClamAVto scan uploads. Uploads run through Orchard Core'sFileCreationServiceand everyIFileEventHandler(seeorchardcore-file-upload-securityandorchardcore-antivirus). - Set the site's Base URL so links in emails work outside a request.
- Orders and carts are covered by
orchardcore-ordersandorchardcore-carts; the shared Commerce menu and storefront account byorchardcore-commerce. - All recipe JSON must be wrapped in
{ "steps": [...] }. - All C# classes must use the
sealedmodifier, except View Models.
Feature and Services
| Item | Value |
|---|---|
| Feature ID | CrestApps.OrchardCore.Downloads |
| Content part | DigitalFilesPart (Files, DownloadLimit, LinkLifetimeDays) |
| File store | IProtectedFileStore<DigitalDownloadFiles> (CrestApps.OrchardCore.FileStorage: SaveAsync, FindAsync, OpenAsync, DeleteAsync, returning ProtectedFile), registered with services.AddProtectedFileArea<DigitalDownloadFiles>(DownloadsConstants.StoreFolder); folder App_Data/.../DigitalFiles/{fileId}/{fileName}. IDigitalFileStore, DigitalFileStore and StoredDigitalFile were removed; stored files are unchanged |
| Entitlements | DownloadEntitlement in collection Downloads, DownloadEntitlementIndex |
| Service | DownloadService (GrantAsync, ListAsync, CreateUrlAsync, ResolveAsync, RecordDownloadAsync, RevokeOrderAsync, RevokeAsync, ResetAsync) |
| Site settings | DownloadSettings (group downloads, Settings > Commerce > Downloads): DownloadLimit 5, LinkLifetimeDays 30 |
| Order seams | DownloadOrderEventHandler (OrderLineGrantHandlerBase<DigitalFilesPart>), IOrderEmailSectionProvider, OrderDownloadsDisplayDriver |
| Permission | ManageDigitalDownloads ("Manage digital files and downloads"; Administrator, Store manager), also guards the settings group |
| Recipe step | DigitalFiles (needs OrchardCore.Recipes.Core) |
| Report | Downloads under Reports > Commerce and the Digital Downloads dashboard widget (with CrestApps.OrchardCore.Reports) |
| Report Builder | Downloads data source (Downloads) with DownloadEntitlements (ManageDigitalDownloads; file store ids and links never exposed); recipe DownloadsReportBuilderReports adds an editable copy to the Store group |
| Sample recipe | Digital downloads sample: a Digital Product type, two ebooks with PDFs, an Ebooks listing, coupons WELCOME10 and EBOOKS5 |
The Part and Settings
DigitalFilesPart.Files holds DigitalFile items (FileId, FileName, Size). DownloadLimit and LinkLifetimeDays override the site settings when set; 0 means no limit or links that never expire.
The part editor uploads each file straight to the store through POST /Admin/downloads/files/upload (up to 1 GB, ManageDigitalDownloads), then saving the product keeps the ids the store knows. GET /Admin/downloads/files/{fileId} opens a stored file for staff. Removing a file from a product does not delete it, so past orders keep their downloads.
When an IFileEventHandler refuses a file, or the scanner cannot be reached, nothing is kept and the upload answers 400 with the reason.
Granting and Revoking
DownloadOrderEventHandler derives from OrderLineGrantHandlerBase<DigitalFilesPart> (Orders.Core), which reads each line's files from the product version the order bought (IContentManager.GetPurchasedAsync(line)), so editing the product later does not change what a buyer gets:
- Paid:
DownloadService.GrantAsync(order)creates one entitlement per file of each line's product, from the product version that was bought, inside the checkout's unit of work so the confirmation email can carry the links. Granting again adds only what is missing. - Canceled: revokes the order's entitlements.
- Refunded: revokes only once the order is refunded in full.
From the order's admin page, staff can Take back one file (DownloadsRevoke) or Give downloads back (DownloadsReset), which resets the count, extends the link by the site lifetime and restores a revoked right.
Links
- A link is
/downloads/{token}(routeDigitalDownload). The token is the entitlement id protected with data protection purposeCrestApps.OrchardCore.Downloads.Link, so links can be shown again; validity is decided by the entitlement. - Opening a link shows a Download button. The download is a
POST, so mail link scanners never use up a download. RecordDownloadAsynccounts under a lock per entitlement.- A dead link answers
410(expired, used up, canceled or refunded), or404when it names nothing.
Buyers see their links on their order page, in the confirmation email (Your downloads, through DownloadEmailSectionProvider) and on account/downloads (AccountDownloads).
Ship Files with a Recipe
Each file names its product and gives its bytes as Base64, or Text for a small text file, up to 10 MB. A product that already has a file of that name keeps it, so rerunning adds nothing. Place the step after the Content step that creates the products.
{
"steps": [
{
"name": "DigitalFiles",
"Files": [
{ "ProductId": "4dgtlprod0trailguide00000a", "FileName": "trail-field-guide.pdf", "Base64": "JVBERi0xLjQK..." },
{ "ProductId": "4dgtlprod0notes0000000000a", "FileName": "read-me.txt", "Text": "Thanks for buying." }
]
}
]
}
A product type for downloads uses ProductPart with product type Digital plus DigitalFilesPart. An order of digital products only has no shipping step.
Extending
- Add a section to the order confirmation email from another module by implementing the Orders
IOrderEmailSectionProviderseam, asDownloadEmailSectionProviderdoes. - Grant other entitlements on payment by deriving from
OrderGrantHandlerBase, orOrderLineGrantHandlerBase<TPart>(implementGetGrantedLineIdsAsync,GrantLineAsync,RevokeLineAsync) when the grant comes from a product part; both handle paid, canceled and full-refund events. - Resolve
DownloadServiceto list or revoke an order's entitlements from custom code instead of writing to theDownloadscollection.
Troubleshooting
| Symptom | Check |
|---|---|
| Upload answers 400 | An IFileEventHandler (antivirus) refused the file or the scanner is unreachable |
| No links in the confirmation email | The order must be paid; the product version bought must have files |
| Email links point to the wrong host | Set the site Base URL |
| Link answers 410 | The entitlement expired, was used up, or the order was canceled or fully refunded. Use Give downloads back |
| Guest gets no links | Enable Customers so checkout collects the guest's email |
| DigitalFiles step error | The product must exist (run after Content), bytes must be valid base64 and at most 10 MB |