Ejemplo n.º 1
0
 /**
  * Apply a coupon code or gift certificate code to the order that's being created/edited.
  */
 private function OrderApplyCouponCode()
 {
     if (!isset($_REQUEST['couponCode']) || !isset($_REQUEST['orderSession'])) {
         exit;
     }
     $orderClass = GetClass('ISC_ADMIN_ORDERS');
     $api = $orderClass->GetCartApi($_REQUEST['orderSession']);
     $response = array();
     $code = trim($_REQUEST['couponCode']);
     // If we were passed a gift certificate code, attempt to apply it first
     if (isc_strlen($code) == GIFT_CERTIFICATE_LENGTH && gzte11(ISC_LARGEPRINT)) {
         if (!$api->ApplyGiftCertificate($code)) {
             $errors = implode("\n", $api->GetErrors());
         }
     } elseif (!CheckExistsCouponCode($code) && CheckExistsCompanyGiftCertificateCode($code)) {
         if (!$api->ApplyCompanyGiftCertificate($code)) {
             $errors = implode("\n", $api->GetErrors());
         }
     } else {
         // Otherwise, it must be a coupon code
         if (!$api->ApplyCoupon($code)) {
             $errors = implode("\n", $api->GetErrors());
         } else {
             // If we've applied a coupon code, we need to refresh the entire grid of order items
             // as prices may have also changed.
             $response['orderTable'] = $orderClass->GenerateOrderItemsGrid();
         }
     }
     if (isset($errors)) {
         $response['error'] = $errors;
     }
     // Generate the order summary again
     $response['orderSummary'] = $orderClass->GenerateOrderSummaryTable();
     echo isc_json_encode($response);
     exit;
 }
Ejemplo n.º 2
0
 /**
  * Build the contents for the order confirmation page. This function sets up everything to be used by
  * the order confirmation on the express checkout page as well as the ConfirmOrder page when using a
  * multi step checkout.
  */
 public function BuildOrderConfirmation()
 {
     //alandy.check customer email.
     $GLOBALS['Hasemailflag2'] = "no";
     $sql = "select customerid from [|PREFIX|]customers where custconemail='" . $_SESSION['CHECKOUT']['account_email'] . "'";
     $query = $GLOBALS['ISC_CLASS_DB']->Query($sql);
     /*  2011-06-13 johnny remove ---- don't check email for guest
     		while($rs=$GLOBALS['ISC_CLASS_DB']->Fetch($query)){
     		    $GLOBALS['Hasemailflag2']="yes";
     		}
     		*/
     if ($_SESSION['Haslogin'] == 1) {
         $GLOBALS['Hasemailflag2'] = "no";
     }
     if (!GetConfig('ShowMailingListInvite')) {
         $GLOBALS['HideMailingListInvite'] = 'none';
     }
     // Do we need to show the special offers & discounts checkbox and should they
     // either of the newsletter checkboxes be ticked by default?
     if (GetConfig('MailAutomaticallyTickNewsletterBox')) {
         $GLOBALS['NewsletterBoxIsTicked'] = 'checked="checked"';
     }
     // Is Interspire Email Marketer integrated?
     if (GetConfig('MailXMLAPIValid') && GetConfig('UseMailerForOrders') && GetConfig('MailOrderList') > 0) {
         // Yes, should we tick the speical offers & discounts checkbox by default?
         if (GetConfig('MailAutomaticallyTickOrderBox')) {
             $GLOBALS['OrderBoxIsTicked'] = 'checked="checked"';
         }
     } else {
         $GLOBALS['HideOrderCheckBox'] = "none";
     }
     if (isset($_REQUEST['ordercomments'])) {
         $GLOBALS['OrderComments'] = $_REQUEST['ordercomments'];
     }
     // Now we check if we have an incoming coupon or gift certificate code to apply
     if (isset($_REQUEST['couponcode']) && $_REQUEST['couponcode'] != '') {
         $code = trim($_REQUEST['couponcode']);
         // Were we passed a gift certificate code?
         if (isc_strlen($code) == GIFT_CERTIFICATE_LENGTH && gzte11(ISC_LARGEPRINT)) {
             $cart = GetClass('ISC_CART');
             if ($cart->api->ApplyGiftCertificate($code)) {
                 // If successful show a message
                 $GLOBALS['CheckoutSuccessMsg'] = GetLang('GiftCertificateAppliedToCart');
             } else {
                 $GLOBALS['CheckoutErrorMsg'] = implode('<br />', $cart->api->GetErrors());
             }
         } elseif (!CheckExistsCouponCode($code) && CheckExistsCompanyGiftCertificateCode($code)) {
             $cart = GetClass('ISC_CART');
             if ($cart->api->ApplyCompanyGiftCertificate($code)) {
                 // If successful show a message
                 $GLOBALS['CheckoutSuccessMsg'] = GetLang('GiftCertificateAppliedToCart');
             } else {
                 $GLOBALS['CheckoutErrorMsg'] = implode('<br />', $cart->api->GetErrors());
             }
         } else {
             $cart = GetClass('ISC_CART');
             $GLOBALS['go'] = 1;
             # Baskaran
             if ($cart->api->ApplyCoupon($code)) {
                 $cart->api->ReapplyCouponsFromCart();
                 //Added by Simha temp fix to avoid having multiple times coupon for same item
                 $cart->api->UpdateCartInformation();
                 // Coupon code applied successfully
                 $GLOBALS['CheckoutSuccessMsg'] = GetLang('CouponAppliedToCart');
             } else {
                 $GLOBALS['CheckoutErrorMsg'] = implode('<br />', $cart->api->GetErrors());
             }
         }
     }
     $GLOBALS['ISC_CLASS_ACCOUNT'] = GetClass('ISC_ACCOUNT');
     // Determine what we'll be showing for the redeem gift certificate/coupon code box
     if (gzte11(ISC_LARGEPRINT)) {
         $GLOBALS['RedeemTitle'] = GetLang('RedeemGiftCertificateOrCoupon');
         $GLOBALS['RedeemIntro'] = GetLang('RedeemGiftCertificateorCouponIntro');
     } else {
         $GLOBALS['RedeemTitle'] = GetLang('RedeemCouponCode');
         $GLOBALS['RedeemIntro'] = GetLang('RedeemCouponCodeIntro');
     }
     $GLOBALS['HideCheckoutError'] = "none";
     $GLOBALS['HidePaymentOptions'] = "";
     $GLOBALS['HideUseCoupon'] = '';
     // if the provider list html is set in session then use it as the payment provider options.
     // it's normally set in payment modules when it's required.
     if (isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
         $GLOBALS['HidePaymentProviderList'] = "";
         $GLOBALS['HidePaymentOptions'] = "";
         $GLOBALS['PaymentProviders'] = $_SESSION['CHECKOUT']['ProviderListHTML'];
         $GLOBALS['StoreCreditPaymentProviders'] = $_SESSION['CHECKOUT']['ProviderListHTML'];
         $GLOBALS['CheckoutWith'] = "";
     } else {
         // Get a list of checkout providers
         $checkoutProviders = GetCheckoutModulesThatCustomerHasAccessTo(true);
         // If no checkout providers are set up, send an email to the store owner and show an error message
         if (empty($checkoutProviders)) {
             $GLOBALS['HideConfirmOrderPage'] = "none";
             $GLOBALS['HideCheckoutError'] = '';
             $GLOBALS['HideTopPaymentButton'] = "none";
             $GLOBALS['HidePaymentProviderList'] = "none";
             $GLOBALS['CheckoutErrorMsg'] = GetLang('NoCheckoutProviders');
             $GLOBALS['NoCheckoutProvidersError'] = sprintf(GetLang("NoCheckoutProvidersErrorLong"), $GLOBALS['ShopPath']);
             $GLOBALS['EmailHeader'] = GetLang("NoCheckoutProvidersSubject");
             $GLOBALS['EmailMessage'] = sprintf(GetLang("NoCheckoutProvidersErrorLong"), $GLOBALS['ShopPath']);
             $emailTemplate = FetchEmailTemplateParser();
             $emailTemplate->SetTemplate("general_email");
             $message = $emailTemplate->ParseTemplate(true);
             require_once ISC_BASE_PATH . "/lib/email.php";
             $obj_email = GetEmailClass();
             $obj_email->Set('CharSet', GetConfig('CharacterSet'));
             $obj_email->From(GetConfig('OrderEmail'), GetConfig('StoreName'));
             $obj_email->Set("Subject", GetLang("NoCheckoutProvidersSubject"));
             $obj_email->AddBody("html", $message);
             $obj_email->AddRecipient(GetConfig('AdminEmail'), "", "h");
             $email_result = $obj_email->Send();
         } else {
             if (count($checkoutProviders) > 1) {
                 $GLOBALS['HideTopPaymentButton'] = "none";
                 $GLOBALS['HideCheckoutError'] = "none";
             } else {
                 $GLOBALS['HidePaymentProviderList'] = "none";
                 $GLOBALS['HideCheckoutError'] = "none";
                 $GLOBALS['HidePaymentOptions'] = "none";
                 list(, $provider) = each($checkoutProviders);
                 if (method_exists($provider['object'], 'ShowPaymentForm') && !isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
                     $GLOBALS['ExpressCheckoutLoadPaymentForm'] = 'ExpressCheckout.ShowSingleMethodPaymentForm();';
                 }
                 if ($provider['object']->GetPaymentType() == PAYMENT_PROVIDER_OFFLINE) {
                     $GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton();";
                 }
                 $GLOBALS['CheckoutWith'] = $provider['object']->GetDisplayName();
             }
         }
         // Build the list of payment provider options
         $GLOBALS['PaymentProviders'] = $GLOBALS['StoreCreditPaymentProviders'] = "";
         foreach ($checkoutProviders as $provider) {
             $GLOBALS['ProviderChecked'] = '';
             if (count($checkoutProviders) == 1) {
                 $GLOBALS['ProviderChecked'] = 'checked="checked"';
             }
             $GLOBALS['ProviderId'] = $provider['object']->GetId();
             $GLOBALS['ProviderName'] = isc_html_escape($provider['object']->GetDisplayName());
             $GLOBALS['ProviderType'] = $provider['object']->GetPaymentType("text");
             if (method_exists($provider['object'], 'ShowPaymentForm')) {
                 $GLOBALS['ProviderPaymentFormClass'] = 'ProviderHasPaymentForm';
             } else {
                 $GLOBALS['ProviderPaymentFormClass'] = '';
             }
             $GLOBALS['PaymentFieldPrefix'] = '';
             $GLOBALS['PaymentProviders'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutProviderOption");
             $GLOBALS['PaymentFieldPrefix'] = 'credit_';
             $GLOBALS['StoreCreditPaymentProviders'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutProviderOption");
         }
     }
     // Are we coming back to this page for a particular reason?
     if (isset($_SESSION['REDIRECT_TO_CONFIRMATION_MSG'])) {
         $GLOBALS['HideCheckoutError'] = '';
         $GLOBALS['CheckoutErrorMsg'] = $_SESSION['REDIRECT_TO_CONFIRMATION_MSG'];
         unset($_SESSION['REDIRECT_TO_CONFIRMATION_MSG']);
     }
     // Get a summary of the order
     $orderSummary = $this->CalculateOrderSummary();
     // Start building the summary of all of the items in the order
     $GLOBALS['SNIPPETS']['CartItems'] = '';
     /* Baskaran */
     $compprice = 0;
     $comptotal = 0;
     /* Code Ends */
     foreach ($orderSummary['products'] as $cartKey => $product) {
         $GLOBALS['ProductQuantity'] = $product['quantity'];
         $GLOBALS['ProductPrice'] = CurrencyConvertFormatPrice($product['price']);
         $GLOBALS['ProductTotal'] = CurrencyConvertFormatPrice($product['total']);
         // If the item in the cart is a gift certificate, we need to show a special type of row
         if (isset($product['type']) && $product['type'] == "giftcertificate") {
             $GLOBALS['GiftCertificateName'] = isc_html_escape($product['data']['prodname']);
             $GLOBALS['GiftCertificateTo'] = isc_html_escape($product['certificate']['to_name']);
             $GLOBALS['SNIPPETS']['CartItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutCartItemGiftCertificate");
         } else {
             $GLOBALS['ProductAvailability'] = isc_html_escape($product['data']['prodavailability']);
             $GLOBALS['ItemId'] = $product['data']['productid'];
             // If this is a discounted price (from a coupon) override the product price to the was/now version
             if (isset($product['discount_price']) && $product['discount_price'] != $product['original_price']) {
                 $GLOBALS['ProductPrice'] = sprintf("<s class='CartStrike'>%s</s> %s", CurrencyConvertFormatPrice($product['original_price']), CurrencyConvertFormatPrice($product['price']));
             }
             // Is this product a variation?
             $GLOBALS['ProductOptions'] = '';
             if (isset($product['options']) && !empty($product['options'])) {
                 $GLOBALS['ProductOptions'] .= "<br /><small>(";
                 $comma = '';
                 foreach ($product['options'] as $name => $value) {
                     if (!trim($name) || !trim($value)) {
                         continue;
                     }
                     $GLOBALS['ProductOptions'] .= $comma . isc_html_escape($name) . ": " . isc_html_escape($value);
                     $comma = ', ';
                 }
                 $GLOBALS['ProductOptions'] .= ")</small>";
             }
             $GLOBALS['EventDate'] = '';
             if (isset($product['event_date'])) {
                 $GLOBALS['EventDate'] = '<div style="font-style: italic; font-size:11px; padding-left:10px">' . $product['event_name'] . ': ' . isc_date('M jS Y', $product['event_date']) . '</div>';
             }
             $GLOBALS['HideGiftWrapping'] = 'display: none';
             $GLOBALS['HideGiftMessagePreview'] = 'display: none';
             $GLOBALS['GiftWrappingName'] = '';
             $GLOBALS['GiftMessagePreview'] = '';
             if (isset($product['wrapping_name'])) {
                 $GLOBALS['HideGiftWrapping'] = '';
                 $GLOBALS['GiftWrappingName'] = isc_html_escape($product['wrapping_name']);
                 if (isset($product['wrapping_message'])) {
                     if (isc_strlen($product['wrapping_message']) > 30) {
                         $product['wrapping_message'] = substr($product['wrapping_message'], 0, 27) . '...';
                     }
                     $GLOBALS['GiftMessagePreview'] = isc_html_escape($product['wrapping_message']);
                     if ($product['wrapping_message']) {
                         $GLOBALS['HideGiftMessagePreview'] = '';
                     }
                 }
             }
             //create configurable product fields on order confirmation page with the data posted from add to cart page
             $GLOBALS['CartProductFields'] = '';
             if (isset($product['productFields'])) {
                 ISC_CARTCONTENT_PANEL::GetProductFieldDetails($product['productFields'], $cartKey);
             }
             /* Baskaran */
             $compitem = $product['compitem'];
             /*@$compproductid = $product['complementary']['comp_productid'];
               @$compmainproductid = $product['complementary']['comp_mainproductid'];
               $mainproductid = $product['product_id'];   */
             $GLOBALS['complementaryrow'] = '';
             for ($y = 0; $y < count($product['complementary']); $y++) {
                 /* Added for to display the complementary product in the cart -- Baskaran */
                 $compproductid = $product['complementary'][$y]['comp_productid'];
                 $compmainproductid = $product['complementary'][$y]['comp_mainproductid'];
                 $mainproductid = $product['product_id'];
                 if ($compitem == 1 and $mainproductid == $compmainproductid) {
                     //                        echo $compproductid." a2 ".$compmainproductid;
                     $compprodname = isc_html_escape($product['complementary'][$y]['comp_product_name']);
                     $compsku = isc_html_escape($product['complementary'][$y]['comp_product_code']);
                     $compprice = $product['complementary'][$y]['comp_original_price'];
                     $comppriceformat = CurrencyConvertFormatPrice($product['complementary'][$y]['comp_original_price']);
                     //                        $comptotal += $compprice;
                     $GLOBALS['CompProductTotal'] = CurrencyConvertFormatPrice($compprice * $product['complementary'][$y]['quantity']);
                     $GLOBALS['complementaryrow'] .= "<tr>\n                            <td>{$compprodname}</td>\n                            <td align='center'>" . $product['complementary'][$y]['quantity'] . "</td>\n                            <td align='center' class='CartItemIndividualPrice'>{$comppriceformat}</td>\n                            <td align='right' class='CartItemTotalPrice'><em class='ProductPrice'>" . $GLOBALS['CompProductTotal'] . "</em></td>\n                            </tr>";
                     $comptotal += $compprice * $product['complementary'][$y]['quantity'];
                 }
             }
             $GLOBALS['ProductName'] = isc_html_escape($product['data']['prodname']);
             $GLOBALS['SNIPPETS']['CartItems'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutCartItem");
         }
     }
     // Do we have a shipping price to show?
     if ($orderSummary['digitalOrder'] == 0) {
         $GLOBALS['ShippingCost'] = CurrencyConvertFormatPrice($orderSummary['shippingCost']);
         $GLOBALS['ShippingMethod'] = sprintf("%s %s %s", isc_html_escape($orderSummary['shippingProvider']), GetLang('For'), $GLOBALS['ShippingCost']);
         $GLOBALS['HideShoppingCartShippingCost'] = '';
         $GLOBALS['ShippingProvider'] = isc_html_escape($orderSummary['shippingProvider']);
         if (count($orderSummary['shippingAddresses']) == 1) {
             $address = current($orderSummary['shippingAddresses']);
             $GLOBALS['ShippingAddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->FormatShippingAddress($address);
         } else {
             if (count($orderSummary['shippingAddresses']) > 1) {
                 $GLOBALS['ShippingAddress'] = '<em>(Order will be shipped to multiple addresses)</em>';
             } else {
                 $GLOBALS['ShippingAddress'] = GetLang('NA');
             }
         }
         // Show the shipping details
         $GLOBALS['HideShippingDetails'] = '';
     } else {
         $GLOBALS['HideShippingDetails'] = 'display: none';
         $GLOBALS['HideShoppingCartShippingCost'] = 'none';
         $GLOBALS['ShippingAddress'] = GetLang('NotRequiredForDigitalDownloads');
         $GLOBALS['ShippingMethod'] = GetLang('ShippingImmediateDownload');
     }
     if (isset($orderSummary['billingAddressId'])) {
         $GLOBALS['BillingAddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->GetAndFormatShippingAddressById($orderSummary['billingAddressId']);
     } else {
         $GLOBALS['BillingAddress'] = $GLOBALS['ISC_CLASS_ACCOUNT']->FormatShippingAddress($orderSummary['billingAddress']);
     }
     // Do we have a handling cost to show?
     if (isset($orderSummary['handlingCost']) && $orderSummary['handlingCost'] > 0) {
         $GLOBALS['HandlingCost'] = CurrencyConvertFormatPrice($orderSummary['handlingCost']);
     } else {
         $GLOBALS['HideShoppingCartHandlingCost'] = 'none';
     }
     // Format the item total
     $GLOBALS['ItemTotal'] = CurrencyConvertFormatPrice($orderSummary['itemTotal']);
     if ($orderSummary['wrappingCost'] > 0) {
         $GLOBALS['GiftWrappingTotal'] = CurrencyConvertFormatPrice($orderSummary['wrappingCost']);
     } else {
         $GLOBALS['HideGiftWrappingTotal'] = 'display: none';
     }
     // Hide everything related to tax by default
     $GLOBALS['HideShoppingCartTaxCost'] = "none";
     $GLOBALS['HideShoppingCartIncludedTaxCost'] = "none";
     // Do we have any tax we need to show?
     if ($orderSummary['taxCost'] > 0) {
         $taxLines = "";
         $taxLang = "";
         if ($orderSummary['taxIncluded']) {
             $taxLang = "Included";
         }
         // get the taxes from the addresses and merge them if they are from the same tax rate
         $taxes = array();
         foreach ($orderSummary['vendors'] as $vendorId => $addresses) {
             foreach ($addresses as $addressId => $addressInfo) {
                 $taxId = $addressInfo['taxId'];
                 if (isset($taxes[$taxId])) {
                     $taxes[$taxId]['taxCost'] += $addressInfo['taxCost'];
                 } else {
                     $taxes[$taxId] = array('taxName' => $addressInfo['taxName'], 'taxCost' => $addressInfo['taxCost'], 'taxRate' => $addressInfo['taxRate']);
                 }
             }
         }
         $GLOBALS['SNIPPETS']['TaxLines'] = "";
         // generate lines for each tax rate
         foreach ($taxes as $taxId => $tax) {
             $GLOBALS['TaxName'] = isc_html_escape(sprintf(GetLang($taxLang . 'TaxLine'), $tax['taxName'], $tax['taxRate'] / 1));
             $GLOBALS['TaxCost'] = CurrencyConvertFormatPrice($tax['taxCost']);
             $taxLines .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutTaxLine");
         }
         // if more than one tax rate is used, display a total line
         if (count($taxes) > 1) {
             $GLOBALS['TaxName'] = isc_html_escape(GetLang($taxLang . 'TotalTax'));
             $GLOBALS['TaxCost'] = CurrencyConvertFormatPrice($orderSummary['taxCost']);
             $taxLines .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("CheckoutTaxLine");
         }
         $GLOBALS['SNIPPETS']['TaxLines'] = "";
         $GLOBALS['SNIPPETS']['IncludedTax'] = "";
         // are we displaying the tax before the total or after as included tax?
         if ($orderSummary['taxIncluded']) {
             $GLOBALS['SNIPPETS']['IncludedTax'] = $taxLines;
         } else {
             $GLOBALS['SNIPPETS']['TaxLines'] = $taxLines;
         }
     }
     // Format the grand total of the order
     $GLOBALS['TotalCost'] = CurrencyConvertFormatPrice($orderSummary['total']);
     $GLOBALS['HideAdjustedTotal'] = "none";
     $GLOBALS['SNIPPETS']['GiftCertificates'] = '';
     $GLOBALS['SNIPPETS']['CompanyGiftCertificates'] = '';
     if ($orderSummary['adjustedTotal'] != $orderSummary['total']) {
         $GLOBALS['HideAdjustedTotal'] = '';
         $GLOBALS['AdjustedTotalCost'] = $orderSummary['adjustedTotal'];
     }
     $GLOBALS['SNIPPETS']['Coupons'] = '';
     if (count($orderSummary['coupons'])) {
         foreach ($orderSummary['coupons'] as $coupon) {
             $GLOBALS['CouponId'] = $coupon['couponid'];
             $GLOBALS['CouponCode'] = $coupon['couponcode'];
             //zcs=>append && show coupon-name
             $query = "\n\t\t\t\t\tSELECT couponname\n\t\t\t\t\tFROM [|PREFIX|]coupons\n\t\t\t\t\tWHERE couponid='" . $coupon['couponid'] . "'\n\t\t\t\t";
             $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
             $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
             $GLOBALS['CouponName'] = $row['couponname'];
             //<=zcs
             // percent coupon
             if ($coupon['coupontype'] == 1) {
                 $discount = $coupon['discount'] . "%";
             } else {
                 $discount = CurrencyConvertFormatPrice($coupon['discount']);
             }
             $GLOBALS['CouponDiscount'] = $discount;
             $GLOBALS['SNIPPETS']['Coupons'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ConfirmOrderCoupon");
         }
     }
     // If we have any gift certificates, list those too
     if (!empty($orderSummary['giftCertificates'])) {
         foreach ($orderSummary['giftCertificates'] as $certificate) {
             $GLOBALS['GiftCertificateCode'] = isc_html_escape($certificate['giftcertcode']);
             $GLOBALS['GiftCertificateId'] = $certificate['giftcertid'];
             $GLOBALS['GiftCertificateBalance'] = CurrencyConvertFormatPrice($certificate['giftcertbalance']);
             $GLOBALS['GiftCertificateRemaining'] = CurrencyConvertFormatPrice($certificate['balanceremaining']);
             $GLOBALS['CertificateAmountUsed'] = CurrencyConvertFormatPrice($certificate['amountused']);
             $GLOBALS['SNIPPETS']['GiftCertificates'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ConfirmOrderGiftCertificate");
         }
     }
     //Add by NI_20100825_Jack
     // If we have any gift certificates, list those too
     if (!empty($orderSummary['companyGiftCertificates'])) {
         foreach ($orderSummary['companyGiftCertificates'] as $certificate) {
             $GLOBALS['CompanyGiftCertificateCode'] = isc_html_escape($certificate['cgccode']);
             $GLOBALS['CompanyGiftCertificateId'] = $certificate['cgcid'];
             $GLOBALS['CompanyGiftCertificateBalance'] = CurrencyConvertFormatPrice($certificate['cgcbalance']);
             $GLOBALS['CompanyGiftCertificateRemaining'] = CurrencyConvertFormatPrice($certificate['balanceremaining']);
             $GLOBALS['CompanyCertificateAmountUsed'] = CurrencyConvertFormatPrice($certificate['amountused']);
             //d($certificate);
             $GLOBALS['SNIPPETS']['CompanyGiftCertificates'] .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("ConfirmOrderCompanyGiftCertificate");
         }
     }
     // If the order total comes to $0.00, then we don't show the payment options and a lot of other things (because they have nothing to pay)
     if ($orderSummary['adjustedTotal'] == 0) {
         $GLOBALS['HidePaymentOptions'] = "none";
         $GLOBALS['HideUseCoupon'] = 'none';
         $GLOBALS['HidePaymentProviderList'] = "none";
         $GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton(); ExpressCheckout.UncheckPaymentProvider();";
     }
     // Does the customer have any store credit they can use?
     $GLOBALS['HideUseStoreCredit'] = "none";
     $GLOBALS['HideRemainingStoreCredit'] = "none";
     $customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerDataByToken();
     if ($customer['custstorecredit'] > 0) {
         $GLOBALS['HidePaymentOptions'] = "";
         $GLOBALS['StoreCredit'] = CurrencyConvertFormatPrice($customer['custstorecredit']);
         $GLOBALS['HideUseStoreCredit'] = "";
         $GLOBALS['HidePaymentProviderList'] = "none";
         // The customer has enough store credit to pay for the entirity of this order
         if ($customer['custstorecredit'] >= $orderSummary['adjustedTotal']) {
             $GLOBALS['PaymentButtonSwitch'] = "ShowContinueButton();";
             $GLOBALS['HideLimitedCreditWarning'] = "none";
             $GLOBALS['HideLimitedCreditPaymentOption'] = "none";
             $GLOBALS['HideCreditPaymentMethods'] = "none";
             $GLOBALS['RemainingCredit'] = $customer['custstorecredit'] - $orderSummary['adjustedTotal'];
             if ($GLOBALS['RemainingCredit'] > 0) {
                 $GLOBALS['HideRemainingStoreCredit'] = '';
                 $GLOBALS['RemainingCredit'] = CurrencyConvertFormatPrice($GLOBALS['RemainingCredit']);
             }
         } else {
             $GLOBALS['Remaining'] = CurrencyConvertFormatPrice($orderSummary['adjustedTotal'] - $customer['custstorecredit']);
             if (count($checkoutProviders) == 1) {
                 $GLOBALS['CheckoutStoreCreditWarning'] = sprintf(GetLang('CheckoutStoreCreditWarning2'), $GLOBALS['Remaining'], $GLOBALS['CheckoutWith']);
                 $GLOBALS['HideLimitedCreditPaymentOption'] = "none";
             } else {
                 $GLOBALS['CheckoutStoreCreditWarning'] = GetLang('CheckoutStoreCreditWarning');
             }
             $GLOBALS['ISC_LANG']['CreditPaymentMethod'] = sprintf(GetLang('CreditPaymentMethod'), $GLOBALS['Remaining']);
         }
         if (count($checkoutProviders) > 1) {
             $GLOBALS['CreditAlt'] = GetLang('CheckoutCreditAlt');
         } else {
             if (count($checkoutProviders) <= 1 && isset($GLOBALS['CheckoutWith'])) {
                 $GLOBALS['CreditAlt'] = sprintf(GetLang('CheckoutCreditAltOneMethod'), $GLOBALS['CheckoutWith']);
             } else {
                 if ($customer['custstorecredit'] >= $orderSummary['adjustedTotal']) {
                     $GLOBALS['HideCreditAltOptionList'] = "none";
                     $GLOBALS['HideConfirmOrderPage'] = "";
                     $GLOBALS['HideTopPaymentButton'] = "none";
                     $GLOBALS['HideCheckoutError'] = "none";
                     $GLOBALS['CheckoutErrorMsg'] = '';
                 }
             }
         }
     }
     // Customer has hit this page before. Delete the existing pending order
     // The reason we do a delete is if they're hitting this page again, something
     // has changed with their order or something has become invalid with it along the way.
     if (isset($_COOKIE['SHOP_ORDER_TOKEN']) && IsValidPendingOrderToken($_COOKIE['SHOP_ORDER_TOKEN'])) {
         $query = "\n\t\t\t\tSELECT orderid\n\t\t\t\tFROM [|PREFIX|]orders\n\t\t\t\tWHERE ordtoken='" . $GLOBALS['ISC_CLASS_DB']->Quote($_COOKIE['SHOP_ORDER_TOKEN']) . "' AND ordstatus=0\n\t\t\t";
         $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
         while ($order = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
             $entity = new ISC_ENTITY_ORDER();
             $entity->delete($order['orderid'], false, true);
         }
     }
     // Are we showing an error message?
     if (isset($GLOBALS['CheckoutErrorMsg']) && $GLOBALS['CheckoutErrorMsg'] != '') {
         $GLOBALS['HideCheckoutError'] = '';
     } else {
         $GLOBALS['HideCheckoutError'] = "none";
     }
     // Is there a success message to show?
     if (isset($GLOBALS['CheckoutSuccessMsg']) && $GLOBALS['CheckoutSuccessMsg'] != '') {
         $GLOBALS['HideCheckoutSuccess'] = '';
     } else {
         $GLOBALS['HideCheckoutSuccess'] = "none";
     }
     // Save the information about the pending order in the checkout session, we'll be using it when they visit the next page
     $_SESSION['CHECKOUT']['PENDING_DATA'] = array("ITEM_TOTAL" => $orderSummary['itemTotal'], "TAX_COST" => number_format($orderSummary['taxCost'], GetConfig('DecimalPlaces'), ".", ""), "TAX_INCLUDED" => $orderSummary['taxIncluded'], "ORDER_TOTAL" => number_format($orderSummary['total'] - $GLOBALS['ISC_CLASS_CART']->api->Get('SUBTOTAL_DISCOUNT'), GetConfig('DecimalPlaces'), ".", ""), "GATEWAY_AMOUNT" => number_format($orderSummary['adjustedTotal'], GetConfig('DecimalPlaces'), ".", ""), "GIFTCERTIFICATE_AMOUNT" => number_format($orderSummary['giftCertificateTotal'], GetConfig('DecimalPlaces'), ".", ""), "COMPANYGIFTCERTIFICATE_AMOUNT" => number_format($orderSummary['companyGiftCertificateTotal'], GetConfig('DecimalPlaces'), ".", ""));
     // Store information about each vendor in the order
     foreach ($orderSummary['vendors'] as $vendorId => $addressInfo) {
         foreach ($addressInfo as $addressId => $vendorInfo) {
             $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorId . '_' . $addressId] = array('ITEM_TOTAL' => $vendorInfo['itemTotal'], 'TAX_COST' => number_format($vendorInfo['taxCost'], GetConfig('DecimalPlaces'), ".", ""), 'TAX_RATE' => number_format($vendorInfo['taxRate'], GetConfig('DecimalPlaces'), ".", ""), 'TAX_NAME' => $vendorInfo['taxName'], 'ORDER_TOTAL' => number_format($vendorInfo['total'] - $GLOBALS['ISC_CLASS_CART']->api->Get('SUBTOTAL_DISCOUNT'), GetConfig('DecimalPlaces'), ".", ""));
         }
     }
     // If this is an anonymous checkout, save that
     if (isset($_POST['anonymousCheckout'])) {
         $_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT'] = 1;
     } else {
         $_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT'] = 0;
     }
     // Checkout out as a new customer and wishing to create an account, we need to save those details
     if (!CustomerIsSignedIn()) {
         if (isset($_POST['createAccount']) || GetConfig('GuestCheckoutCreateAccounts')) {
             // If we're automatically creating accounts, assign the user a random password
             $autoAccount = 0;
             if (isset($_POST['billing_Password'])) {
                 $password = $_POST['billing_Password'];
             }
             if (!isset($_POST['createAccount']) && GetConfig('GuestCheckoutCreateAccounts')) {
                 $password = substr(md5(uniqid(true)), 0, 8);
                 $autoAccount = 1;
             }
             if (!isset($_SESSION['CHECKOUT']['CREATE_ACCOUNT']) && isset($_POST['billing_EmailAddress'])) {
                 $_SESSION['CHECKOUT']['CREATE_ACCOUNT'] = 1;
                 $_SESSION['CHECKOUT']['ACCOUNT_DETAILS'] = array('email' => $_POST['billing_EmailAddress'], 'password' => $password, 'firstname' => $_POST['billing_FirstName'], 'lastname' => $_POST['billing_LastName'], 'company' => $_POST['billing_CompanyName'], 'phone' => $_POST['billing_Phone'], 'autoAccount' => $autoAccount);
             }
         } else {
             unset($_SESSION['CHECKOUT']['CREATE_ACCOUNT']);
             unset($_SESSION['CHECKOUT']['ACCOUNT_DETAILS']);
         }
     } else {
         unset($_SESSION['CHECKOUT']['CREATE_ACCOUNT']);
         unset($_SESSION['CHECKOUT']['ACCOUNT_DETAILS']);
     }
     if (GetConfig('EnableOrderComments') == 1) {
         $GLOBALS['HideOrderComments'] = "";
     } else {
         $GLOBALS['HideOrderComments'] = "none";
     }
     if ($GLOBALS['ISC_CLASS_CART']->api->Get('SUBTOTAL_DISCOUNT') == 0) {
         $GLOBALS['HideOrderDiscount'] = "display : none";
     } else {
         $GLOBALS['OrderDiscount'] = CurrencyConvertFormatPrice($GLOBALS['ISC_CLASS_CART']->api->Get('SUBTOTAL_DISCOUNT'));
         $GLOBALS['HideOrderDiscount'] = "";
     }
     if (GetConfig('EnableOrderTermsAndConditions') == 1) {
         $GLOBALS['HideOrderTermsAndConditions'] = "";
         if (GetConfig('OrderTermsAndConditionsType') == "link") {
             $GLOBALS['AgreeTermsAndConditions'] = GetLang('YesIAgree');
             $GLOBALS['TermsAndConditionsLink'] = "<a href='" . GetConfig('OrderTermsAndConditionsLink') . "' target='_BLANK'>" . strtolower(GetLang('TermsAndConditions')) . "</a>.";
             $GLOBALS['HideTermsAndConditionsTextarea'] = "display:none;";
         } else {
             $GLOBALS['HideTermsAndConditionsTextarea'] = '';
             $GLOBALS['OrderTermsAndConditions'] = GetConfig('OrderTermsAndConditions');
             $GLOBALS['AgreeTermsAndConditions'] = GetLang('AgreeTermsAndConditions');
             $GLOBALS['TermsAndConditionsLink'] = '';
         }
     } else {
         $GLOBALS['HideOrderTermsAndConditions'] = "display:none;";
     }
     $GLOBALS['AdjustedTotalCost'] = CurrencyConvertFormatPrice($orderSummary['adjustedTotal']);
 }