示例#1
0
 /**
  * Calculate the order details and populate the necessary session fields so we can call CreateOrder()
  *
  * @return void
  **/
 public function CalculateOrder()
 {
     $GLOBALS['ISC_CLASS_CART'] = GetClass('ISC_CART');
     //$GLOBALS['ISC_CLASS_CART'] not declared earlier, Added by Simha
     if ($GLOBALS['ISC_CLASS_CART']->api->AllProductsInCartAreIntangible()) {
         $all_digital_downloads = 1;
     } else {
         $all_digital_downloads = 0;
     }
     $GLOBALS['ISC_CLASS_CHECKOUT'] = GetClass('ISC_CHECKOUT');
     $orderSummary = $GLOBALS['ISC_CLASS_CHECKOUT']->CalculateOrderSummary();
     $this->module->DebugLog($orderSummary);
     $product_array = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCart(true);
     $itemTotal = 0;
     foreach ($product_array as $k => $product) {
         $comptotal = 0;
         /// Baskaran
         /*
         $compitem = $product['compitem'];
         @$compproductid = $product['complementary']['comp_productid'];
         @$compmainproductid = $product['complementary']['comp_mainproductid'];
         $mainproductid = $product['product_id'];
         
         if($compitem == 1 and $mainproductid == $compmainproductid) {
             $compprice = $product['complementary']['comp_original_price'];
             $comptotal += $compprice;
         }
         /// Code Ends 
         */
         //if .. else added by Simha to consider the discount price in order total
         /* To add complementary product to Google checkout -- Baskaran*/
         if ($product['compitem'] == 1) {
             for ($y = 0; $y < count($product['complementary']); $y++) {
                 if ($product['product_id'] == $product['complementary'][$y]['comp_mainproductid']) {
                     $compprodname = $product['complementary'][$y]['comp_product_name'];
                     $compprodprice = $product['complementary'][$y]['comp_original_price'];
                     $compqty = $product['complementary'][$y]['quantity'];
                     $comptotal += $compprodprice * $compqty;
                 }
             }
         }
         if (isset($product['discount_price']) && $product['discount_price'] < $product['product_price']) {
             $curprice = $product['discount_price'];
         } else {
             $curprice = $product['product_price'];
         }
         $itemTotal += $curprice * $product['quantity'] + $comptotal;
         # $comptotal added to add the complementary amount to the table -- Baskaran
     }
     if (isset($this->response->data[$this->response->root]['order-adjustment']['shipping']['merchant-calculated-shipping-adjustment'])) {
         $shipping = $this->response->data[$this->response->root]['order-adjustment']['shipping']['merchant-calculated-shipping-adjustment'];
     } else {
         $shipping = array('shipping-cost' => array('VALUE' => 0), 'shipping-name' => array('VALUE' => ''));
     }
     $shippingCost = $shipping['shipping-cost']['VALUE'];
     $vendorIds = $GLOBALS['ISC_CLASS_CART']->api->GetCartVendorIds();
     $vendorIds = array_shift($vendorIds);
     //array_pop replaced by array_shift to consider only the first vendor after merging vendors
     $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorIds . '_0'] = array();
     // The cost of shipping
     $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['COST'] = $shippingCost;
     // The handling cost
     $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['HANDLING'] = 0;
     // The name of the tax being applied
     $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_NAME'] = $orderSummary['taxName'];
     // The dollar value of the tax being applied
     $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorIds . '_0']['TAX_COST'] = $orderSummary['taxCost'];
     $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_COST'] = $orderSummary['taxCost'];
     // The rate the tax is being applied at as a percentage (0-100)
     $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_RATE'] = $orderSummary['taxRate'];
     // Is the tax already being included in the price of the products 0/1
     $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_INCLUDED'] = $orderSummary['taxIncluded'];
     $orderTotal = $itemTotal + $shippingCost;
     if (!$orderSummary['taxIncluded'] && !(GetConfig('TaxTypeSelected') == 2)) {
         $orderTotal += $orderSummary['taxCost'];
     }
     // The total of the order including items, shipping, handling and tax
     $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorIds . '_0']['ORDER_TOTAL'] = $orderTotal;
     $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorIds . '_0']['ITEM_TOTAL'] = $itemTotal;
     $_SESSION['CHECKOUT']['PENDING_DATA']['ORDER_TOTAL'] = $orderTotal;
     //$GLOBALS['ISC_CLASS_LOG']->LogSystemSuccess($this->logtype, 'response details '.print_r($this->response, true));
     // The shipping address array
     $_SESSION['CHECKOUT']['SHIPPING_ADDRESS'] = $this->GetAddressFromResponse($this->response->data[$this->response->root]['buyer-shipping-address']);
     // The billing address array
     $_SESSION['CHECKOUT']['BILLING_ADDRESS'] = $this->GetAddressFromResponse($this->response->data[$this->response->root]['buyer-billing-address']);
     // The english name of the provider
     $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['PROVIDER'] = $shipping['shipping-name']['VALUE'];
     // The id of the provider
     $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['MODULE'] = $this->GetShippingProviderModuleByName($shipping['shipping-name']['VALUE']);
     $shippingZoneId = GetShippingZoneIdByAddress($_SESSION['CHECKOUT']['SHIPPING_ADDRESS']);
     $shippingZone = GetShippingZoneById($shippingZoneId);
     // The amount of store credit being applied to the order
     $creditDiscount = 0;
     // The name of the gift certificates being applied
     $giftCertificates = '';
     $giftCertificateDiscount = 0;
     // The total amount of all the gift certs being applied
     $_SESSION['CHECKOUT']['PENDING_DATA']['GIFTCERTIFICATE_AMOUNT'] = $giftCertificateDiscount;
     // The amount being sent to the checkout gateway (order total - gift certifcate discounts - store credit discounts)
     $_SESSION['CHECKOUT']['PENDING_DATA']['GATEWAY_AMOUNT'] = $orderTotal - $creditDiscount - $giftCertificateDiscount;
     //$GLOBALS['ISC_CLASS_LOG']->LogSystemSuccess($this->logtype, 'checkout before creating the pending order '.print_r($_SESSION['CHECKOUT'], true));
     // Now that we're here, we have everything we need to create the pending order.
     // Create it and store it. We hard code the geoip information since google will be
     // making the request
     $selectedCurrency = GetCurrencyById($GLOBALS['CurrentCurrency']);
     $pendingOrder = array('customertoken' => '', 'customerid' => 0, 'itemtotal' => $orderSummary['itemTotal'], 'shippingcost' => $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['COST'], 'handlingcost' => $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['HANDLING'], 'taxname' => $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_NAME'], 'taxcost' => $_SESSION['CHECKOUT']['PENDING_DATA']['VENDORS'][$vendorIds . '_0']['TAX_COST'], 'taxrate' => $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_RATE'], 'totalincludestax' => $_SESSION['CHECKOUT']['PENDING_DATA']['TAX_INCLUDED'], 'totalcost' => $_SESSION['CHECKOUT']['PENDING_DATA']['ORDER_TOTAL'], 'shippingaddress' => $_SESSION['CHECKOUT']['SHIPPING_ADDRESS'], 'billingaddress' => $_SESSION['CHECKOUT']['BILLING_ADDRESS'], 'shippingprovider' => $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['PROVIDER'], 'shippingmodule' => $_SESSION['CHECKOUT']['SHIPPING'][$vendorIds . '_0']['MODULE'], 'paymentmethod' => 'checkout_googlecheckout', 'isdigitalorder' => (int) $all_digital_downloads, 'storecreditamount' => $creditDiscount, 'giftcertificateamount' => $_SESSION['CHECKOUT']['PENDING_DATA']['GIFTCERTIFICATE_AMOUNT'], 'giftcertificates' => $giftCertificates, 'gatewayamount' => $_SESSION['CHECKOUT']['PENDING_DATA']['GATEWAY_AMOUNT'], 'currencyid' => $selectedCurrency['currencyid'], 'currencyexchangerate' => $selectedCurrency['currencyexchangerate'], 'ordshippingzoneid' => $shippingZoneId, 'ordshippingzone' => $shippingZone['zonename']);
     return $pendingOrder;
 }
示例#2
0
 /**
  * Factor in the handling fee for a shipping quote in a particular shipping zone.
  *
  * @param int The ID of the shipping zone this quote comes from.
  * @param float The base shipping price to have handling factored in to.
  * @param float The handling fee for this shipping method.
  * @param boolean Set to true if this order contains digital items and we need to add on the digital handing
  * @return float The adjusted price with handling factored in.
  */
 public function FactorInZoneHandling($zoneId, $price, $methodHandling, $includeDigitalHandling = false)
 {
     $zone = GetShippingZoneById($zoneId);
     if (!is_array($zone)) {
         return $price;
     } else {
         if ($zone['zonehandlingseparate'] == 1) {
             return $price;
         }
     }
     $digitalHandling = 0;
     if ($includeDigitalHandling == true && GetConfig('DigitalOrderHandlingFee')) {
         $digitalHandling = GetConfig('DigitalOrderHandlingFee');
     }
     if ($zone['zonehandlingtype'] == 'module') {
         return $price + $methodHandling + $digitalHandling;
     } else {
         if ($zone['zonehandlingtype'] == 'global') {
             return $price + $zone['zonehandlingfee'] + $digitalHandling;
         } else {
             return $price + $digitalHandling;
         }
     }
 }
	public function getAvailableShippingMethods($enableRealTime = true, $cacheResults = true)
	{
		list($shippingQuoteItems, $fixedShippingCost) = $this->getShippingQuoteItems();

		$shippingQuotes = array();
		if ($cacheResults) {
			$this->shippingCache = array();
			$shippingQuotes = &$this->shippingCache;
		}

		// Fetch the shipping zone that this address belongs in
		$shippingZoneId = $this->getShippingAddressZone();
		$shippingZone = GetShippingZoneById($shippingZoneId);

		// Calculate the handling fee
		$zoneHandlingFee = 0;
		if ($shippingZone['zonehandlingtype'] == 'global' && $shippingZone['zonehandlingseparate']) {
			$zoneHandlingFee = $shippingZone['zonehandlingfee'];
		}

		// Free shipping method
		if ($this->allowsFreeShipping()) {
			$shippingQuotes[] = array(
				'description'	=> getLang('FreeShipping'),
				'price'			=> 0,
				'methodId'		=> -1,
				'module'		=> '',
				'handling'		=> $zoneHandlingFee,
			);

			if (empty($shippingQuoteItems)) {
				return $shippingQuotes;
			}
		}

		// Fixed shipping cost method
		if (empty($shippingQuoteItems) && $fixedShippingCost) {
			$adjustedPrice = $this->factorInShippingHandling($shippingZoneId, $fixedShippingCost, 0);
			$fixedShippingName = GetConfig('StoreName');

			$shippingQuotes[] = array(
				'description'	=> $fixedShippingName,
				'price'			=> $adjustedPrice,
				'methodId'		=> -1,
				'module'		=> '',
				'handling'		=> $zoneHandlingFee,
			);

			if (empty($shippingQuoteItems)) {
				return $shippingQuotes;
			}
		}

		// Fetch applicable shipping methods for this zone
		$query = "
			SELECT *
			FROM [|PREFIX|]shipping_methods
			WHERE zoneid='".(int)$shippingZoneId."' AND methodenabled='1' AND methodvendorid='".(int)$shippingZone['zonevendorid']."'
		";
		$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
		while ($method = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
			$quotes = $this->getShippingMethodQuotes($method, $enableRealTime);

			if($quotes)
				$shippingQuotes = array_merge($shippingQuotes, $quotes);
		}

		// Sort the shipping quotes by price
		uasort($shippingQuotes, array($this, 'sortShippingQuotes'));
		return $shippingQuotes;
	}
 /**
  * Create the pending order in the database with the customers selected payment details, etc.
  *
  * @return array An array containing information about what needs to be done next.
  */
 public function SavePendingOrder()
 {
     $provider = null;
     $verifyPaymentProvider = true;
     $redirectToFinishOrder = false;
     $providerId = '';
     $pendingOrderResult = array();
     if (!isset($_SESSION['CHECKOUT']['PENDING_DATA'])) {
         return false;
     }
     // Did they agree to signup to any mailing lists?
     if (isset($_POST['join_mailing_list'])) {
         ISC_SetCookie("JOIN_MAILING_LIST", 1, time() + 3600 * 24 * 7);
     }
     if (isset($_POST['join_order_list'])) {
         ISC_SetCookie("JOIN_ORDER_LIST", 1, time() + 3600 * 24 * 7);
     }
     $orderTotal = $_SESSION['CHECKOUT']['PENDING_DATA']['ORDER_TOTAL'];
     $giftCertificateAmount = $_SESSION['CHECKOUT']['PENDING_DATA']['GIFTCERTIFICATE_AMOUNT'];
     $gatewayAmount = $_SESSION['CHECKOUT']['PENDING_DATA']['GATEWAY_AMOUNT'];
     $creditUsed = 0;
     $giftCertificates = array();
     // Find out what currency we are using. We'll need this later to display their previous orders in the currency that they have selected
     $selectedCurrency = GetCurrencyById($GLOBALS['CurrentCurrency']);
     if (isset($_SESSION['OFFERCART']['GIFTCERTIFICATES']) && is_array($_SESSION['OFFERCART']['GIFTCERTIFICATES'])) {
         $giftCertificates = $_SESSION['OFFERCART']['GIFTCERTIFICATES'];
         // Now we check that the gift certificates can actually be applied to the order
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES'] = GetClass('ISC_GIFTCERTIFICATES');
         $badCertificates = array();
         $remainingBalance = 0;
         $GLOBALS['ISC_CLASS_GIFT_CERTIFICATES']->GiftCertificatesApplicableToOrder($orderTotal, $giftCertificates, $remainingBalance, $badCertificates);
         // One or more gift certificates were invalid so this order is now invalid
         if (count($badCertificates) > 0) {
             $badCertificatesList = '<strong>' . GetLang('BadGiftCertificates') . '</strong><ul>';
             foreach ($badCertificates as $code => $reason) {
                 if (is_array($reason) && $reason[0] == "expired") {
                     $reason = sprintf(GetLang('BadGiftCertificateExpired'), CDate($reason[1]));
                 } else {
                     $reason = GetLang('BadGiftCertificate' . ucfirst($reason));
                 }
                 $badCertificatesList .= sprintf("<li>%s - %s", isc_html_escape($code), $reason);
             }
             $badCertificatesList .= "</ul>";
             $pendingOrderResult = array('error' => GetLang('OrderContainedInvalidGiftCertificates'), 'errorDetails' => $badCertificatesList);
             return $pendingOrderResult;
         } else {
             if ($orderTotal == $giftCertificateAmount && $remainingBalance > 0) {
                 $pendingOrderResult = array('error' => GetLang('OrderTotalStillRemainingCertificates'));
                 return $pendingOrderResult;
             } else {
                 if ($orderTotal == $giftCertificateAmount) {
                     $providerId = 'giftcertificate';
                     $verifyPaymentProvider = false;
                     $redirectToFinishOrder = true;
                 }
             }
         }
     }
     // If the order total is 0, then we just forward the user on to the "Thank You" page and set the payment provider to ''
     if ($orderTotal == 0) {
         $providerId = '';
         $verifyPaymentProvider = false;
         $redirectToFinishOrder = true;
     }
     if ($verifyPaymentProvider) {
         if (isset($_POST['credit_checkout_provider']) && $_POST['credit_checkout_provider'] != "") {
             $_POST['checkout_provider'] = $_POST['credit_checkout_provider'];
         }
         $selected_provider = "";
         $providers = GetCheckoutModulesThatCustomerHasAccessTo(true);
         // If there's more than one, use the value they've chosen
         if (count($providers) > 1 && isset($_POST['checkout_provider']) || isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
             $selected_provider = $_POST['checkout_provider'];
         } else {
             if (count($providers) == 1) {
                 $selected_provider = $providers[0]['object']->GetId();
                 $_POST['checkout_provider'] = $selected_provider;
             } else {
                 $selected_provider = '';
             }
         }
         if (!isset($_POST['checkout_provider'])) {
             $_POST['checkout_provider'] = '';
         }
         // Are we using our store credit?
         $GLOBALS['ISC_CLASS_CUSTOMER'] = GetClass('ISC_CUSTOMER');
         $customer = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerDataByToken();
         if (isset($_POST['store_credit']) && $_POST['store_credit'] == 1 && $customer['custstorecredit'] > 0) {
             // User has not chosen a payment provider and can't afford this order using only store credit, throw back as error
             if (!$_POST['checkout_provider'] && $customer['custstorecredit'] < $orderTotal) {
                 return false;
             } else {
                 $onlyCredit = false;
                 $updateExtra = '';
                 // If we're only using store credit
                 $creditToUse = $orderTotal - $giftCertificateAmount;
                 if ($customer['custstorecredit'] >= $creditToUse) {
                     // Set the checkout provider
                     $providerId = 'storecredit';
                     $verifyPaymentProvider = false;
                     $redirectToFinishOrder = true;
                     $creditUsed = $creditToUse;
                     $onlyCredit = true;
                 } else {
                     // Using all of our store credit to pay for this order and we owe more.
                     $creditUsed = $customer['custstorecredit'];
                     $gatewayAmount -= $creditUsed;
                 }
             }
         }
     }
     // Now with round 2, do we still need to verify the payment provider?
     if ($verifyPaymentProvider) {
         // If there's more than one provider and one wasn't selected on the order confirmation screen then there's a problem
         if ((count($providers) == 0 || count($providers) > 1 && !isset($_POST['checkout_provider'])) && !isset($_SESSION['CHECKOUT']['ProviderListHTML'])) {
             return false;
         }
         // Is the payment provider selected actually valid?
         if (!GetModuleById('checkout', $provider, $selected_provider)) {
             return false;
         }
         $providerId = $provider->GetId();
     }
     // Load up all of the data for the items in the cart
     $GLOBALS['ISC_CLASS_MAKEAOFFER'] = GetClass('ISC_MAKEAOFFER');
     $cartItems = $GLOBALS['ISC_CLASS_MAKEAOFFER']->api->GetProductsInCart();
     // OK, we're successful down to here - do they want to create an account?
     if (isset($_SESSION['CHECKOUT']['CREATE_ACCOUNT'])) {
         $accountDetails = $_SESSION['CHECKOUT']['ACCOUNT_DETAILS'];
         $token = GenerateCustomerToken();
         $customerData = array('email' => trim($accountDetails['email']), 'password' => $accountDetails['password'], 'firstname' => $accountDetails['firstname'], 'lastname' => $accountDetails['lastname'], 'company' => $accountDetails['company'], 'phone' => $accountDetails['phone'], 'token' => $token);
         //alandy modify.2011-5-20.
         /*$sql="select customerid from [|PREFIX|]customers where custconemail='".$accountDetails['email']."'";
         		$query=$GLOBALS['ISC_CLASS_DB']->Query($sql);
         		while($rs=$GLOBALS['ISC_CLASS_DB']->Fetch($query)){
         		    $GLOBALS['Hasemailflag']="yes";
         		      return array(
         				    'error' => GetLang('AccountInternalError')
         			    );
         			    
         	        }*/
         $cusquery = "SELECT customerid\n\t\t\t\tFROM [|PREFIX|]customers\n\t\t\t\tWHERE isguest = 1 AND LOWER(custconemail)='" . $GLOBALS['ISC_CLASS_DB']->Quote(isc_strtolower($customerData['email'])) . "'";
         $cusresult = $GLOBALS['ISC_CLASS_DB']->Query($cusquery);
         $cusrow = $GLOBALS['ISC_CLASS_DB']->Fetch($cusresult);
         $custId = $cusrow['customerid'];
         if ($custId == '') {
             // 20110613 johnny add ---- add flag for guest user email don't exist
             if ($_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) {
                 $customerData['isguest'] = 1;
             }
             $customerId = $GLOBALS['ISC_CLASS_CUSTOMER']->CreateCustomerAccount($customerData, false, $accountDetails['autoAccount']);
         } else {
             if (!$_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) {
                 $customerId = $GLOBALS['ISC_CLASS_CUSTOMER']->CreateCustomerAccount($customerData, true, $accountDetails['autoAccount']);
                 /* delet already exist guest account
                 			$entity = new ISC_ENTITY_CUSTOMER();
                 			$entity->delete($custId);
                 			*/
             } else {
                 $customerId = $custId;
                 // update guest account in customer table for guest user email exist
                 $GLOBALS['ISC_CLASS_DB']->Query("UPDATE [|PREFIX|]customers SET custconfirstname = '" . $customerData['firstname'] . "', custconlastname = '" . $customerData['lastname'] . "' WHERE customerid = {$customerId}");
             }
         }
         if (!$customerId) {
             return array('error' => GetLang('AccountInternalError'));
         }
         if (!$_SESSION['CHECKOUT']['PENDING_DATA']['GUEST_CHECKOUT']) {
             $GLOBALS['ISC_CLASS_CUSTOMER']->LoginCustomerById($customerId, true);
         }
         unset($_SESSION['CHECKOUT']['CREATE_ACCOUNT']);
         unset($_SESSION['CHECKOUT']['ACCOUNT_DETAILS']);
         // Log the customer in
         @ob_end_clean();
     }
     if (isset($_COOKIE['SHOP_TOKEN'])) {
         $customerToken = $_COOKIE['SHOP_TOKEN'];
     } else {
         $customerToken = '';
     }
     $orderComments = '';
     if (isset($_REQUEST['ordercomments'])) {
         $orderComments = $_REQUEST['ordercomments'];
     }
     $checkoutSession = $_SESSION['CHECKOUT'];
     $pendingData = $checkoutSession['PENDING_DATA'];
     // Get a list of the vendors for all of the items in the cart, and loop through them
     // to build all of the pending orders
     $cartContent = $this->BreakdownCartByAddressVendorforshipping();
     //Changed to merging function by Simha
     $vendorOrderInfo = array();
     foreach ($cartContent as $vendorId => $addresses) {
         foreach ($addresses as $addressId => $products) {
             $allDigital = 1;
             $productArray = array();
             foreach ($products as $cartItemId => $product) {
                 // A physical product, mark as so
                 if ($product['data']['prodtype'] == PT_PHYSICAL) {
                     $allDigital = 0;
                 }
                 // Mark the quantity of this item
                 $productArray[$cartItemId] = $product['quantity'];
             }
             $vendorInfo = $pendingData['VENDORS'][$vendorId . '_' . $addressId];
             $vendorData = array('itemtotal' => $vendorInfo['ITEM_TOTAL'], 'taxcost' => $vendorInfo['TAX_COST'], 'taxname' => $vendorInfo['TAX_NAME'], 'taxrate' => $vendorInfo['TAX_RATE'], 'totalcost' => $vendorInfo['ORDER_TOTAL'], 'shippingcost' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['COST'], 'handlingcost' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['HANDLING'], 'shippingprovider' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['PROVIDER'], 'shippingmodule' => @$_SESSION['CHECKOUT']['SHIPPING'][$vendorId][$addressId]['MODULE'], 'isdigitalorder' => $allDigital, 'products' => $productArray);
             if ($addressId == 0) {
                 $addresses = $this->GetOrderShippingAddresses();
                 $vendorData['shippingaddress'] = $addresses[$addressId];
             } else {
                 $vendorData['shippingaddressid'] = $addressId;
             }
             // Shipping zones can be configured per vendor, so we need to be sure
             // to pass this along correctly too
             if (isset($vendorInfo['SHIPPING_ZONE'])) {
                 $shippingZone = GetShippingZoneById($vendorInfo['SHIPPING_ZONE']);
                 if (is_array($shippingZone)) {
                     $vendorData['ordshippingzoneid'] = $shippingZone['zoneid'];
                     $vendorData['ordshippingzone'] = $shippingZone['zonename'];
                 }
             }
             $vendorOrderInfo[$vendorId . '_' . $addressId] = $vendorData;
         }
     }
     // Set some defaults about the rest of the order
     $pendingOrder = array("customertoken" => $customerToken, 'paymentmethod' => $providerId, "storecreditamount" => $creditUsed, "giftcertificateamount" => $giftCertificateAmount, "giftcertificates" => $giftCertificates, "gatewayamount" => $gatewayAmount, 'totalincludestax' => $pendingData['TAX_INCLUDED'], "currencyid" => $selectedCurrency['currencyid'], "currencyexchangerate" => $selectedCurrency['currencyexchangerate'], 'ordercomments' => $orderComments, 'ipaddress' => GetIP(), 'vendorinfo' => $vendorOrderInfo);
     if (isset($customerId)) {
         $pendingOrder['customerid'] = $customerId;
     }
     // Determine the address ID we're using for billing
     if (is_array($_SESSION['CHECKOUT']['BILLING_ADDRESS'])) {
         $pendingOrder['billingaddress'] = $_SESSION['CHECKOUT']['BILLING_ADDRESS'];
     } else {
         $pendingOrder['billingaddressid'] = (int) $_SESSION['CHECKOUT']['BILLING_ADDRESS'];
     }
     if (isset($_POST['ordermessage'])) {
         $pendingOrder['ordermessage'] = $_POST['ordermessage'];
     } else {
         $pendingOrder['ordermessage'] = '';
     }
     /**
      * Save our custom fields. If we are creating a new account then split this up so the
      * account fields will go in the customers table and the rest will go in the orders table
      */
     if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['customer']) && isset($customerId) && isId($customerId)) {
         $formSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['customer']);
         if (isId($formSessionId)) {
             $updateData = array('customerid' => $customerId, 'email' => $customerData['email'], 'firstname' => $customerData['firstname'], 'lastname' => $customerData['lastname'], 'company' => $customerData['company'], 'phone' => $customerData['phone'], 'custformsessionid' => $formSessionId);
             $entity = new ISC_ENTITY_CUSTOMER();
             $entity->edit($updateData);
         }
     }
     /**
      * OK, now to store the custom address fields. Check here to see if we are not split
      * shipping (single order)
      */
     if (!isset($_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING']) || !$_SESSION['CHECKOUT']['IS_SPLIT_SHIPPING']) {
         $pendingOrder['ordformsessionid'] = '';
         if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS'])) {
             /**
              * Save the billing
              */
             if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && isset($pendingOrder['billingaddress']['saveAddress']) && $pendingOrder['billingaddress']['saveAddress']) {
                 $pendingOrder['billingaddress']['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']);
             }
             /**
              * Now for the shipping. Only save this once for all the shipping addresses
              */
             if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'])) {
                 $shippSessId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping']);
                 foreach ($pendingOrder['vendorinfo'] as $vendorId => $vendorData) {
                     if (isset($vendorData['shippingaddress']['saveAddress']) && $vendorData['shippingaddress']['saveAddress']) {
                         $pendingOrder['vendorinfo'][$vendorId]['shippingaddress']['shipformsessionid'] = $shippSessId;
                     }
                 }
             }
             /**
              * Now the orders. This part is tricky because the billing and shipping information
              * have the same keys (same fields used in the frontend). We need to split them up
              * into separate billing and shipping information and then save it
              */
             if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'])) {
                 /**
                  * We create a map first so we can map the shipping information to its proper field
                  * ID
                  */
                 $billingKeys = array_keys($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']);
                 $fieldAddressMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_BILLING, $billingKeys);
                 /**
                  * OK, we have the map, now to split up the custom fields
                  */
                 $orderSessData = array();
                 foreach ($fieldAddressMap as $fieldId => $newShippingFieldId) {
                     $orderSessData[$fieldId] = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'][$fieldId];
                     if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'][$fieldId])) {
                         $orderSessData[$newShippingFieldId] = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['shipping'][$fieldId];
                     }
                 }
                 $pendingOrder['ordformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($orderSessData);
             }
         }
         /**
          * This is for split shipping. Loop through each address to get their default custom
          * field data, combine it with the billing custom field data, create the form session
          * record and then save that ID for each address
          */
     } else {
         $shippingAddresses = $this->GetOrderShippingAddresses();
         $origFormSessionData = array();
         if (isset($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing']) && is_array($_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'])) {
             $origFormSessionData = $_SESSION['CHECKOUT']['CUSTOM_FIELDS']['billing'];
         }
         foreach ($pendingOrder['vendorinfo'] as $vendorId => $vendorData) {
             $address = null;
             $orderSessData = array();
             if (array_key_exists($vendorData['shippingaddressid'], $shippingAddresses)) {
                 $address = $shippingAddresses[$vendorData['shippingaddressid']];
             }
             if (isset($address['shipformsessionid']) && isId($address['shipformsessionid'])) {
                 $shippingSessionData = $GLOBALS['ISC_CLASS_FORM']->getSavedSessionData($address['shipformsessionid']);
                 if (is_array($shippingSessionData)) {
                     /**
                      * Same deal with this save session data because the billing and shipping data
                      * use the same fields and therefore have the same keys
                      */
                     $billingKeys = array_keys($origFormSessionData);
                     $fieldAddressMap = $GLOBALS['ISC_CLASS_FORM']->mapAddressFieldList(FORMFIELDS_FORM_BILLING, $billingKeys);
                     /**
                      * OK, we have the map, now to split up the custom fields
                      */
                     $orderSessData = array();
                     foreach ($fieldAddressMap as $fieldId => $newShippingFieldId) {
                         $orderSessData[$fieldId] = $origFormSessionData[$fieldId];
                         $orderSessData[$newShippingFieldId] = $shippingSessionData[$fieldId];
                     }
                 }
             }
             $newFormSessionId = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($orderSessData);
             if (isId($newFormSessionId)) {
                 $pendingOrder['vendorinfo'][$vendorId]['ordformsessionid'] = $newFormSessionId;
             }
         }
     }
     $pendingToken = CreateOrder($pendingOrder, $cartItems);
     // Try to add the record and if we can't then take them back to the shopping cart
     if (!$pendingToken) {
         return false;
     }
     // Persist the pending order token as a cookie for 24 hours
     ISC_SetCookie("SHOP_ORDER_TOKEN", $pendingToken, time() + 3600 * 24, true);
     $_COOKIE['SHOP_ORDER_TOKEN'] = $pendingToken;
     // Redirecting to finish order page?
     if ($redirectToFinishOrder) {
         return array('redirectToFinishOrder' => true);
     }
     $orderData = LoadPendingOrdersByToken($pendingToken);
     // Otherwise, the gateway want's to do something
     $provider->SetOrderData($orderData);
     // Is this an online payment provider? It would like to do something
     if ($provider->GetPaymentType() == PAYMENT_PROVIDER_ONLINE || method_exists($provider, "ShowPaymentForm")) {
         // Call the checkout process for the selected provider
         if (method_exists($provider, "ShowPaymentForm")) {
             return array('provider' => $provider, 'showPaymentForm' => true);
         } else {
             return array('provider' => $provider);
         }
     } else {
         return array('provider' => $provider);
     }
 }