MODULES
...
eCommerce
FAQ - eCommerce
How to Sell Digital Products
8min
in this article i'll explain how you can use our media download and ecommerce modules to sell digital products prerequisites you have installed the secure zone module's latest version you have installed the media downloads and ecommerce modules you have created products you have followed our document on cart, checkout and orders flow with the secure zone module introduction in this article, i'll explain how you can datasource to a media download item to a product allowing the product to be downloaded after it has been purchased to ensure that the media download can only be accessed after the product has been purchased we'll output it within a user orders layout create a media download item firstly, let's create our downloadable product, to do this we'll create a new media download item, you'll need to repeat this step for every product that can be downloaded we'll be using an image for this example, but you can use any file type that the media download module supports add datasource field to your products now we've added our downloadable product, let's datasource it to the product it is related to, we'll need to add a new custom field to our products to do this go to ecommerce > products > edit module structure then add a new field and set the type to 'datasource (single item)' finally, let's link each of our media download items to the products they're associated with, to do this head to ecommerce > products > your product > custom fields you should see a dropdown containing all the media download items, select the one that matches your product output the media download link within your user orders layout now we've got everything needed for our products to be downloadable, let's output the download somewhere it can only be accessed after being purchased locate the `user orders` layout within the secure zone module code editor > modules > module 5 (secure zones) > user orders within this layout we'll have access to the `orders` object, containing all of the user's previous purchases, this should also contain a order products (old) or order products flat (new) object (depending on your ecommerce module version) within each order this contains information about the product purchased, we'll have access to the media download item id from here we can output the products data like so {% for this in orders %} {{this order products\[0] product properties}} {% endfor %} however, we just need the media download item id which can be outputted like so, if you have other custom fields you'll need to replace 'product 1' with the field name {% for this in orders %} {% assign media download id = this order products\[0] product properties\['module field custom 14/product 1'] %} {% endfor %} if there are multiple products in one order, we'll need to create an array of the media download item ids for each product, we'll nest another loop within the loop above over {{orders}} here's how this would look {% assign media download id = '\[]' | parse json %} {% for this in orders %} {% for model in this order products%} {% assign media download id = media download id | add to array model product properties\['module field custom 14/product 1'] %} {% endfor %} {% assign media download id = media download id | join ',' %} {% endfor %} so no we've assigned all of our media download ids to ' media download id ' we'll use this within the 'item ids' parameter on our media download layout include {% include 'module' id '17' layout 'my layout' item ids media download id %} now, locate your media download layouts these can be found under code editor > modules > module 17 (media downloads) from here you can either use an existing layout or copy the default layout structure to create your own (ensure you've added a 'list' folder within the folder for your layout, the 'list' folder should then contain item and wrapper layouts) we'll only need to include the media download items within the 'wrapper' file, here's how this looks {% include 'modules/siteglide media downloads/get/get items' item layout 'item' %} then within the 'item' layout, we'll add an anchor to allow the items to be downloaded we'll also output the name of the media download item as the anchor's text \<p>\<a href="{{this\['url']}}">{{this\['name']}}\</a>\</p>