/** * Show the details of an order and allow them to print an invoice */ private function ViewOrderDetails() { $GLOBALS['SNIPPETS']['AccountOrderItemRow'] = ""; $count = 0; if (!isset($_GET['order_id']) || !is_numeric($_GET['order_id'])) { redirect('account.php?action=view_orders'); } $GLOBALS['FlassMessage'] = GetFlashMessageBoxes(); // Retrieve the completed order that matches the customers user id $orderId = (int)$_GET['order_id']; $GLOBALS['OrderId'] = $orderId; $customerId = getClass('ISC_CUSTOMER')->getcustomerId(); $query = " SELECT *, ( SELECT CONCAT(custconfirstname, ' ', custconlastname) FROM [|PREFIX|]customers WHERE customerid=ordcustid ) AS custname, ( SELECT statusdesc FROM [|PREFIX|]order_status WHERE statusid=ordstatus ) AS ordstatustext FROM [|PREFIX|]orders WHERE ordcustid='".(int)$customerId."' AND orderid='".(int)$orderId."' AND deleted = 0 "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); $row = $GLOBALS['ISC_CLASS_DB']->fetch($result); if(!$row) { redirect('account.php?action=view_orders'); } $GLOBALS['DisableReturnButton'] = ""; if (!gzte11(ISC_LARGEPRINT)) { $GLBOALS['DisableReturnButton'] = "none"; } $order = $row; // Fetch the shipping addresses for this order $addresses = array(); $query = " SELECT * FROM [|PREFIX|]order_addresses WHERE order_id='".$order['orderid']."' "; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($address = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $addresses[$address['id']] = $address; } // Fetch the shipping details for the order $query = " SELECT * FROM [|PREFIX|]order_shipping WHERE order_id=".$order['orderid']; $result = $GLOBALS['ISC_CLASS_DB']->query($query); while($shipping = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $addresses[$shipping['order_address_id']]['shipping'] = $shipping; } $GLOBALS['OrderComments'] = ''; if($row['ordcustmessage'] != '') { $GLOBALS['OrderComments'] = nl2br(isc_html_escape($row['ordcustmessage'])); } else { $GLOBALS['HideOrderComments'] = 'display: none'; } if(OrderIsComplete($row['ordstatus'])) { if (!gzte11(ISC_LARGEPRINT)) { $GLOBALS['DisableReturnButton'] = "none"; } if ($row['ordstatus'] == 4 || GetConfig('EnableReturns') == 0) { $GLOBALS['DisableReturnButton'] = "none"; } $GLOBALS['HideOrderStatus'] = "none"; $orderComplete = true; } else { $GLOBALS['HideOrderStatus'] = ''; $GLOBALS['OrderStatus'] = $row['ordstatustext']; $GLOBALS['DisableReturnButton'] = "none"; $orderComplete = false; } // Hide print order invoive if it's a incomplete order $GLOBALS['ShowOrderActions'] = ''; if(!$row['ordstatus']) { $GLOBALS['ShowOrderActions'] = 'display:none'; } $GLOBALS['OrderDate'] = isc_date(GetConfig('ExtendedDisplayDateFormat'), $row['orddate']); $GLOBALS['OrderTotal'] = CurrencyConvertFormatPrice($row['total_inc_tax'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true); // Format the billing address $GLOBALS['ShipFullName'] = isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname']); $GLOBALS['ShipCompany'] = ''; if($row['ordbillcompany']) { $GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($row['ordbillcompany']); } $GLOBALS['ShipAddressLines'] = isc_html_escape($row['ordbillstreet1']); if ($row['ordbillstreet2'] != "") { $GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($row['ordbillstreet2']); } $GLOBALS['ShipSuburb'] = isc_html_escape($row['ordbillsuburb']); $GLOBALS['ShipState'] = isc_html_escape($row['ordbillstate']); $GLOBALS['ShipZip'] = isc_html_escape($row['ordbillzip']); $GLOBALS['ShipCountry'] = isc_html_escape($row['ordbillcountry']); $GLOBALS['ShipPhone'] = ""; $GLOBALS['BillingAddress'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AddressLabel"); // Is there a shipping address, or is it a digital download? if ($order['ordisdigital']) { $GLOBALS['HideSingleShippingAddress'] = 'display: none'; } else if ($order['shipping_address_count'] > 1) { $GLOBALS['ShippingAddress'] = GetLang('OrderWillBeShippedToMultipleAddresses'); $GLOBALS['HideItemDetailsHeader'] = 'display:none;'; } else { $shippingAddress = current($addresses); $GLOBALS['ShipFullName'] = isc_html_escape($shippingAddress['first_name'].' '.$shippingAddress['last_name']); $GLOBALS['ShipCompany'] = ''; if($shippingAddress['company']) { $GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($shippingAddress['company']); } $GLOBALS['ShipAddressLines'] = isc_html_escape($shippingAddress['address_1']); if ($shippingAddress['address_2'] != "") { $GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($shippingAddress['address_2']); } $GLOBALS['ShipSuburb'] = isc_html_escape($shippingAddress['city']); $GLOBALS['ShipState'] = isc_html_escape($shippingAddress['state']); $GLOBALS['ShipZip'] = isc_html_escape($shippingAddress['zip']); $GLOBALS['ShipCountry'] = isc_html_escape($shippingAddress['country']); $GLOBALS['ShipPhone'] = ""; $GLOBALS['ShippingAddress'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AddressLabel"); } $itemTotalColumn = 'total_ex_tax'; if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) { $itemTotalColumn = 'total_inc_tax'; } $GLOBALS['OrderTotalRows'] = ''; $totalRows = getOrderTotalRows($order); foreach($totalRows as $id => $totalRow) { $GLOBALS['ISC_CLASS_TEMPLATE']->assign('label', $totalRow['label']); $GLOBALS['ISC_CLASS_TEMPLATE']->assign('classNameAppend', ucfirst($id)); $value = currencyConvertFormatPrice( $totalRow['value'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'] ); $GLOBALS['ISC_CLASS_TEMPLATE']->assign('value', $value); $GLOBALS['OrderTotalRows'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->getSnippet('AccountOrderTotalRow'); } $OrderProducts = array(); $ProductIds = array(); // Load up the items in this order $query = " SELECT o.*, op.*, oa.address_1, oa.address_2, oa.city, oa.zip, oa.country, oa.state, p.productid, p.prodpreorder, p.prodreleasedate, p.prodpreordermessage FROM [|PREFIX|]orders o LEFT JOIN [|PREFIX|]order_products op ON op.orderorderid LEFT JOIN [|PREFIX|]products p ON p.productid = op.ordprodid LEFT JOIN [|PREFIX|]order_addresses oa ON oa.`id` = op.order_address_id WHERE orderorderid = " . (int)$order['orderid'] ." ORDER BY op.order_address_id"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); //check if products are reorderable while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $OrderProducts[$row['orderprodid']] = $row; $ProductIds[] = $row['ordprodid']; } $UnreorderableProducts = $this->GetUnreorderableProducts($OrderProducts, $ProductIds); // for grouping of shipping addresses in template output $previousAddressId = null; $destinationCounter = 0; foreach ($OrderProducts as $row) { if ($count++ % 2 != 0) { $GLOBALS['ItemClass'] = "OrderItem2"; } else { $GLOBALS['ItemClass'] = "OrderItem1"; } $GLOBALS['OrderProductId'] = $row['orderprodid']; $GLOBALS['DisableReorder'] = ''; $GLOBALS['ReorderMessage'] = ""; $GLOBALS['HideItemMessage'] = 'display:none;'; if(isset($UnreorderableProducts[$row['orderprodid']])) { $GLOBALS['DisableReorder'] = 'Disabled'; $GLOBALS['ReorderMessage'] = $UnreorderableProducts[$row['orderprodid']]; if(isset($_REQUEST['reorder']) && $_REQUEST['reorder']==1) { $GLOBALS['HideItemMessage'] = ''; } } $GLOBALS['Qty'] = (int) $row['ordprodqty']; $GLOBALS['Name'] = isc_html_escape($row['ordprodname']); $GLOBALS['EventDate'] = ''; if ($row['ordprodeventdate'] != 0) { $GLOBALS['EventDate'] = $row['ordprodeventname'] . ': '. isc_date('M jS Y', $row['ordprodeventdate']); } // Does the product still exist or has it been deleted? $prod_name = GetProdNameById($row['ordprodid']); if ($prod_name == "" && $row['ordprodtype'] == 'giftcertificate') { $GLOBALS['Link'] = "javascript:product_giftcertificate()"; $GLOBALS['Target'] = ""; }else if ($prod_name == "") { $GLOBALS['Link'] = "javascript:product_removed()"; $GLOBALS['Target'] = ""; } else { $GLOBALS['Link'] = ProdLink(GetProdNameById($row['ordprodid'])); $GLOBALS['Target'] = "_blank"; } $GLOBALS['DownloadsLink'] = ''; if ($row['ordprodtype'] == "digital" && $orderComplete) { $GLOBALS['DownloadItemEncrypted'] = $this->EncryptDownloadKey($row['orderprodid'], $row['ordprodid'], $row['orderorderid'], $row['ordtoken']); $GLOBALS['DownloadsLink'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AccountOrderItemDownloadLink"); } $GLOBALS['Refunded'] = ''; $GLOBALS['StrikeEnd'] = ''; $GLOBALS['StrikeStart'] = ''; if ($row['ordprodrefunded'] > 0) { if ($row['ordprodrefunded'] == $row['ordprodqty']) { $GLOBALS['StrikeStart'] = "<s>"; $GLOBALS['StrikeEnd'] = "</s>"; $GLOBALS['Refunded'] = '<span class="Refunded">'.GetLang('OrderProductRefunded').'</span>'; } else { $GLOBALS['Refunded'] = '<span class="Refunded">'.sprintf(GetLang('OrderProductsRefundedX'), $row['ordprodrefunded']).'</span>'; } } $GLOBALS['Price'] = CurrencyConvertFormatPrice( $row[$itemTotalColumn], $order['ordcurrencyid'], $order['ordcurrencyexchangerate'] ); // Were there one or more options selected? $GLOBALS['ProductOptions'] = ''; if($row['ordprodoptions'] != '') { $options = @unserialize($row['ordprodoptions']); if(!empty($options)) { $GLOBALS['ProductOptions'] = "<br /><small class='OrderItemOptions'>("; $comma = ''; foreach($options as $name => $value) { $GLOBALS['ProductOptions'] .= $comma.isc_html_escape($name).": ".isc_html_escape($value); $comma = ', '; } $GLOBALS['ProductOptions'] .= ")</small>"; } } if($row['ordprodwrapname']) { $GLOBALS['GiftWrappingName'] = isc_html_escape($row['ordprodwrapname']); $GLOBALS['HideWrappingOptions'] = ''; } else { $GLOBALS['GiftWrappingName'] = ''; $GLOBALS['HideWrappingOptions'] = 'display: none'; } $GLOBALS['HideExpectedReleaseDate'] = 'display:none;'; $GLOBALS['ExpectedReleaseDate'] = ''; if ($row['prodpreorder']) { if ($row['prodreleasedate']) { $message = $row['prodpreordermessage']; if (!$message) { $message = GetConfig('DefaultPreOrderMessage'); } $GLOBALS['ExpectedReleaseDate'] = '(' . str_replace('%%DATE%%', isc_date(GetConfig('DisplayDateFormat'), $row['prodreleasedate']), $message) . ')'; } else { $GLOBALS['ExpectedReleaseDate'] = '(' . GetLang('PreOrderProduct') . ')'; } $GLOBALS['HideExpectedReleaseDate'] = ''; } $GLOBALS['ItemShippingRow'] = ''; if ($order['shipping_address_count'] > 1 && ($previousAddressId != $row['order_address_id'])) { $destinationCounter++; $GLOBALS['Destination_Number'] = GetLang('Destination_Number', array('number' => $destinationCounter)); $addressLine = array_filter(array( $row['address_1'], $row['address_2'], $row['city'], $row['state'], $row['zip'], $row['country'], )); $GLOBALS['ItemShippingRow_AddressLine'] = Store_String::rightTruncate(implode(', ', $addressLine), 60); $GLOBALS['ItemShippingRow'] = $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet('AccountOrderItemShippingRow'); } $GLOBALS['SNIPPETS']['AccountOrderItemRow'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("AccountOrderItemRow"); $previousAddressId = $row['order_address_id']; } $GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(sprintf("%s - %s%d", GetConfig('StoreName'), GetLang('OrderIdHash'), $orderId)); $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("account_order"); $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(); }
/** * Email the invoice from an order to a customer * * @param int The ID of the order to email the invoice for. * @param int The optional ID of the order status. Will default to the already stored status ID of the order */ function EmailInvoiceToCustomer($orderId, $newStatusId=null) { // Load the details for this order $order_row = GetOrder($orderId, true); if($order_row === false) { return false; } // All prices in the emailed invoices will be shown in the default currency of the store $defaultCurrency = GetDefaultCurrency(); $GLOBALS['OrderNumber'] = $orderId; if (isId($newStatusId)) { $order_status = $newStatusId; } else { $order_status = $order_row['ordstatus']; } $order_payment_module = $order_row['orderpaymentmodule']; if($order_row['ordcustid'] > 0) { $GLOBALS['ViewOrderStatusMsg'] = GetLang('ASummaryIsShownBelow')." <a href='".$GLOBALS['ShopPath']."/orderstatus.php'>".GetLang('ClickHere')."</a>."; } else { $GLOBALS['ViewOrderStatusMsg'] = ""; } $emailTemplate = FetchEmailTemplateParser(); if ($order_row['shipping_address_count'] > 1) { // multiple shipping addresses $GLOBALS['ShippingAddress'] = GetLang('OrderWillBeShippedToMultipleAddresses'); } else if ($order_row['shipping_address_count'] == 0) { // no shipping addresses (digital order) $GLOBALS['ShippingAddress'] = GetLang('ShippingImmediateDownload'); } else { // single shipping address $address = $GLOBALS['ISC_CLASS_DB']->FetchRow(" SELECT oa.* FROM `[|PREFIX|]order_addresses` oa WHERE oa.order_id = " . (int)$order_row['orderid'] . " "); $GLOBALS['ShipFullName'] = isc_html_escape($address['first_name'].' '.$address['last_name']); $GLOBALS['ShipCompany'] = ''; if($address['company']) { $GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($address['company']); } $GLOBALS['ShipAddressLines'] = isc_html_escape($address['address_1']); if ($address['address_2'] != "") { $GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($address['address_2']); } $GLOBALS['ShipSuburb'] = isc_html_escape($address['city']); $GLOBALS['ShipState'] = isc_html_escape($address['state']); $GLOBALS['ShipZip'] = isc_html_escape($address['zip']); $GLOBALS['ShipCountry'] = isc_html_escape($address['country']); $GLOBALS['ShipPhone'] = isc_html_escape($address['phone']); // show shipping email, if any if(!$address['email']) { $GLOBALS['HideShippingEmail'] = 'display: none'; } else { $GLOBALS['ShippingEmail'] = $address['email']; } $GLOBALS['ShippingAddress'] = $emailTemplate->GetSnippet("AddressLabel"); } // Format the billing address $GLOBALS['ShipFullName'] = isc_html_escape($order_row['ordbillfirstname'].' '.$order_row['ordbilllastname']); $GLOBALS['ShipCompany'] = ''; if($order_row['ordbillcompany']) { $GLOBALS['ShipCompany'] = '<br />'.isc_html_escape($order_row['ordbillcompany']); } $GLOBALS['ShipAddressLines'] = isc_html_escape($order_row['ordbillstreet1']); if ($order_row['ordbillstreet2'] != "") { $GLOBALS['ShipAddressLines'] .= '<br />' . isc_html_escape($order_row['ordbillstreet2']); } $GLOBALS['ShipSuburb'] = isc_html_escape($order_row['ordbillsuburb']); $GLOBALS['ShipState'] = isc_html_escape($order_row['ordbillstate']); $GLOBALS['ShipZip'] = isc_html_escape($order_row['ordbillzip']); $GLOBALS['ShipCountry'] = isc_html_escape($order_row['ordbillcountry']); $GLOBALS['ShipPhone'] = isc_html_escape($order_row['ordbillphone']); // show billing email, if any if(!$order_row['ordbillemail']) { $GLOBALS['HideBillingEmail'] = 'display: none'; } else { $GLOBALS['BillingEmail'] = $order_row['ordbillemail']; } $GLOBALS['BillingAddress'] = $emailTemplate->GetSnippet("AddressLabel"); // Format the shipping provider's details $shippingCostColumn = 'cost_ex_tax'; $itemPriceColumn = 'price_ex_tax'; $itemTotalColumn = 'total_ex_tax'; $subTotalColumn = 'subtotal_ex_tax'; if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) { $shippingCostColumn = 'cost_inc_tax'; $itemPriceColumn = 'price_inc_tax'; $itemTotalColumn = 'total_inc_tax'; $subTotalColumn = 'subtotal_inc_tax'; } $GLOBALS['TotalCost'] = FormatPrice($order_row['total_inc_tax'], false, true, false, $defaultCurrency, true); $email = $order_row['ordbillemail']; if(!$order_row['ordbillemail']) { // Get the customer's email address $query = sprintf("select custconemail from [|PREFIX|]customers where customerid='%d'", $GLOBALS['ISC_CLASS_DB']->Quote($order_row['ordcustid'])); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $email = $row['custconemail']; } } if(!$email) { return false; } $prodHasSKU = false; $WrapCost = 0; $fieldArray = GetOrderProductFieldsData($orderId); // We need to loop throuh all the prodcts to see if any of them have an SKU foreach($order_row['products'] as $product_row) { if (trim($product_row['ordprodsku']) !== '') { $prodHasSKU = true; } } // OK, now set the proper columns for the product list if ($prodHasSKU) { $GLOBALS['CartItemColumns'] = $emailTemplate->GetSnippet("InvoiceProductColumns"); } else { $GLOBALS['CartItemColumns'] = $emailTemplate->GetSnippet("InvoiceProductColumnsNoSKU"); } $GLOBALS['SNIPPETS']['CartItems'] = ''; $previousAddressId = null; foreach($order_row['products'] as $product_row) { if ($order_row['shipping_address_count'] > 1 && $product_row['order_address_id'] != $previousAddressId) { if ($product_row['order_address_id']) { $addressLine = array_filter(array( $product_row['address_1'], $product_row['address_2'], $product_row['city'], $product_row['state'], $product_row['zip'], $product_row['country'], )); $addressLine = GetLang('ItemsShippedTo') . ' ' . Store_String::rightTruncate(implode(', ', $addressLine), 70); } else { $addressLine = GetLang('ItemsShippedToDigital'); } $GLOBALS['AddressLine'] = $addressLine; $GLOBALS['SNIPPETS']['CartItems'] .= $emailTemplate->GetSnippet("InvoiceProductShipRow"); $previousAddressId = $product_row['order_address_id']; } $pOptions = ''; if($product_row['ordprodoptions'] != '') { $options = @unserialize($product_row['ordprodoptions']); if(!empty($options)) { $pOptions = "<br /><small>("; $comma = ''; foreach($options as $name => $value) { $pOptions .= $comma.isc_html_escape($name).": ".isc_html_escape($value); $comma = ', '; } $pOptions .= ")</small>"; } } $GLOBALS['ProductOptions'] = $pOptions; $GLOBALS['EventDate'] = ''; if ($product_row['ordprodeventdate']) { $GLOBALS['EventDate'] = '<br /><span style="padding-left : 10px; padding-bottom:10px; font-size:11px; font-style:italic">('.$product_row['ordprodeventname'] . ': ' . isc_date('dS M Y', $product_row['ordprodeventdate']) . ')</span>'; } $GLOBALS['ProductPrice'] = FormatPrice($product_row[$itemPriceColumn], false, true, false, $defaultCurrency, true); $GLOBALS['ProductTotal'] = FormatPrice($product_row[$itemTotalColumn], false, true, false, $defaultCurrency, true); $GLOBALS['ProductQuantity'] = $product_row['ordprodqty']; $GLOBALS['ProductName'] = isc_html_escape($product_row['ordprodname']); $GLOBALS['ProductSku'] = ' '; if ($prodHasSKU && trim($product_row['ordprodsku']) !== '') { $GLOBALS['ProductSku'] = isc_html_escape($product_row['ordprodsku']); } // If this is a digital download and the order is complete, append a download link to the name of the product if($product_row['ordprodtype'] == 'digital' && OrderIsComplete($order_status)) { $GLOBALS['ISC_CLASS_ACCOUNT'] = GetClass('ISC_ACCOUNT'); $downloadEncrypted = $GLOBALS['ISC_CLASS_ACCOUNT']->EncryptDownloadKey($product_row['orderprodid'], $product_row['ordprodid'], $orderId, $order_row['ordtoken']); $downloadLink = $GLOBALS['ShopPathSSL'].'/account.php?action=download_item&data=' . $downloadEncrypted; $GLOBALS['ProductName'] .= ' (<a href="'.$downloadLink.'">'.GetLang('DownloadLink').'</a>)'; } $GLOBALS['CartProductFields'] = ''; if(isset($fieldArray[$product_row['orderprodid']])) { $GLOBALS['CartProductFields'] = LoadEmailOrderProductFields($fieldArray[$product_row['orderprodid']]); } if(isset($product_row['ordprodwrapcost'])) { $WrapCost += $product_row['ordprodwrapcost']; } $GLOBALS['ExpectedReleaseDate'] = ''; if ($product_row['prodpreorder']) { if ($product_row['prodreleasedate']) { $message = $product_row['prodpreordermessage']; if (!$message) { $message = GetConfig('DefaultPreOrderMessage'); } $GLOBALS['ExpectedReleaseDate'] = '(' . str_replace('%%DATE%%', isc_date(GetConfig('DisplayDateFormat'), $product_row['prodreleasedate']), $message) . ')'; } else { $GLOBALS['ExpectedReleaseDate'] = '(' . GetLang('PreOrderProduct') . ')'; } } if ($prodHasSKU) { $GLOBALS['SNIPPETS']['CartItems'] .= $emailTemplate->GetSnippet("InvoiceCartItem"); } else { $GLOBALS['SNIPPETS']['CartItems'] .= $emailTemplate->GetSnippet("InvoiceCartItemNoSKU"); } } $totalRows = getOrderTotalRows($order_row); $GLOBALS['SNIPPETS']['TotalRows'] = ''; foreach($totalRows as $row) { $emailTemplate->assign('label', isc_html_escape($row['label'])); $emailTemplate->assign('value', formatPrice($row['value'], false, true, false, $defaultCurrency, true)); $GLOBALS['SNIPPETS']['TotalRows'] .= $emailTemplate->getSnippet('InvoiceTotalRow'); } // Set the shipping method if ($order_row['ordisdigital']) { $GLOBALS['ShippingMethod'] = GetLang('ImmediateDownload'); } else { $GLOBALS['ShippingMethod'] = sprintf(GetLang('FreeShippingFromX'), $GLOBALS['StoreName']); } // What's the status of the order? If it's awaiting payment (7) then show the awaiting payment notice if ($order_status == 7) { // Get the awaiting payment snippet, for offline payment providers also show the "how to pay for your order" message" $checkout_provider = null; GetModuleById('checkout', $checkout_provider, $order_payment_module); if (is_object($checkout_provider) && $checkout_provider->getpaymenttype() == PAYMENT_PROVIDER_OFFLINE && method_exists($checkout_provider, 'GetOfflinePaymentMessage')) { $paymentData = array( 'orders' => array($order_row['orderid'] => $order_row) ); $checkout_provider->SetOrderData($paymentData); $GLOBALS['PaymentGatewayAmount'] = CurrencyConvertFormatPrice($order_row['total_inc_tax'], $order_row['ordcurrencyid'], $order_row['ordcurrencyexchangerate'], true); $GLOBALS['PaymentMessage'] = $checkout_provider->GetOfflinePaymentMessage(); $GLOBALS['PendingPaymentDetails'] = $emailTemplate->GetSnippet("InvoicePendingPaymentDetails"); $GLOBALS['PendingPaymentNotice'] = $emailTemplate->GetSnippet("InvoicePendingPaymentNotice"); } } $GLOBALS['OrderCommentBlock'] = ''; if($order_row['ordcustmessage'] != '') { $GLOBALS['OrderComments'] = isc_html_escape($order_row['ordcustmessage']); $GLOBALS['OrderCommentBlock'] = $emailTemplate->GetSnippet("InvoiceOrderComment"); } $emailTemplate->SetTemplate("invoice_email"); $message = $emailTemplate->ParseTemplate(true); // Create a new email API object to send the email $store_name = GetConfig('StoreName'); $obj_email = GetEmailClass(); $obj_email->From(GetConfig('OrderEmail'), $store_name); $obj_email->Set("Subject", sprintf(GetLang('YourOrderFrom'), $store_name)); $obj_email->AddBody("html", $message); $obj_email->AddRecipient($email, "", "h"); $email_result = $obj_email->Send(); $forwardEmails = array(); if($order_row['ordvendorid'] > 0) { $query = " SELECT vendororderemail FROM [|PREFIX|]vendors WHERE vendorid='".(int)$order_row['ordvendorid']."' "; $vendorOrderEmails = $GLOBALS['ISC_CLASS_DB']->FetchOne($query); $forwardEmails = array_merge($forwardEmails, explode(',', $vendorOrderEmails)); } // If there are any additional recipients (forward invoices to addresses), send them as well if(GetConfig('ForwardInvoiceEmails')) { $forwardEmails = array_merge($forwardEmails, explode(',', GetConfig('ForwardInvoiceEmails'))); } $forwardEmails = array_unique($forwardEmails); foreach($forwardEmails as $address) { if(!trim($address)) { continue; } $emailClass = GetEmailClass(); $emailClass->Set('CharSet', GetConfig('CharacterSet')); $emailClass->From(GetConfig('OrderEmail'), $store_name); $emailClass->Set("Subject", "Fwd: ".sprintf(GetLang('YourOrderFrom'), $store_name)." (#".$order_row['orderid'].")"); $emailClass->AddBody("html", $message); $emailClass->AddRecipient($address, "", "h"); $status = $emailClass->Send(); } // If the email was sent ok, show a confirmation message if ($email_result['success']) { return true; } else { // Email error return false; } }
/** * Generate a single printable invoice. * @param int * @return strong The generated printable invoice (HTML) */ function generatePrintableInvoice($orderId) { $db = $GLOBALS['ISC_CLASS_DB']; $template = TEMPLATE::GetInstance(); $template->assign('StoreAddressFormatted', nl2br(getConfig('StoreAddress'))); // allow access to deleted orders if printing from within control panel $isAdmin = (defined('ISC_ADMIN_CP') && ISC_ADMIN_CP); $query = " SELECT o.*, CONCAT(c.custconfirstname, ' ', c.custconlastname) AS ordcustname, c.custconemail AS ordcustemail, c.custconphone AS ordcustphone FROM [|PREFIX|]orders o LEFT JOIN [|PREFIX|]customers c ON o.ordcustid = c.customerid WHERE o.orderid = '".(int)$orderId."' "; if (!$isAdmin) { $query .= " AND o.deleted = 0 "; } $result = $db->Query($query); $row = $db->Fetch($result); $order = $row; if(!$row) { return false; } $template->assign('OrderId', $row['orderid']); $template->assign('OrderDate', cDate($row['orddate'])); if($row['ordcustmessage']) { $template->assign('Comments', nl2br(isc_html_escape($row['ordcustmessage']))); $template->assign('HideComments', ''); } else { $template->assign('Comments', ''); $template->assign('HideComments', 'display: none'); } $template->assign('InvoiceTitle', sprintf(getLang('InvoiceTitle'), $orderId)); $showShipping = true; $template->assign('totalRowColspan', 4); $template->assign('hideAddressColumn', 'display: none'); if($row['shipping_address_count'] > 1) { $showShipping = false; $template->assign('totalRowColspan', 5); $template->assign('hideAddressColumn', ''); $template->assign('hideInvoiceShippingDetails', 'display: none'); } else if($row['ordisdigital']) { $template->assign('hideInvoiceShippingDetails', 'display: none'); $showShipping = false; } $totalRows = getOrderTotalRows($row, $showShipping); $templateTotalRows = ''; foreach($totalRows as $id => $totalRow) { $template->assign('label', $totalRow['label']); $template->assign('classNameAppend', ucfirst($id)); $value = currencyConvertFormatPrice( $totalRow['value'], $row['ordcurrencyid'], $row['ordcurrencyexchangerate'], true ); $template->assign('value', $value); $templateTotalRows .= $template->getSnippet('PrintableInvoiceTotalRow'); } $template->assign('totals', $templateTotalRows); // Fetch shipping addresses in this order $addresses = array(); $query = " SELECT * FROM [|PREFIX|]order_addresses WHERE order_id='".(int)$orderId."' ORDER BY `id` "; $result = $db->query($query); while($address = $db->fetch($result)) { $addresses[$address['id']] = $address; } // Fetch shippng details $query = " SELECT * FROM [|PREFIX|]order_shipping WHERE order_id='".(int)$orderId."' ORDER BY order_address_id "; $result = $db->query($query); while($shipping = $db->fetch($result)) { $addresses[$shipping['order_address_id']]['shipping'] = $shipping; } // Order has a single shipping address if($row['shipping_address_count'] == 1) { $address = current($addresses); $template->assign('ShippingAddress', getInvoiceShippingAddressBlock($address)); $template->assign('ShippingEmail', isc_html_escape($address['email'])); if(!$address['email']) { $template->assign('HideShippingEmail', 'display: none'); } $template->assign('ShippingMethod', isc_html_escape($address['shipping']['method'])); } // Format the customer details if($row['ordcustid'] == 0) { $template->assign('HideCustomerDetails', 'display: none'); } $template->assign('CustomerId', $row['ordcustid']); $template->assign('CustomerName', isc_html_escape($row['ordcustname'])); $template->assign('CustomerEmail', $row['ordcustemail']); $template->assign('CustomerPhone', $row['ordcustphone']); // Format the billing address $template->assign('ShipFullName', isc_html_escape($row['ordbillfirstname'].' '.$row['ordbilllastname'])); if($row['ordbillcompany']) { $template->assign('ShipCompany', '<br />'.isc_html_escape($row['ordbillcompany'])); } else { $template->assign('ShipCompany', ''); } $addressLine = isc_html_escape($row['ordbillstreet1']); if ($row['ordbillstreet2'] != "") { $addressLine .= '<br />' . isc_html_escape($row['ordbillstreet2']); } $template->assign('ShipAddressLines', $addressLine); $template->assign('ShipSuburb', isc_html_escape($row['ordbillsuburb'])); $template->assign('ShipState', isc_html_escape($row['ordbillstate'])); $template->assign('ShipZip', isc_html_escape($row['ordbillzip'])); $template->assign('ShipCountry', isc_html_escape($row['ordbillcountry'])); $template->assign('BillingAddress', $template->getSnippet('AddressLabel')); $template->assign('BillingPhone', isc_html_escape($row['ordbillphone'])); if(!$row['ordbillphone']) { $template->assign('HideBillingPhone', 'display: none'); } $template->assign('BillingEmail', isc_html_escape($row['ordbillemail'])); if(!$row['ordbillemail']) { $template->assign('HideBillingEmail', 'display: none'); } // Set the payment method $paymentMethod = $row['orderpaymentmethod']; if($row['orderpaymentmethod'] == '') { $paymentMethod = getLang('NA'); } if($row['orderpaymentmethod'] != 'storecredit' && $row['orderpaymentmethod'] != 'giftcertificate') { $paymentMethod .= " (". formatPriceInCurrency($row['total_inc_tax'], $row['orddefaultcurrencyid']).")"; } $template->assign('PaymentMethod', $paymentMethod); // Get the products in the order $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)$orderId." ORDER BY p.fieldsortorder ASC "; $result = $db->Query($query); $fields = array(); while ($row = $db->Fetch($result)) { $fieldsArray[$row['ordprodid']][] = $row; } $query = " SELECT op.*, p.productid, p.prodpreorder, p.prodreleasedate, p.prodpreordermessage FROM [|PREFIX|]order_products op LEFT JOIN [|PREFIX|]products p ON p.productid = op.ordprodid WHERE op.orderorderid='".(int)$orderId."' ORDER BY op.order_address_id "; $result = $db->query($query); $productsTable = ''; $lastAddressId = -1; $shippingCostColumn = 'cost_ex_tax'; $itemPriceColumn = 'price_ex_tax'; $itemTotalColumn = 'total_ex_tax'; if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) { $shippingCostColumn = 'cost_inc_tax'; $itemPriceColumn = 'price_inc_tax'; $itemTotalColumn = 'total_inc_tax'; } $addressProducts = array(); while($product = $db->fetch($result)) { if(!isset($addressProducts[$product['order_address_id']])) { $addressProducts[$product['order_address_id']] = array(); } $addressProducts[$product['order_address_id']][] = $product; } foreach($addressProducts as $addressId => $products) { $numProducts = count($products); if(!isset($addresses[$addressId])) { $template->assign('productShippingAddress', getLang('NA')); } else { $address = $addresses[$addressId]; $template->assign('productShippingAddress', getInvoiceShippingAddressBlock($address)); } $template->assign('addressColumnRowSpan', $numProducts); if($order['shipping_address_count'] > 1) { $template->assign('hideAddressColumn', ''); $template->assign('invoiceItemClass', 'InvoiceItemDivider'); } foreach($products as $product) { $template->assign('ProductName', isc_html_escape($product['ordprodname'])); if($product['ordprodsku']) { $template->assign('ProductSku', isc_html_escape($product['ordprodsku'])); } else { $template->assign('ProductSku', getLang('NA')); } $template->assign('ProductQuantity', $product['ordprodqty']); $pOptions = ''; if($product['ordprodoptions'] != '') { $options = @unserialize($product['ordprodoptions']); 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['orderprodid']])) { $fields = $fieldsArray[$product['orderprodid']]; 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', ''); } $template->assign('ProductCost', currencyConvertFormatPrice( $product[$itemPriceColumn], $order['ordcurrencyid'], $order['ordcurrencyexchangerate'], true) ); $template->assign('ProductTotalCost', currencyConvertFormatPrice( $product[$itemTotalColumn], $order['ordcurrencyid'], $order['ordcurrencyexchangerate'], true) ); if($product['ordprodwrapname']) { $template->assign('FieldName', getLang('GiftWrapping')); $template->assign('FieldValue', isc_html_escape($product['ordprodwrapname'])); $template->assign('ProductGiftWrapping', $template->getSnippet('PrintableInvoiceItemConfigurableField')); $template->assign('HideGiftWrapping', ''); } else { $template->assign('ProductGiftWrapping', ''); $template->assign('HideGiftWrapping', 'display: none'); } if($product['ordprodeventdate']) { $template->assign('FieldName', isc_html_escape($product['ordprodeventname'])); $template->assign('FieldValue', isc_date('dS M Y', $product['ordprodeventdate'])); $template->assign('ProductEventDate', $template->getSnippet('PrintableInvoiceItemConfigurableField')); $template->assign('HideEventDate', ''); } else { $template->assign('ProductEventDate', ''); $template->assign('HideEventDate', 'display: none'); } // determine preorder status $template->Assign('HidePreOrder', ''); $template->Assign('ProductPreOrder', ''); if ($product['productid'] && $product['prodpreorder']) { // product is pre-order because it exists in current db with preorder status if ($product['prodreleasedate']) { $message = $product['prodpreordermessage']; if (!$message) { $message = GetConfig('DefaultPreOrderMessage'); } $message = str_replace('%%DATE%%', isc_date(GetConfig('DisplayDateFormat'), $product['prodreleasedate']), $message); } else { $message = GetLang('PreOrderProduct'); } $template->Assign('ProductPreOrder', $message); } else { $template->Assign('HidePreOrder', 'display:none;'); } $productsTable .= $template->GetSnippet('PrintableInvoiceItem'); $template->assign('hideAddressColumn', 'display: none'); $template->assign('productShippingAddress', ''); $template->assign('addressColumnRowSpan', 1); $template->assign('invoiceItemClass', ''); } } if($order['shipping_address_count'] > 1) { $template->assign('hideAddressColumn', ''); } $template->assign('ProductsTable', $productsTable); return $template->GetSnippet('PrintableInvoice'); }
/** * Display the quick view for an order * * @return void **/ public function GetOrderQuickView() { $this->engine->loadLangFile('orders'); if(empty($_REQUEST['o'])) { exit; } $orderId = (int)$_REQUEST['o']; // Get the details for this order from the database $query = " SELECT o.*, CONCAT(custconfirstname, ' ', custconlastname) AS custname, custconemail, custconphone, (SELECT COUNT(messageid) FROM [|PREFIX|]order_messages WHERE messageorderid=orderid AND messagestatus='unread') AS numunreadmessages FROM [|PREFIX|]orders o LEFT JOIN [|PREFIX|]customers c ON (c.customerid=o.ordcustid) WHERE o.orderid='".$GLOBALS['ISC_CLASS_DB']->Quote($orderId)."' "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); $order = $GLOBALS['ISC_CLASS_DB']->Fetch($result); $orderStatuses = array(); $query = " SELECT * FROM [|PREFIX|]order_status ORDER BY statusorder ASC "; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($status = $GLOBALS['ISC_CLASS_DB']->fetch($result)) { $orderStatuses[$status['statusid']] = $status['statusdesc']; } $this->template->assign('orderStatuses', $orderStatuses); // Order wasn't found if(!$order) { echo getLang('OrderDetailsNotFound'); exit; } // If this user is a vendor, do they have permission to acess this order? else if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && $row['ordvendorid'] != $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) { echo getLang('OrderDetailsNotFound'); exit; } $addressTypes = array( 'billingAddress' => 'ordbill', ); // Build the address fields foreach($addressTypes as $var => $dbKey) { $address = array( 'firstname' => $order[$dbKey.'firstname'], 'lastname' => $order[$dbKey.'lastname'], 'company' => $order[$dbKey.'company'], 'address1' => $order[$dbKey.'street1'], 'address2' => $order[$dbKey.'street2'], 'city' => $order[$dbKey.'suburb'], 'state' => $order[$dbKey.'state'], 'zip' => $order[$dbKey.'zip'], 'country' => $order[$dbKey.'country'] ); if($order[$dbKey.'countrycode'] && file_exists(ISC_BASE_PATH.'/lib/flags/'.strtolower($order[$dbKey.'countrycode']).'.gif')) { $address['countryFlag'] = strtolower($order[$dbKey.'countrycode']); } $this->template->assign($var, $address); } $itemTotalColumn = 'total_ex_tax'; $shippingCostColumn = 'cost_ex_tax'; if(getConfig('taxDefaultTaxDisplayOrders') == TAX_PRICES_DISPLAY_INCLUSIVE) { $itemTotalColumn = 'total_inc_tax'; $shippingCostColumn = 'cost_inc_tax'; } // Does the payment method have any extra info to show? $provider = null; if(GetModuleById('checkout', $provider, $order['orderpaymentmodule'])) { if(method_exists($provider, "DisplayPaymentDetails")) { $this->template->assign('orderExtraInfo', $provider->DisplayPaymentDetails($order)); } } if($order['extrainfo']) { $extraArray = unserialize($order['extrainfo']); if(!empty($extraArray['payment_message'])) { $order['payment_message'] = $extraArray['payment_message']; } } // Fetch all of the addresses in this order $orderAddresses = array(); $query = " SELECT * FROM [|PREFIX|]order_addresses WHERE order_id='".$order['orderid']."' "; $result = $this->db->query($query); while($address = $this->db->fetch($result)) { if($address['country_iso2'] && file_exists(ISC_BASE_PATH.'/lib/flags/'.strtolower($address['country_iso2']).'.gif')) { $address['countryFlag'] = strtolower($address['country_iso2']); } $orderAddresses[$address['id']] = array( 'address' => $address, 'shipping' => array(), 'products' => array(), ); // Grab any custom form fields if($address['form_session_id']) { $orderAddresses[$address['id']]['customFields'] = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData( $address['form_session_id'], array(), FORMFIELDS_FORM_SHIPPING, true ); } } // Fetch the shipping details for this order $query = " SELECT * FROM [|PREFIX|]order_shipping WHERE order_id='".$order['orderid']."' "; $result = $this->db->query($query); while($shipping = $this->db->fetch($result)) { $shipping['cost'] = $shipping[$shippingCostColumn]; $orderAddresses[$shipping['order_address_id']]['shipping'] = $shipping; } // Get the products in the order $prodFieldsArray = getClass('ISC_ADMIN_ORDERS')->getOrderProductFieldsData($orderId); // Get the products in the order $products = array(); $query = " SELECT o.*, p.productid, p.prodname, p.prodpreorder, p.prodreleasedate, p.prodpreordermessage FROM [|PREFIX|]order_products o LEFT JOIN [|PREFIX|]products p ON (p.productid=o.ordprodid) WHERE orderorderid='" . $orderId . "' ORDER BY ordprodname"; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while($product = $this->db->fetch($result)) { if($product['ordprodoptions'] != '') { $product['options'] = unserialize($product['ordprodoptions']); } if(isset($prodFieldsArray[$product['orderprodid']])) { $product['configurable_fields'] = $prodFieldsArray[$product['orderprodid']]; } if($product['prodname']) { $product['prodlink'] = prodLink($product['prodname']); } if($product['productid'] && $product['prodpreorder']) { $message = getLang('Thisisapreordereditem'); if($product['prodreleasedate']) { $message = $product['prodpreordermessage']; if(!$message) { $message = getConfig('DefaultPreOrderMessage'); } $message = str_replace('%%DATE%%', isc_date(getConfig('DisplayDateFormat'), $product['prodreleasedate']), $message); } $product['preorder_message'] = $message; } if($product['ordprodeventdate']) { $product['ordprodeventdate'] = isc_date('jS M Y', $product['ordprodeventdate']); } $product['total'] = $product[$itemTotalColumn]; $productAddressId = $product['order_address_id']; if(!isset($orderAddresses[$productAddressId])) { $orderAddresses[$productAddressId] = array( 'products' => array() ); } $orderAddresses[$productAddressId]['products'][] = $product; } $this->template->assign('orderAddresses', $orderAddresses); $this->template->assign('totalRows', getOrderTotalRows($order)); if (gzte11(ISC_MEDIUMPRINT) && isId($order['ordformsessionid'])) { $billingFields = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData( $order['ordformsessionid'], array(), FORMFIELDS_FORM_BILLING, true ); $this->template->assign('billingCustomFields', $billingFields); $shippingFields = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData( $order['ordformsessionid'], array(), FORMFIELDS_FORM_SHIPPING, true ); $this->template->assign('shippingCustomFields', $shippingFields); } $this->template->assign('order', $order); $this->template->assign('orderStatusOptions', getClass('ISC_ADMIN_ORDERS')->getOrderStatusOptions($order['ordstatus']) ); $message = ''; $flashMessages = GetFlashMessages(); if(is_array($flashMessages)) { foreach($flashMessages as $flashMessage) { $message .= MessageBox($flashMessage['message'], $flashMessage['type']); } } $this->template->assign('message', $message); $this->template->display('order.quickview.tpl'); }