Exemple #1
0
/**
 * Given some details, generate a printable packing slip.
 *
 * @param string $title Title of the packing slip.
 * @param array $details Array of details about the packing slip.
 * @param array $products Array of products for the packing slip.
 * @return string Generated HTML packing slip.
 */
function generatePrintablePackingSlip($title, $details, $products)
{
	$db = $GLOBALS['ISC_CLASS_DB'];

	$template = new TEMPLATE('ISC_LANG');
	$template->frontEnd();
	$template->setTemplateBase(ISC_BASE_PATH . "/templates");
	$template->panelPHPDir = ISC_BASE_PATH . "/includes/display/";
	$template->templateExt = "html";
	$template->setTemplate(getConfig("template"));

	$template->assign('PackingSlipTitle', $title);
	$template->assign('OrderId', $details['shiporderid']);
	$template->assign('OrderDate', cdate($details['shiporderdate']));

	if(!empty($details['shipmethod'])) {
		$template->assign('ShippingMethod', isc_html_escape($details['shipmethod']));
	}
	else {
		$template->assign('HideShippingMethod', 'display: none');
	}

	if(!empty($details['shiptrackno'])) {
		$template->assign('TrackingNo', isc_html_escape($details['shiptrackno']));
	}
	else {
		$template->assign('HideTrackingNo', 'display: none');
	}

	if(!empty($details['shipcomments'])) {
		$template->assign('Comments', nl2br(isc_html_escape($details['shipcomments'])));
		$template->assign('HideComments', '');
	}
	else {
		$template->assign('Comments', '');
		$template->assign('HideComments', 'display: none');
	}

	if(!empty($details['shipdate'])) {
		$template->assign('DateShipped', cDate($details['shipdate']));
	}
	else {
		$template->assign('HideShippingDate', 'display: none');
	}

	if(empty($products)) {
		return false;
	}

	$query = "
		SELECT customerid, CONCAT(custconfirstname, ' ', custconlastname) AS ordcustname, custconemail AS ordcustemail, custconphone AS ordcustphone
		FROM [|PREFIX|]customers
		WHERE customerid = '".$db->Quote($details['shipcustid'])."'
	";
	$query .= $db->AddLimit(0, 1);
	$result = $db->Query($query);

	$template->assign('CustomerName', '');
	$template->assign('CustomerEmail', '');
	$template->assign('CustomerPhone', '');

	if($customer = $db->Fetch($result)) {
		// Format the customer details
		$template->assign('CustomerName', isc_html_escape($customer['ordcustname']));
		$template->assign('CustomerEmail', isc_html_escape($customer['ordcustemail']));
		$template->assign('CuastomerPhone', isc_html_escape($customer['ordcustphone']));
		$template->assign('CustomerId', $customer['customerid']);
	}
	else {
		$template->assign('HideCustomerDetails', 'display: none');
	}

	$template->assign('StoreAddressFormatted', nl2br(GetConfig('StoreAddress')));

	$addressDetails = array(
		'shipfirstname'	=> $details['shipbillfirstname'],
		'shiplastname'	=> $details['shipbilllastname'],
		'shipcompany'	=> $details['shipbillcompany'],
		'shipaddress1'	=> $details['shipbillstreet1'],
		'shipaddress2'	=> $details['shipbillstreet2'],
		'shipcity'		=> $details['shipbillsuburb'],
		'shipstate'		=> $details['shipbillstate'],
		'shipzip'		=> $details['shipbillzip'],
		'shipcountry'	=> $details['shipbillcountry'],
		'countrycode'	=> $details['shipbillcountrycode'],
	);
	$template->assign('BillingAddress', ISC_ADMIN_ORDERS::buildOrderAddressDetails($addressDetails, false));
	$template->assign('BillingPhone', isc_html_escape($details['shipbillphone']));
	if(!$details['shipbillphone']) {
		$template->assign('HideBillingPhone', 'display: none');
	}
	$template->assign('BillingEmail', isc_html_escape($details['shipbillemail']));
	if(!$details['shipbillemail']) {
		$template->assign('HideBillingEmail', 'display: none');
	}

	$addressDetails = array(
		'shipfirstname'	=> $details['shipshipfirstname'],
		'shiplastname'	=> $details['shipshiplastname'],
		'shipcompany'	=> $details['shipshipcompany'],
		'shipaddress1'	=> $details['shipshipstreet1'],
		'shipaddress2'	=> $details['shipshipstreet2'],
		'shipcity'		=> $details['shipshipsuburb'],
		'shipstate'		=> $details['shipshipstate'],
		'shipzip'		=> $details['shipshipzip'],
		'shipcountry'	=> $details['shipshipcountry'],
		'countrycode'	=> $details['shipshipcountrycode'],
	);
	$template->assign('ShippingAddress', ISC_ADMIN_ORDERS::buildOrderAddressDetails($addressDetails, false));
	$template->assign('ShippingPhone', isc_html_escape($details['shipshipphone']));
	if(!$details['shipshipphone']) {
		$template->assign('HideShippingPhone', 'display: none');
	}
	$template->assign('ShippingEmail', isc_html_escape($details['shipshipemail']));
	if(!$details['shipshipemail']) {
		$template->assign('HideShippingEmail', 'display: none');
	}

	$fieldsArray = array();
	$query = "
		SELECT o.*
		FROM [|PREFIX|]order_configurable_fields o
		JOIN [|PREFIX|]product_configurable_fields p ON o.fieldid = p.productfieldid
		WHERE o.orderid=".(int)$details['shiporderid']."
		ORDER BY p.fieldsortorder ASC
	";
	$result = $db->Query($query);
	$fields = array();
	while ($row = $db->Fetch($result)) {
		$fieldsArray[$row['ordprodid']][] = $row;
	}

	// Build the list of products that are being shipped
	$productsTable = '';
	foreach($products as $product) {
		$template->assign('ProductName', isc_html_escape($product['prodname']));
		if($product['prodcode']) {
			$template->assign('ProductSku', isc_html_escape($product['prodcode']));
		}
		else {
			$template->assign('ProductSku', getLang('NA'));
		}
		$template->assign('ProductQuantity', $product['prodqty']);

		$pOptions = '';
		if($product['prodoptions'] != '') {
			$options = @unserialize($product['prodoptions']);
			if(!empty($options)) {
				foreach($options as $name => $value) {
					$template->assign('FieldName', isc_html_escape($name));
					$template->assign('FieldValue', isc_html_escape($value));
					$pOptions .= $template->GetSnippet('PrintableInvoiceItemConfigurableField');
				}
			}
		}

		if($pOptions) {
			$template->assign('ProductOptions', $pOptions);
			$template->assign('HideVariationOptions', '');
		}
		else {
			$template->assign('HideVariationOptions', 'display: none');
		}

		$productFields = '';
		if(!empty($fieldsArray[$product['prodordprodid']])) {
			$fields = $fieldsArray[$product['prodordprodid']];
			foreach($fields as $field) {
				if(empty($field['textcontents']) && empty($field['filename'])) {
					continue;
				}

				$fieldValue = '-';
				$template->assign('FieldName', isc_html_escape($field['fieldname']));

				if($field['fieldtype'] == 'file') {
					$fieldValue = '<a href="'.GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/configured_products/'.urlencode($field['originalfilename']).'">'.isc_html_escape($field['originalfilename']).'</a>';
				}
				else {
					$fieldValue = isc_html_escape($field['textcontents']);
				}

				$template->assign('FieldValue', $fieldValue);
				$productFields .= $template->getSnippet('PrintableInvoiceItemConfigurableField');
			}
		}
		$template->assign('ProductConfigurableFields', $productFields);
		if(!$productFields) {
			$template->assign('HideConfigurableFields', 'display: none');
		}
		else {
			$template->assign('HideConfigurableFields', '');
		}

		if($product['prodeventdatename']) {
			$template->assign('FieldName', isc_html_escape($product['prodeventdatename']));
			$template->assign('FieldValue', isc_date('dS M Y', $product['prodeventdate']));
			$template->assign('ProductEventDate', $template->getSnippet('PrintableInvoiceItemConfigurableField'));
			$template->assign('HideEventDate', '');
		}
		else {
			$template->assign('ProductEventDate', '');
			$template->assign('HideEventDate', 'display: none');
		}

		$productsTable .= $template->GetSnippet('PrintablePackingSlipItem');
	}
	$template->assign('ProductsTable', $productsTable);
	$template->setTemplate('packing_slip_print');
	return $template->parseTemplate(true);
}