function oaGetProductTax($cartContent, $d, $addresses) { $res = 0; for ($i = 0; $i < count($cartContent["cart_content"]); $i++) { $cartItem = $cartContent["cart_content"][$i]; $q = db_query("select count(*) from " . PRODUCTS_TABLE . " where productID=" . (int) $cartItem["productID"]); $count = db_fetch_row($q); if ($count[0] == 0) { continue; } $cartItem = $cartContent["cart_content"][$i]; $price = $cartItem["costUC"] - $cartItem["costUC"] / 100 * $d; $price = $price * $cartItem["quantity"]; if (is_array($addresses[0])) { $tax = taxCalculateTax2($cartItem["productID"], $addresses[0], $addresses[1]); } else { $tax = taxCalculateTax($cartItem["productID"], $addresses[0], $addresses[1]); } $res += $tax; } return $res; }
function getOrderSummarize($shippingMethodID, $paymentMethodID, $shippingAddressID, $billingAddressID, $shippingModuleFiles, $paymentModulesFiles, $shServiceID = 0) { // result this function $sumOrderContent = array(); $q = db_query('select email_comments_text from ' . PAYMENT_TYPES_TABLE . ' where PID=' . (int) $paymentMethodID); $payment_email_comments_text = db_fetch_row($q); $payment_email_comments_text = $payment_email_comments_text[0]; $q = db_query('select email_comments_text from ' . SHIPPING_METHODS_TABLE . ' where SID=' . (int) $shippingMethodID); $shipping_email_comments_text = db_fetch_row($q); $shipping_email_comments_text = $shipping_email_comments_text[0]; $cartContent = cartGetCartContent(); $pred_total = oaGetClearPrice($cartContent); if (isset($_SESSION['log'])) { $log = $_SESSION['log']; } else { $log = null; } $d = oaGetDiscountPercent($cartContent, $log); $discount = $pred_total / 100 * $d; // ordering with registration if ($shippingAddressID != 0 || isset($log)) { $addresses = array($shippingAddressID, $billingAddressID); $shipping_address = regGetAddressStr($shippingAddressID); $billing_address = regGetAddressStr($billingAddressID); $shaddr = regGetAddress($shippingAddressID); $sh_firstname = $shaddr['first_name']; $sh_lastname = $shaddr['last_name']; } else { if (!isset($_SESSION['receiver_countryID']) || !isset($_SESSION['receiver_zoneID'])) { return NULL; } $shippingAddress = array('countryID' => $_SESSION['receiver_countryID'], 'zoneID' => $_SESSION['receiver_zoneID']); $billingAddress = array('countryID' => $_SESSION['billing_countryID'], 'zoneID' => $_SESSION['billing_zoneID']); $addresses = array($shippingAddress, $billingAddress); $shipping_address = quickOrderGetReceiverAddressStr(); $billing_address = quickOrderGetBillingAddressStr(); $sh_firstname = $_SESSION['receiver_first_name']; $sh_lastname = $_SESSION['receiver_last_name']; } foreach ($cartContent['cart_content'] as $key => $cartItem) { // if conventional ordering if ($shippingAddressID != 0) { $productID = GetProductIdByItemId($cartItem['id']); $cartItem['tax'] = taxCalculateTax($productID, $addresses[0], $addresses[1]); } else { $productID = $cartItem['id']; $cartItem['tax'] = taxCalculateTax2($productID, $addresses[0], $addresses[1]); } if (!empty($cartItem['opt_margin']) && $paymentMethodID == 2) { $cost = $cartItem['costUC']; $margin = $cost / 100 * CONF_PERCENT_MARGIN; $cost += $margin; $costShow = show_price($cost * $cartItem['quantity']); $pred_total += $margin * $cartItem['quantity']; $cartContent['cart_content'][$key]['costUC'] = $cost; $cartContent['cart_content'][$key]['cost'] = $costShow; $cartItem['costUC'] = $cost; $cartItem['cost'] = $costShow; } $sumOrderContent[] = $cartItem; } $shipping_method = shGetShippingMethodById($shippingMethodID); if (!$shipping_method) { $shipping_name = '-'; } else { $shipping_name = $shipping_method['Name']; } $payment_method = payGetPaymentMethodById($paymentMethodID); if (!$payment_method) { $payment_name = '-'; } else { $payment_name = $payment_method['Name']; } //do not calculate tax for this payment type! if (isset($payment_method['calculate_tax']) && (int) $payment_method['calculate_tax'] == 0) { foreach ($sumOrderContent as $key => $val) { $sumOrderContent[$key]['tax'] = 0; } $orderDetails = array('first_name' => $sh_firstname, 'last_name' => $sh_lastname, 'email' => '', 'order_amount' => oaGetOrderAmountExShippingRate($cartContent, $addresses, $log, FALSE, $shServiceID)); $tax = 0; $total = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, FALSE, $shServiceID); $shipping_cost = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, FALSE, $shServiceID); } else { $orderDetails = array('first_name' => $sh_firstname, 'last_name' => $sh_lastname, 'email' => '', 'order_amount' => oaGetOrderAmountExShippingRate($cartContent, $addresses, $log, FALSE)); $tax = oaGetProductTax($cartContent, $d, $addresses); $total = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, TRUE, $shServiceID); $shipping_cost = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, TRUE, $shServiceID); } $tServiceInfo = null; if (is_array($shipping_cost)) { $_T = array_shift($shipping_cost); $tServiceInfo = $_T['name']; $shipping_cost = $_T['rate']; } $payment_form_html = ''; $paymentModule = modGetModuleObj($payment_method['module_id'], PAYMENT_MODULE); if ($paymentModule) { $order = array(); $address = array(); if ($shippingAddressID != 0) { $payment_form_html = $paymentModule->payment_form_html(array('BillingAddressID' => $billingAddressID)); } else { $payment_form_html = $paymentModule->payment_form_html(array('countryID' => $_SESSION['billing_countryID'], 'zoneID' => $_SESSION['billing_zoneID'], 'first_name' => $_SESSION['billing_first_name'], 'last_name' => $_SESSION['billing_last_name'], 'city' => $_SESSION['billing_city'], 'address' => $_SESSION['billing_address'])); } } return array('sumOrderContent' => $sumOrderContent, 'discount' => $discount, 'discount_percent' => $d, 'discount_show' => show_price($discount), 'pred_total_disc' => show_price($pred_total * ((100 - $d) / 100)), 'pred_total' => show_price($pred_total), 'totalTax' => show_price($tax), 'totalTaxUC' => $tax, 'shipping_address' => $shipping_address, 'billing_address' => $billing_address, 'shipping_name' => $shipping_name, 'payment_name' => $payment_name, 'shipping_cost' => show_price($shipping_cost), 'shipping_costUC' => $shipping_cost, 'payment_form_html' => $payment_form_html, 'total' => show_price($total), 'totalUC' => $total, 'payment_email_comments_text' => $payment_email_comments_text, 'shipping_email_comments_text' => $shipping_email_comments_text, 'orderContentCartProductsCount' => count($sumOrderContent), 'shippingServiceInfo' => $tServiceInfo); }
/** * @param int $orderID * @param array $shipping_info - ('countryID','zoneID', 'zip') * @param array $billing_info - ('countryID','zoneID', 'zip') */ function saveToOrderedCarts($orderID, $shipping_info, $billing_info, $calculate_tax = true) { $sql = "DELETE FROM ?#ORDERED_CARTS_TABLE WHERE orderID=?"; db_phquery($sql, $orderID); $r_aItem = $this->Items->getChildNodes('item'); $tc = count($r_aItem); for ($i = 0; $i < $tc; $i++) { $aItem =& $r_aItem[$i]; /* @var $aItem xmlNodeX */ $aProduct =& $aItem->getFirstChildByName('product'); $productID = $aProduct->attribute('id'); db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)', $productID); $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); //if(strpos($aItem->attribute('id'), '_') !== false){ // db_phquery('INSERT ?#SHOPPING_CART_ITEMS_TABLE (productID) VALUES(?)',$productID); // $aItem->attribute('id', db_insert_id(SHOPPING_CART_ITEMS_TABLE)); $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ db_phquery('INSERT ?#SHOPPING_CART_ITEMS_CONTENT_TABLE (itemID, variantID) VALUES(?,?)', $aItem->attribute('id'), $aVariant->attribute('id')); } //} $dbq = ' SELECT ' . LanguagesManager::sql_prepareField('name') . ' AS name, product_code, categoryID FROM ?#PRODUCTS_TABLE WHERE productID=? '; $q_product = db_phquery($dbq, $productID); $product = db_fetch_row($q_product); $productComplexName = ''; $aVariants =& $aItem->getFirstChildByName('variants'); $r_aVariant = $aVariants->getChildrenByName('variant'); $variants = array(); foreach ($r_aVariant as $aVariant) { /* @var $aVariant xmlNodeX */ $variants[] = $aVariant->attribute('id'); } $options = GetStrOptions($variants); if ($options != "") { $productComplexName = $product["name"] . " (" . $options . ")"; } else { $productComplexName = $product["name"]; } if ($product["product_code"]) { $productComplexName = "[" . $product["product_code"] . "] " . $productComplexName; } $price = GetPriceProductWithOption($variants, $productID); if ($aItem->getChildData('sample')) { $productComplexName .= " [SAMPLE]"; $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $productID); $sample_price = db_fetch_assoc($q_sample_price); $price = $sample_price["sample_price"]; $quantity = 1; } else { $quantity = $aItem->getChildData('quantity'); } $tax = $calculate_tax ? taxCalculateTax2($productID, $shipping_info, $billing_info) : 0; $dbq = ' INSERT ?#ORDERED_CARTS_TABLE (itemID, orderID, name, Price, Quantity, tax ) VALUES (?, ?, ?, ?, ?, ?) '; db_phquery($dbq, $aItem->attribute('id'), $orderID, $productComplexName, $price, $quantity, $tax); $q = db_phquery('SELECT statusID FROM ?#ORDERS_TABLE WHERE orderID=?', $orderID); $order = db_fetch_row($q); if ($order["statusID"] != ostGetCanceledStatusId() && CONF_CHECKSTOCK) { $dbq = ' UPDATE ?#PRODUCTS_TABLE SET in_stock=in_stock-' . xEscapeSQLstring($quantity) . ' WHERE productID=? '; db_phquery($dbq, $productID); } } }
function taxCalculateTax($productID, $shippingAddressID, $billingAddressID) { $shippingAddress = regGetAddress($shippingAddressID); $billingAddress = regGetAddress($billingAddressID); return taxCalculateTax2($productID, $shippingAddress, $billingAddress); }