Exemple #1
0
function ordOrderProcessing($shippingMethodID, $paymentMethodID, $shippingAddressID, $billingAddressID, $shippingModuleFiles, $paymentModulesFiles, $customers_comment, $cc_number, $cc_holdername, $cc_expires, $cc_cvv, $log, $smarty_mail, $shServiceID = 0)
{
    $customerID = $log != null ? regGetIdByLogin($log) : NULL;
    if ($log != null) {
        $customerInfo = regGetCustomerInfo2($log);
    } else {
        $customerInfo['first_name'] = $_SESSION['first_name'];
        $customerInfo['last_name'] = $_SESSION['last_name'];
        $customerInfo['Email'] = $_SESSION['email'];
        $customerInfo['affiliationLogin'] = $_SESSION['affiliationLogin'];
    }
    $order_time = get_current_time();
    $frandl = mt_rand(3, 999);
    $order_active_link = md5($order_time) . $frandl;
    $customer_ip = stGetCustomerIP_Address();
    $statusID = CONF_ACTIVE_ORDER == 1 ? 0 : ostGetNewOrderStatus();
    $customer_affiliationLogin = isset($customerInfo['affiliationLogin']) ? $customerInfo['affiliationLogin'] : '';
    $customer_email = $customerInfo['Email'];
    $currencyID = currGetCurrentCurrencyUnitID();
    if ($currencyID != 0) {
        $currentCurrency = currGetCurrencyByID($currencyID);
        $currency_code = $currentCurrency['currency_iso_3'];
        $currency_value = $currentCurrency['currency_value'];
        $currency_round = $currentCurrency['roundval'];
    } else {
        $currency_code = '';
        $currency_value = 1;
        $currency_round = 2;
    }
    // get shipping address
    if ($shippingAddressID != 0) {
        $shippingAddress = regGetAddress($shippingAddressID);
        $shippingAddressCountry = cnGetCountryById($shippingAddress['countryID']);
        $shippingAddress['country_name'] = $shippingAddressCountry['country_name'];
    } else {
        $shippingCountryName = cnGetCountryById($_SESSION['receiver_countryID']);
        $shippingCountryName = $shippingCountryName['country_name'];
        $shippingAddress['first_name'] = $_SESSION['receiver_first_name'];
        $shippingAddress['last_name'] = $_SESSION['receiver_last_name'];
        $shippingAddress['country_name'] = $shippingCountryName;
        $shippingAddress['state'] = $_SESSION['receiver_state'];
        $shippingAddress['city'] = $_SESSION['receiver_city'];
        $shippingAddress['address'] = $_SESSION['receiver_address'];
        $shippingAddress['zoneID'] = $_SESSION['receiver_zoneID'];
    }
    if (is_null($shippingAddress['state']) || trim($shippingAddress['state']) == '') {
        $zone = znGetSingleZoneById($shippingAddress['zoneID']);
        $shippingAddress['state'] = $zone['zone_name'];
    }
    // get billing address
    if ($billingAddressID != 0) {
        $billingAddress = regGetAddress($billingAddressID);
        $billingAddressCountry = cnGetCountryById($billingAddress['countryID']);
        $billingAddress['country_name'] = $billingAddressCountry['country_name'];
    } else {
        $billingCountryName = cnGetCountryById($_SESSION['billing_countryID']);
        $billingCountryName = $billingCountryName['country_name'];
        $billingAddress['first_name'] = $_SESSION['billing_first_name'];
        $billingAddress['last_name'] = $_SESSION['billing_last_name'];
        $billingAddress['country_name'] = $billingCountryName;
        $billingAddress['state'] = $_SESSION['billing_state'];
        $billingAddress['city'] = $_SESSION['billing_city'];
        $billingAddress['address'] = $_SESSION['billing_address'];
        $billingAddress['zoneID'] = $_SESSION['billing_zoneID'];
    }
    if (is_null($billingAddress['state']) || trim($billingAddress['state']) == '') {
        $zone = znGetSingleZoneById($billingAddress['zoneID']);
        $billingAddress['state'] = $zone['zone_name'];
    }
    $cartContent = cartGetCartContent();
    foreach ($cartContent['cart_content'] as $key => $cartItem) {
        if (!empty($cartItem['opt_margin']) && $paymentMethodID == 2) {
            $cost = $cartItem['costUC'];
            $margin = $cost / 100 * CONF_PERCENT_MARGIN;
            $cost += $margin;
            $costShow = show_price($cost * $cartItem['quantity']);
            $cartContent['cart_content'][$key]['costUC'] = $cost;
            $cartContent['cart_content'][$key]['cost'] = $costShow;
        }
    }
    if ($log != null) {
        $addresses = array($shippingAddressID, $billingAddressID);
    } else {
        $addresses = array(array('countryID' => $_SESSION['receiver_countryID'], 'zoneID' => $_SESSION['receiver_zoneID']), array('countryID' => $_SESSION['billing_countryID'], 'zoneID' => $_SESSION['billing_zoneID']));
    }
    $orderDetails = array('first_name' => $shippingAddress['first_name'], 'last_name' => $shippingAddress['last_name'], 'email' => $customerInfo['Email'], 'order_amount' => oaGetOrderAmountExShippingRate($cartContent, $addresses, $log, FALSE));
    $shippingMethod = shGetShippingMethodById($shippingMethodID);
    $shipping_email_comments_text = $shippingMethod['email_comments_text'];
    $shippingName = $shippingMethod['Name'];
    $paymentMethod = payGetPaymentMethodById($paymentMethodID);
    $paymentName = $paymentMethod['Name'];
    $payment_email_comments_text = $paymentMethod['email_comments_text'];
    if (isset($paymentMethod['calculate_tax']) && (int) $paymentMethod['calculate_tax'] == 0) {
        $order_amount = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, TRUE, $shServiceID);
        $d = oaGetDiscountPercent($cartContent, $log);
        $tax = 0;
        $shipping_costUC = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, FALSE, $shServiceID, TRUE);
        $discount_percent = oaGetDiscountPercent($cartContent, $log);
    } else {
        $order_amount = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, TRUE, $shServiceID);
        $d = oaGetDiscountPercent($cartContent, $log);
        $tax = oaGetProductTax($cartContent, $d, $addresses);
        $shipping_costUC = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, TRUE, $shServiceID, TRUE);
        $discount_percent = oaGetDiscountPercent($cartContent, $log);
    }
    $shServiceInfo = '';
    if (is_array($shipping_costUC)) {
        list($shipping_costUC) = $shipping_costUC;
        $shServiceInfo = $shipping_costUC['name'];
        $shipping_costUC = $shipping_costUC['rate'];
    }
    $paymentMethod = payGetPaymentMethodById($paymentMethodID);
    if ($paymentMethod) {
        $currentPaymentModule = modGetModuleObj($paymentMethod['module_id'], PAYMENT_MODULE);
    } else {
        $currentPaymentModule = null;
    }
    if ($currentPaymentModule != null) {
        //define order details for payment module
        $order_payment_details = array('customer_email' => $customer_email, 'customer_ip' => $customer_ip, 'order_amount' => $order_amount, 'currency_code' => $currency_code, 'currency_value' => $currency_value, 'shipping_cost' => $shipping_costUC, 'order_tax' => $tax, 'shipping_info' => $shippingAddress, 'billing_info' => $billingAddress);
        $process_payment_result = $currentPaymentModule->payment_process($order_payment_details);
        //gets payment processing result
        if (!($process_payment_result == 1)) {
            //die ($process_payment_result);
            if (isset($_POST)) {
                $_SESSION['order4confirmation_post'] = $_POST;
            }
            xSaveData('PaymentError', $process_payment_result);
            if (!$customerID) {
                RedirectProtected('index.php?order4_confirmation_quick=yes' . '&shippingMethodID=' . $_GET['shippingMethodID'] . '&paymentMethodID=' . $_GET['paymentMethodID'] . '&shServiceID=' . $shServiceID);
            } else {
                RedirectProtected('index.php?order4_confirmation=yes' . '&shippingAddressID=' . $_GET['shippingAddressID'] . '&shippingMethodID=' . $_GET['shippingMethodID'] . '&billingAddressID=' . $_GET['billingAddressID'] . '&paymentMethodID=' . $_GET['paymentMethodID'] . '&shServiceID=' . $shServiceID);
            }
            return false;
        }
    }
    $customerID = (int) $customerID;
    //    debug($cartContent['cart_content']);
    //
    //    exit;
    $sql = 'INSERT INTO ' . ORDERS_TABLE . '
    SET
    customerID =  ' . (int) $customerID . ',
    order_time = "' . xEscSQL($order_time) . '",
    customer_ip = "' . xToText($customer_ip) . '",
    shipping_type = "' . xToText($shippingName) . '",
    payment_type = "' . xToText($paymentName) . '",
    customers_comment = "' . xToText($customers_comment) . '",
    statusID = ' . (int) $statusID . ',
    shipping_cost = "' . (double) $shipping_costUC . '",
    order_discount = "' . (double) $discount_percent . '",
    order_amount= "' . (double) $order_amount . '",
    currency_code = "' . xEscSQL($currency_code) . '",
    currency_value = "' . (double) $currency_value . '",
    customer_firstname = "' . xToText($customerInfo['first_name']) . '",
    customer_lastname = "' . xToText($customerInfo['last_name']) . '",
    customer_email = "' . xToText($customer_email) . '",
    shipping_firstname = "' . xToText($shippingAddress['first_name']) . '",
    shipping_lastname = "' . xToText($shippingAddress['last_name']) . '",
    shipping_country= "' . xToText($shippingAddress['country_name']) . '",
    shipping_state= "' . xToText($shippingAddress['state']) . '",
    shipping_city= "' . xToText($shippingAddress['city']) . '",
    shipping_address= "' . xToText($shippingAddress['address']) . '",
    billing_firstname= "' . xToText($billingAddress['first_name']) . '",
    billing_lastname= "' . xToText($billingAddress['last_name']) . '",
    billing_country= "' . xToText($billingAddress['country_name']) . '",
    billing_state= "' . xToText($billingAddress['state']) . '",
    billing_city= "' . xToText($billingAddress['city']) . '",
    billing_address= "' . xToText($billingAddress['address']) . '",
    cc_number= "' . xEscSQL($cc_number) . '",
    cc_holdername= "' . xToText($cc_holdername) . '",
    cc_expires= "' . xEscSQL($cc_expires) . '",
    cc_cvv= "' . xEscSQL($cc_cvv) . '",
    affiliateID= "' . (isset($_SESSION['refid']) ? $_SESSION['refid'] : regGetIdByLogin($customer_affiliationLogin)) . '",
    shippingServiceInfo= "' . $shServiceInfo . '",
    custlink= "' . xEscSQL($order_active_link) . '",
    currency_round= "' . (int) $currency_round . '",
    paymethod= ' . (int) $paymentMethodID;
    db_query($sql);
    $orderID = db_insert_id(ORDERS_TABLE);
    if (!CONF_ACTIVE_ORDER) {
        stChangeOrderStatus($orderID, $statusID);
    }
    $paymentMethod = payGetPaymentMethodById($paymentMethodID);
    if ($paymentMethod) {
        $currentPaymentModule = modGetModuleObj($paymentMethod['module_id'], PAYMENT_MODULE);
        //                $currentPaymentModule = payGetPaymentModuleById( $paymentMethod['module_id'], $paymentModulesFiles );
    } else {
        $currentPaymentModule = null;
    }
    //save shopping cart content to database and update in-stock information
    if ($log != null) {
        cartMoveContentFromShoppingCartsToOrderedCarts($orderID, $shippingMethodID, $paymentMethodID, $shippingAddressID, $billingAddressID, $shippingModuleFiles, $paymentModulesFiles, $smarty_mail);
    } else {
        _moveSessionCartContentToOrderedCart($orderID, $paymentMethodID);
        //update in-stock information
        if ($statusID != ostGetCanceledStatusId() && CONF_CHECKSTOCK) {
            $q1 = db_query('select itemID, Quantity FROM ' . ORDERED_CARTS_TABLE . ' WHERE orderID=' . (int) $orderID);
            while ($item = db_fetch_row($q1)) {
                $q2 = db_query('select productID FROM ' . SHOPPING_CART_ITEMS_TABLE . ' WHERE itemID=' . (int) $item['itemID']);
                $pr = db_fetch_row($q2);
                if ($pr) {
                    db_query('update ' . PRODUCTS_TABLE . ' set in_stock = in_stock - ' . (int) $item['Quantity'] . ' where productID=' . (int) $pr[0]);
                    $q = db_query('select name, in_stock FROM ' . PRODUCTS_TABLE . ' WHERE productID=' . (int) $pr[0]);
                    $productsta = db_fetch_row($q);
                    if ($productsta[1] == 0) {
                        if (CONF_AUTOOFF_STOCKADMIN) {
                            db_query('update ' . PRODUCTS_TABLE . ' set enabled=0 where productID=' . (int) $pr[0]);
                        }
                        if (CONF_NOTIFY_STOCKADMIN) {
                            $smarty_mail->assign('productstaname', $productsta[0]);
                            $smarty_mail->assign('productstid', $pr[0]);
                            $stockadmin = $smarty_mail->fetch('notify_stockadmin.tpl');
                            $ressta = xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, CUSTOMER_ACTIVATE_99 . ' - ' . CONF_SHOP_NAME, $stockadmin);
                        }
                    }
                }
            }
        }
        //now save registration form aux fields into CUSTOMER_REG_FIELDS_VALUES_TABLE_QUICKREG
        //for quick checkout orders these fields are stored separately than for registered customer (SS_customers)
        db_query('delete from ' . CUSTOMER_REG_FIELDS_VALUES_TABLE_QUICKREG . ' where orderID=' . (int) $orderID);
        foreach ($_SESSION as $key => $val) {
            if (strstr($key, 'additional_field_') && strlen(trim($val)) > 0) {
                $id = (int) str_replace('additional_field_', '', $key);
                if ($id > 0) {
                    db_query('insert into ' . CUSTOMER_REG_FIELDS_VALUES_TABLE_QUICKREG . ' (orderID, reg_field_ID, reg_field_value) values (' . (int) $orderID . ', ' . (int) $id . ', "' . xToText(trim($val)) . '");');
                }
            }
        }
    }
    if ($currentPaymentModule != null) {
        $currentPaymentModule->after_processing_php($orderID);
    }
    _sendOrderNotifycationToAdmin($orderID, $smarty_mail, $tax);
    _sendOrderNotifycationToCustomer($orderID, $smarty_mail, $customerInfo['Email'], $log, $payment_email_comments_text, $shipping_email_comments_text, $tax, $order_active_link);
    if ($log == null) {
        _quickOrderUnsetSession();
    }
    unset($_SESSION['order4confirmation_post']);
    return $orderID;
}
Exemple #2
0
                 regAuthenticate($login, $cust_password);
             }
             $RedirectURL = '';
             if (isset($order)) {
                 if (isset($billingAddressID)) {
                     $RedirectURL = "index.php?order2_shipping=yes&shippingAddressID=" . regGetDefaultAddressIDByLogin($login) . "&defaultBillingAddressID=" . $billingAddressID;
                 } else {
                     $RedirectURL = "index.php?order2_shipping=yes&shippingAddressID=" . regGetDefaultAddressIDByLogin($login);
                 }
             } elseif (isset($order_without_billing_address)) {
                 $RedirectURL = "index.php?order2_shipping=yes&shippingAddressID=" . regGetDefaultAddressIDByLogin($login);
             } else {
                 $RedirectURL = "index.php?r_successful=yes";
             }
             if (CONF_ENABLE_REGCONFIRMATION && (isset($order) || isset($order_without_billing_address))) {
                 xSaveData('xREGMAILCONF_URLORDER2', $RedirectURL);
                 $RedirectURL = "index.php?act_customer=1&order2=yes";
             }
             RedirectJavaScript($RedirectURL);
         } else {
             $smarty->assign("reg_error", ERROR_INPUT_STATE);
         }
     } else {
         $smarty->assign("reg_error", $error);
     }
 }
 // countries
 $callBackParam = array();
 $count_row = 0;
 $countries = cnGetCountries($callBackParam, $count_row);
 $smarty->assign("countries", $countries);
function settingCONF_BYCOUNTRY_BYZONE_PERCENT_FORM()
{
    $curr_country = isset($_POST["shipping_module_bycountry_byzone_country"]) ? $_POST["shipping_module_bycountry_byzone_country"] : 0;
    $curr_country = (int) $curr_country;
    if (!$curr_country) {
        $curr_country = xGetData('SXshipping_module_bycountry_byzone_countryPERC');
    }
    xSaveData('SXshipping_module_bycountry_byzone_countryPERC', $curr_country);
    $module_id = isset($_GET['setting_up']) ? $_GET['setting_up'] : 0;
    $ModuleConfig = modGetModuleConfig($module_id);
    if (!$ModuleConfig['ModuleClassName']) {
        $module_id = 0;
    }
    if (isset($_POST["save"])) {
        $radiotoggle = isset($_POST["shipping_module_bycountry_byzone_radiotoggle"]) ? $_POST["shipping_module_bycountry_byzone_radiotoggle"] : 0;
        if ($radiotoggle == 0) {
            $rate = (double) $_POST["shipping_module_bycountry_byzone_zone_rate_0"];
            $sql = '
                                DELETE FROM ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                                WHERE module_id="' . $module_id . '" AND countryID=' . $curr_country . ' and zoneID=0
                        ';
            db_query($sql);
            $sql = '
                                INSERT INTO ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                                (module_id, countryID, zoneID, shipping_rate)
                                VALUES (' . $module_id . ', ' . $curr_country . ', 0, ' . $rate . ')
                        ';
            db_query($sql);
        } else {
            $sql = '
                                DELETE FROM ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                                WHERE module_id="' . $module_id . '" AND countryID=' . $curr_country . '
                        ';
            db_query($sql);
            foreach ($_POST as $key => $val) {
                if (strstr($key, "shipping_module_bycountry_byzone_zone_rate_")) {
                    $zone = (int) str_replace("shipping_module_bycountry_byzone_zone_rate_", "", $key);
                    $rate = (double) $val;
                    if ($zone > 0 && $rate != 0) {
                        $sql = '
                                                        INSERT INTO ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                                                        (module_id, countryID, zoneID, shipping_rate)
                                                        VALUES (' . $module_id . ', ' . $curr_country . ', ' . $zone . ', ' . $rate . ')
                                                ';
                        db_query($sql);
                    }
                }
            }
        }
    }
    $res = "<table border=0>\n<tr>\n<td>" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_1 . "</td>\n";
    $countries_count = 0;
    $countries = cnGetCountries(null, $countries_count);
    $res .= "<td><select name='shipping_module_bycountry_byzone_country'>\n";
    $res .= "<option value='0'>" . ADMIN_NOT_DEFINED . "</option>\n";
    foreach ($countries as $country) {
        $res .= "<option value='" . $country["countryID"] . "' ";
        if ($curr_country == $country["countryID"]) {
            $res .= " selected ";
        }
        $res .= ">";
        $res .= $country["country_name"];
        $res .= "</option>\n";
    }
    $res .= "</select></td>";
    $res .= "<td><input type=submit name=shipping_module_bycountry_byzone_change_country value=\"" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_2 . "\"></td>\n";
    $res .= "</tr>\n";
    //show toggle + zones
    if ($curr_country > 0) {
        $zones = znGetZonesById($curr_country);
        //toggle
        $res .= "<tr><td colspan=3><hr size=1></td></tr>\n";
        $res .= "<tr><td colspan=3>\n";
        $sql = '
                        SELECT shipping_rate FROM ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                        WHERE module_id="' . $module_id . '" AND countryID=' . $curr_country . ' and zoneID=0
                ';
        $q = db_query($sql);
        $row = db_fetch_row($q);
        if ($row || count($zones) == 0) {
            $radiotoggle = 0;
            //fixed for this country
            $rate = (double) $row[0];
        } else {
            $radiotoggle = 1;
            //by zone definition
            $rate = 0;
        }
        $res .= "<table border=0><tr><td valign=top>\n<input type=radio name=shipping_module_bycountry_byzone_radiotoggle value=0";
        if ($radiotoggle == 0) {
            $res .= " checked";
        }
        $res .= " onclick='JavaScript:shipping_module_bycountry_byzone_toogleClickHandler();'></td>\n";
        $res .= "<td valign=top>" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_7 . "</td>\n";
        $res .= "<td><input type=text name=shipping_module_bycountry_byzone_zone_rate_0 value=\"{$rate}\">" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_3 . "</td></tr>\n";
        $res .= "<tr><td valign=top>\n<input type=radio name=shipping_module_bycountry_byzone_radiotoggle value=1";
        if ($radiotoggle == 1) {
            $res .= " checked";
        }
        $res .= " onclick='JavaScript:shipping_module_bycountry_byzone_toogleClickHandler();'></td>\n";
        $res .= "<td colspan=2>" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_4 . "\n";
        //zones
        if (count($zones) > 0) {
            $res .= "<p><table>\n";
            foreach ($zones as $zone) {
                $zoneID = (int) $zone["zoneID"];
                $sql = '
                                        SELECT shipping_rate FROM ' . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TABLE . '
                                        WHERE module_id="' . $module_id . '" AND countryID=' . $curr_country . ' and zoneID=' . $zoneID . '
                                ';
                $q = db_query($sql);
                $row = db_fetch_row($q);
                $zone_shipping_rate = (double) $row[0];
                $res .= "<tr><td>" . $zone["zone_name"] . ":</td>";
                $res .= "<td><input type=text name=shipping_module_bycountry_byzone_zone_rate_" . $zoneID . " value='" . $zone_shipping_rate . "'>" . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_5 . "</td></tr>";
            }
            $res .= "</table>\n";
        } else {
            $res .= "<p>&lt; " . CSHIPPINGMODULEBYCOUNTRYBYZONEPERCENT_TXT_6 . " &gt;";
        }
        $res .= "</td></tr></table>\n";
        $res .= "</td></tr>\n";
    }
    $res .= "</table>";
    //javascript code
    if ($curr_country > 0) {
        $res .= "\n                                <script language='JavaScript'>\n                                function shipping_module_bycountry_byzone_toogleClickHandler()\n                                {\n\n                                        if ( document.shipping_method_form.shipping_module_bycountry_byzone_radiotoggle[0].checked )\n                                        {\n                                                document.shipping_method_form.shipping_module_bycountry_byzone_zone_rate_0.disabled = false;\n                                                " . _create_JS_zones_handlers_bycountryzone_percent($zones, "true") . "\n                                        }\n                                        else if ( document.shipping_method_form.shipping_module_bycountry_byzone_radiotoggle[1].checked )\n                                        {\n                                                document.shipping_method_form.shipping_module_bycountry_byzone_zone_rate_0.disabled = true;\n                                                " . _create_JS_zones_handlers_bycountryzone_percent($zones, "false") . "\n                                        }\n                                }\n\n                                shipping_module_bycountry_byzone_toogleClickHandler();\n                                </script>\n                ";
    }
    return $res;
}