Opencart, in addition to selling regular physical goods, allows you to sell digital goods - files that can be downloaded after purchase. This is a default functionality that is available in all versions of the CMS. The article will help you understand how it works.

What is opencart download?

First of all, this is an object stored in the database. Each download file has its own identifier (download_id), which is used to implement the product-to-file connection and, in fact, to download this file. That is, you do not interact with the physical file directly.

A download is a property of the product and is associated with it in exactly the same way that categories, filters, etc. are. The download file is not a stand-alone item, you cannot sell it separately from the product. It is also not possible to buy separate files attached to the product.

How opencart stores files for download

The /system/storage/download/ folder is the default place where opencart stores its downloads. The DIR_DOWNLOAD constant contains that path. You can change it in config.php.

In the database, the following tables are provided for saving downloads:

  • oc_download
  • oc_download_description
  • oc_product_to_download

It looks like this:

Explanation of some table fields:

  • download_id is an automatically created unique identifier of the download item;
  • filename is the name under which the file is stored on the server. Note that when you save a file, opencart adds a random string to its name. For example, if you are creating a download with the file.pdf file, it will be named as file.pdf.7nVP71yFpwHUPhqvfcHkjRyJPkESssCr in the DIR_DOWNLOAD directory. This prevents direct access to files and overwriting files with the same tipycal names such as manual.pdf, guide.pdf, etc;
  • mask is the name under which a customer downloads the file;
  • name is what a customer see in the download list.

How to link a file to a product

  1. Firstly, you have to create a download. Для початку, необхідно створити завантаження. To do this, go to Catalog -> Downloads and push the “Add new” button to open the form.

  1. Upload a file using the Upload button. Filename and Mask fields are filled in automatically. You have to fill in the download name and click Save.

You can also manually specify a file name in the Filename field. In this case, make sure that the file with the same name is in the /storage/download/ directory. Random character set after file extension is optional if you manually upload files to the server.

  1. Now that the download file is created, you can link it to a product. Open the product for editing and go to the Links tab and start typing the download name in the Downloads field. In the drop-down list, select the needed file.

  1. Save the product. That’s all, the download is now linked to the product and the customer will be able to download it after purchasing the product.

Opencart settings you should pay attention to

The main opencart settings contain some options which are related to downloads. Let’s look at them.

Complete order status – The client will only be able to access the download when the status of his order is one of checked statuses in this field. The setting is located in the Options tab.

There are fields in the Server tab:

They contain allowed extensions and MIME-types. The file must satisfy both conditions, otherwise opencart will not save it. A list of common MIME types can be found on Wikipedia.

How the customer gets access to the download

To access files, the customer must purchase the product and the status of the order must be Completed. Please note that a customer cannot place a guest order if at least one item in the cart has downloads. Registration is required because access to downloads is made from the personal account.

Download link looks like:
Opencart makes a query to the database using download_id to get details of the item (filename, mask). Also at this moment Opencart checks if the customer really bought the product to which the file is attached. If the validation is successful and the request returns information, Opencart reads the file _Filename_ into the stream and then passes it to customer’s browser as a file. The browser suggests to save it as _Mask_. In other words, the customer does not interact with the original _Filename_ file directly. Direct access to the file is not possible.

The advantages of the Advanced Downloads module

First of all, you need to understand that the module is not a replacement for the default Downloads feature, but only a complement to it. Yes, if you remove or disable a module, all downloads and their relations will remain.

            Main advantages of the Advanced Downloads module:

  1. The module allows free access to files so that a customer can download, for example, the manual to the fridge without buying it. When you create a download, you can specify whether it is paid or free. A product may have both types of downloads.
  2. The module allows you to output a list of attached downloads directly to the product page. It's just convenient. Of course, a customer can download a paid file only after purchase.
  3. Advanced Downloads simplifies the process of creating downloads and linking them to the product. For example, creation and attachment are carried out in a single place in the Downloads tab in the product form.

All other features of the module are detailed on its page.