Archive for the ‘PrestaShop’ Category

18
Mar

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:

<!-- 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}">
			{*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}
		</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!

, , , , , , , , , , , , , , , , , , , , , ,

16
Mar

Some modules, especially payment modules, need extra or special order statuses – for example, our Amazon FPS module for PrestaShop needed an extra status “Processing Amazon FPS Payment”. How do we do this in PrestaShop?

Order statuses are stored in the table “order_state” and each order status is defined as a constant in the config/defines.inc.php. We will need to add our new order status to this table and also define it as a constant to be able to use it. As a module development company, we have 2 options:

  1. Give the insert query in the installation guide and ask our customers to run it manually – and define the constant in our module with the assumption that the customer will do it correctly.
  2. Make the module automatically add the status into the table and define the constant.

We like the second option – here is how to do it in PrestaShop for language “English” (id: 1)
Add this code on the top of your module file (that is, if your module name is Helloworld then your module file path is modules/helloworld/helloworld.php)

// check if the order status is defined
if (!defined('_MY_ORDER_STATUS_')) {
        // order status is not defined - check if, it exists in the table
	$rq = Db::getInstance()->getRow('
	SELECT `id_order_state` FROM `'._DB_PREFIX_.'order_state_lang`
	WHERE id_lang = \''.pSQL('1').'\' AND  name = \''.pSQL('My Order Status').'\'');
	if ($rq && isset($rq['id_order_state']) && intval($rq['id_order_state']) > 0) {
		// order status exists in the table - define it.
		define('_MY_ORDER_STATUS_', $rq['id_order_state']);
	} else {
                // order status doesn't exist in the table
                // insert it into the table and then define it.
		Db::getInstance()->Execute('
		INSERT INTO `'._DB_PREFIX_.'order_state` (`unremovable`, `color`) VALUES(1, \'lightblue\')');
		$stateid = Db::getInstance()->Insert_ID();
		Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'order_state_lang` (`id_order_state`, `id_lang`, `name`)
		VALUES(' . intval($stateid) . ', 1, \'My Order Status\')');
		define('_PS_OS_AMAZONFPS_PROCESS_PAYMENT_', $stateid);
	}
}

Hope this helps!

,