Jump to content

[HELP] Linking "Mail Alerts 3.6.1" and "Customer Files Upload 1.9.1" modules


Recommended Posts

Hello,

I use the module "Customer Files Upload 1.9.1" (https://mypresta.eu/modules/ordering-process/customer-files-upload.html) in order to allow customers to upload some files to their order.

Now I am trying to modify the "Mail Alerts 3.6.1" module in order to see a preview of the uploaded files into the e-mail generated one a new order is created.

 

I modified the file /modules/mailalerts/mailalerts.php as follow:

<?php
/*...omissis...*/

if (!defined('_CAN_LOAD_FILES_'))
	exit;

include_once(dirname(__FILE__).'/MailAlert.php');

class MailAlerts extends Module
{
	/*...omissis...*/
	
	/* LINE 245: added function to fetch fetch from the database the files uploaded via module "Customer Files Upload 1.9.1" */
	public function getUploadedFiles($id_cart)
	{
		$sql_products = '
			SELECT `idcart`, `cookieid`, `description`, `filename`
			FROM `'._DB_PREFIX_.'orderfiles_product`
			WHERE `idcart` = '.(int)$id_cart;
		
		$sql_cart = '
			SELECT `idcart`, `description`, `filename`
			FROM `'._DB_PREFIX_.'orderfiles_cart`
			WHERE `idcart` = '.(int)$id_cart;

		$products_files = Db::getInstance()->executeS($sql_products);
		$cart_files = Db::getInstance()->executeS($sql_cart);
		$result = array();
		
		if($products_files)
		{
			foreach ($product_files as $key => $pf)
			{
				$item = [
					'idcart' => $pf['idcart'],
					'cookieid' => $pf['cookieid'],
					'description' => $pf['description'],
					'filename' => $pf['filename']
				];
				array_push($result, $item);
			}
		}
		
		if($cart_files)
		{
			foreach ($cart_files as $key => $cf)
			{
				$item = [
					'idcart' => $cf['idcart'],
					'cookieid' => null,
					'description' => $cf['description'],
					'filename' => $cf['filename']
				];
				array_push($result, $item);
			}
		}
		
		return $result;
	}

	public function hookActionValidateOrder($params)
	{
		/*...omissis...*/
		
		/* LINE 392: added code to display the previews */
		$uploaded_files = $this->getUploadedFiles((int)$params['cart']->id);
		$files_list = 'Cart ID: '.(int)$params['cart']->id.$cart_files;
		if ($uploaded_files && (count($uploaded_files) > 0)) 
		{
			$file_base_url = 'http://www.mydomain.com/modules/orderfiles';
			
			foreach ($uploaded_files as $key => $uf)
			{
				if ($uf['cookieid'] && ($uf['cookieid'] !== null))
				{
					$file_folder = '/productfiles/'.$uf['cookieid'];
				} else {
					$file_folder = '/cartfiles/'.$uf['idcart'];
				}
				
				$uploaded_files .= 
				'<p>
					<img src="'.$file_base_url.$file_folder.'/'.$uf['filename'].'.jpg"><br />'
					.$uf['description'].'<br/>
					(<a href="'.$file_base_url.$file_folder.'/'.$uf['filename'].'">'.$uf['filename'].'</a>)
				</p>';
			}
		} else {
			$files_list .= '<p><strong>ATTENTION! No file uploaded with this order.</strong></p>'; 
		}

		// Filling-in vars for email
		$template_vars = array(
			/*...omissis...*/

			/* LINE 484: added new template var */
			'{files_list}' => $files_list
		);

		/*...omissis...*/
	}

	/*...omissis...*/
}

Everything worked fine when I was trying to fetch and display data from one table only ('orderfiles_product'), but something went wrong when I tried to add the files recorded into a second table ('orderfiles_cart'): when I upload file both on the product page and on the cart page, only the cart files are loaded and previewed.

 

Thank you very much in advance for your kind help and availability.

Edited by saverio.cannilla (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...