You have setup a download-able product in PrestaShop and want to make it available to customer’s who have paid and are verified. By default, as soon as the order goes through the product download link becomes active – what if, you want to first verify the order and only then, make the download link active? PrestaShop already has the framework for this ready – you just need to fill in some code to get it working.
Open: order-detail.php
At the bottom of this script you will find this section:
|
|
$smarty->assign('errors', $errors); if (Tools::getValue('ajax') == 'true') $smarty->display(_PS_THEME_DIR_.'order-detail.tpl'); else { include(dirname(__FILE__).'/header.php'); $smarty->display(_PS_THEME_DIR_.'order-detail.tpl'); include(dirname(__FILE__).'/footer.php'); } |
Add this line just above it:
|
|
$smarty->assign('denyDownloadForOrderStates', array(_PS_OS_PREPARATION_, _PS_OS_CANCELED_, _PS_OS_REFUND_, _PS_OS_ERROR_, _PS_OS_SHIPPING_)); |
In the array you will put all the order statuses for which you want to prevent product download.
Open: themes/[your-theme-name]/order-detail.tpl
Find the section marked: <!– Classic products –>
Modify this section like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<!-- Classic products --> {if $product.product_quantity > $product.customizationQuantityTotal} <tr class="item"> {if $return_allowed}<td class="order_cb"><input type="checkbox" id="cb_{$product.id_order_detail|intval}" name="ids_order_detail[{$product.id_order_detail|intval}]" value="{$product.id_order_detail|intval}" /></td>{/if} <td><label for="cb_{$product.id_order_detail|intval}">{if $product.product_reference}{$product.product_reference|escape:'htmlall':'UTF-8'}{else}--{/if}</label></td> <td class="bold"> <label for="cb_{$product.id_order_detail|intval}"> <span style="background-color: yellow">{*Schogini - added this line to check denyDownloadForOrderStates; we have populated this array in the php file too*} {if $product.download_hash && $invoice && !in_array($order_history.0.id_order_state, $denyDownloadForOrderStates)} <a href="{$base_dir}get-file.php?key={$product.filename|escape:'htmlall':'UTF-8'}-{$product.download_hash|escape:'htmlall':'UTF-8'}" title="{l s='download this product'}"> <img src="{$img_dir}icon/download_product.gif" class="icon" alt="{l s='Download product'}" /> </a> <a href="{$base_dir}get-file.php?key={$product.filename|escape:'htmlall':'UTF-8'}-{$product.download_hash|escape:'htmlall':'UTF-8'}" title="{l s='download this product'}"> {$product.product_name|escape:'htmlall':'UTF-8'} </a> {else} {$product.product_name|escape:'htmlall':'UTF-8'} {/if}</span> </label> </td> <td><input class="order_qte_input" name="order_qte_input[{$product.id_order_detail|intval}]" type="text" size="2" value="{$productQuantity|intval}" /><label for="cb_{$product.id_order_detail|intval}"><span class="order_qte_span editable">{$productQuantity|intval}</span></label></td> <td><label for="cb_{$product.id_order_detail|intval}">{convertPriceWithCurrency price=$product.product_price_wt currency=$currency convert=0}</label></td> <td><label for="cb_{$product.id_order_detail|intval}">{convertPriceWithCurrency price=$product.total_wt currency=$currency convert=0}</label></td> </tr> {/if} |
We have now removed the download links from the web but, what about the email that is sent?
I haven’t found a straight forward solution for it – what I have done is edited the email template and removed the download link altogether. Instead, I have added a message to the “order status change” email telling the customer to login into his account on the shop to download the product (no links are sent via any email)
Open: mails/[language]/download_product.html
And remove this tag {virtualProducts}
This will remove the link to download products from your email
You can now edit other email templates and add appropriate message informing the customer to login into his account on the shop to download the product.
You can check out the order statuses, whether an email will be sent when the order status is changed to it and the email template that will be sent via the admin area of your shop
Login into admin area > Orders tab > Statuses
Accordingly you can edit the email template file: mails/[language]/[email template.html or .txt]
I am sure there is a much more efficient method of doing it but, after a lot of searching this is what worked for me!