Exemple #1
0
 function _getShippingCosts($shipping_methods, $order, $moduleFiles)
 {
     if (!isset($_SESSION["receiver_countryID"]) || !isset($_SESSION["receiver_zoneID"])) {
         return NULL;
     }
     $shipping_modules = modGetModules($moduleFiles);
     $shippingAddressID = 0;
     $shipping_costs = array();
     $res = cartGetCartContent();
     $sh_address = array("countryID" => $_SESSION["receiver_countryID"], "zoneID" => $_SESSION["receiver_zoneID"]);
     $addresses = array($sh_address, $sh_address);
     $j = 0;
     foreach ($shipping_methods as $shipping_method) {
         $_ShippingModule = modGetModuleObj($shipping_method["module_id"], SHIPPING_RATE_MODULE);
         if ($_ShippingModule) {
             if ($_ShippingModule->allow_shipping_to_address($sh_address)) {
                 $shipping_costs[$j] = oaGetShippingCostTakingIntoTax($res, $shipping_method["SID"], $addresses, $order);
             } else {
                 $shipping_costs[$j] = array(array('rate' => -1));
             }
         } else {
             $shipping_costs[$j] = oaGetShippingCostTakingIntoTax($res, $shipping_method["SID"], $addresses, $order);
         }
         $j++;
     }
     $_i = count($shipping_costs) - 1;
     for (; $_i >= 0; $_i--) {
         $_t = count($shipping_costs[$_i]) - 1;
         for (; $_t >= 0; $_t--) {
             if ($shipping_costs[$_i][$_t]['rate'] > 0) {
                 $shipping_costs[$_i][$_t]['rate'] = show_price($shipping_costs[$_i][$_t]['rate']);
             } else {
                 if (count($shipping_costs[$_i]) == 1 && $shipping_costs[$_i][$_t]['rate'] < 0) {
                     $shipping_costs[$_i] = 'n/a';
                 } else {
                     $shipping_costs[$_i][$_t]['rate'] = '';
                 }
             }
         }
     }
     return $shipping_costs;
 }
Exemple #2
0
 function _getOrder()
 {
     $cust_password = "";
     $Email = "";
     $first_name = "";
     $last_name = "";
     $subscribed4news = "";
     $additional_field_values = "";
     $countryID = "";
     $zoneID = "";
     $state = "";
     $city = "";
     $address = "";
     regGetCustomerInfo($_SESSION["log"], $cust_password, $Email, $first_name, $last_name, $subscribed4news, $additional_field_values, $countryID, $zoneID, $state, $city, $address);
     $order["first_name"] = $first_name;
     $order["last_name"] = $last_name;
     $order["email"] = $Email;
     $res = cartGetCartContent();
     $order["orderContent"] = $res["cart_content"];
     $d = oaGetDiscountPercent($res, $_SESSION["log"]);
     $order["order_amount"] = $res["total_price"] - $res["total_price"] / 100 * $d;
     return $order;
 }
Exemple #3
0
                $t = db_query($sql);
                $rr = db_fetch_row($t);
                $sum = priceСost((int) $_SESSION['gids'][$i], $rr['Price']);
                if (is_array($_SESSION['configurations'][$i])) {
                    foreach ($_SESSION['configurations'][$i] as $vars) {
                        $sql = '
                        SELECT
                        price_surplus
                        FROM ' . PRODUCTS_OPTIONS_SET_TABLE . '
                        WHERE variantID=' . (int) $vars . ' AND productID=' . (int) $_SESSION['gids'][$i];
                        $q1 = db_query($sql);
                        $r1 = db_fetch_row($q1);
                        $sum += $r1['price_surplus'];
                    }
                }
                $k += $_SESSION['counts'][$i] * $sum;
                $cnt += $_SESSION['counts'][$i];
            }
        }
    }
}
$cart = cartGetCartContent();
if (!empty($cart['cart_content'])) {
    $qty = 0;
    foreach ($cart['cart_content'] as $k => $v) {
        $qty += $v['quantity'];
    }
}
//$smarty->assign('shopping_cart_value', $k);
$smarty->assign('shopping_cart_value_shown', show_price($cart['total_price']));
$smarty->assign('shopping_cart_items', (int) $qty);
function cartCheckMinTotalOrderAmount()
{
    $res = cartGetCartContent();
    $d = oaGetDiscountValue($res, "");
    $order["order_amount"] = $res["total_price"] - $d;
    return $order["order_amount"] < CONF_MINIMAL_ORDER_AMOUNT ? false : true;
}
Exemple #5
0
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);
}
        }
        $k += $price;
        $cnt += $quantity;
    }
} elseif (isset($_SESSION["gids"])) {
    //...session vars
    for ($i = 0; $i < count($_SESSION["gids"]); $i++) {
        if (!$_SESSION["gids"][$i]) {
            continue;
        }
        $sum = db_phquery_fetch(DBRFETCH_FIRST, "SELECT Price FROM ?#PRODUCTS_TABLE WHERE productID=?", $_SESSION["gids"][$i]);
        foreach ($_SESSION["configurations"][$i] as $var) {
            $sum += db_phquery_fetch(DBRFETCH_FIRST, "SELECT price_surplus FROM ?#PRODUCTS_OPTIONS_SET_TABLE WHERE variantID=? AND productID=?", $var, $_SESSION["gids"][$i]);
        }
        if ($_SESSION["sample"][$i]) {
            $quantity = 1;
            $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$i]);
            $sample_price = db_fetch_assoc($q_sample_price);
            $sum = $sample_price["sample_price"];
        } else {
            $quantity = $_SESSION["counts"][$i];
        }
        $k += $quantity * $sum;
        $cnt += $quantity;
    }
}
$d = oaGetDiscountValue(cartGetCartContent(), is_null($customerEntry) ? null : $customerEntry->Login);
$k = $k - $d;
$smarty->assign("shopping_cart_value", $k);
$smarty->assign("shopping_cart_value_shown", show_price($k));
$smarty->assign("shopping_cart_items", $cnt);
Exemple #7
0
function cartCheckMinTotalOrderAmount()
{
    $res = cartGetCartContent();
    $d = oaGetDiscountPercent($res, '');
    $order['order_amount'] = $res['total_price'] - $res['total_price'] / 100 * $d;
    if ($order['order_amount'] < CONF_MINIMAL_ORDER_AMOUNT) {
        return false;
    } else {
        return true;
    }
}
 function main()
 {
     $Register =& Register::getInstance();
     $smarty =& $Register->get(VAR_SMARTY);
     /*@var $smarty Smarty*/
     // shopping cart
     //iframe cookie security workaround
     if (isset($_GET['check_cookie'])) {
         if ($_GET['check_cookie'] != session_id()) {
             $productID = (int) $_GET['productID'];
             $product_data = GetProduct($productID);
             $product_slug = $product_data && isset($product_data['slug']) ? $product_data['slug'] : '';
             $url = "?ukey=product_widget&productID={$productID}&product_slug={$product_slug}&check_cookie&";
             $widgets = false;
             $Register->set('widgets', $widgets);
             $_SERVER['REQUEST_URI'] = preg_replace('/(^|&)widgets=1/', '', $_SERVER['REQUEST_URI']);
             RedirectSQ($url);
         } else {
             renderURL('check_cookie&productID', '', true);
         }
     }
     if (isset($_GET["make_more_exact_cart_content"])) {
         $smarty->assign("make_more_exact_cart_content", 1);
     }
     if (isset($_GET["remove"]) && $_GET["remove"] > 0) {
         //remove from cart product with productID == $remove
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->setItemQuantity($_GET['remove'], 0);
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         RedirectSQ('remove=');
     }
     $cart_view = $this->_detect_cart_view();
     if (isset($_POST["update"]) || isset($_POST["recalculate"])) {
         //update shopping cart content
         if ($_POST['discount_coupon_code'] != '') {
             $this->_check_and_apply_coupon($_POST['discount_coupon_code']);
         }
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $upd_data = scanArrayKeysForID($_POST, 'count');
         foreach ($upd_data as $_itemID => $_data) {
             $cartEntry->setItemQuantity($_itemID, intval($_data['count']));
         }
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         if (cartCheckMinOrderAmount() && cartCheckMinTotalOrderAmount()) {
             switch ($cart_view) {
                 case CARTVIEW_FRAME:
                     if (isset($_POST['checkout']) && $Register->get('store_mode') == 'facebook') {
                         $store_mode = false;
                         $Register->set('store_mode', $store_mode);
                         $jsgoto = '?ukey=checkout&view=noframe';
                         RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     }
                     RedirectSQ(isset($_POST['checkout']) ? '?ukey=checkout' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1' : '')));
                     break;
                 case CARTVIEW_WIDGET:
                 case CARTVIEW_FADE:
                     $jsgoto = isset($_POST['checkout']) ? '?ukey=checkout&view=noframe' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1&view=frame' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1&view=frame' : ''));
                     RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     break;
             }
         } elseif (isset($_POST['checkout']) || isset($_POST['google_checkout_x']) || isset($_POST['ppe_checkout_x'])) {
             $smarty->assign('cart_error_show', '1');
         }
     }
     if (isset($_GET["clear_cart"])) {
         //completely clear shopping cart
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->cleanCurrentCart('erase');
         //remove coupon from empty cart
         ClassManager::includeClass('discount_coupon');
         discount_coupon::remove();
         RedirectSQ('clear_cart=');
     }
     if (isset($_POST['checkout'])) {
         if (SystemSettings::is_hosted() && file_exists(WBS_DIR . '/kernel/classes/class.metric.php')) {
             include_once WBS_DIR . '/kernel/classes/class.metric.php';
             $DB_KEY = SystemSettings::get('DB_KEY');
             $U_ID = sc_getSessionData('U_ID');
             $metric = metric::getInstance();
             $metric->addAction($DB_KEY, $U_ID, 'SC', 'CHECKOUT', isset($_GET['widgets']) ? 'WIDGET' : 'STOREFRONT', '');
         }
     }
     $resCart = cartGetCartContent();
     $resDiscount = dscGetCartDiscounts($resCart["total_price"], isset($_SESSION["log"]) ? $_SESSION["log"] : "");
     $currencyEntry = Currency::getSelectedCurrencyInstance();
     $cart_discount_show = $resDiscount['other_discounts']['cu'] > 0 ? $currencyEntry->getView($resDiscount['other_discounts']['cu']) : '';
     $coupon_discount_show = $resDiscount['coupon_discount']['cu'] > 0 ? $currencyEntry->getView($resDiscount['coupon_discount']['cu']) : '';
     $smarty->assign("cart_content", xHtmlSpecialChars($resCart["cart_content"], null, 'name'));
     $smarty->assign("cart_amount", $resCart["total_price"] - $resDiscount["discount_standart_unit"]);
     $smarty->assign('cart_min', show_price(CONF_MINIMAL_ORDER_AMOUNT));
     $smarty->assign("cart_total", $currencyEntry->getView($resDiscount['total']['cu']));
     $smarty->assign('cart_discount', $cart_discount_show);
     $smarty->assign('discount_percent', round($resDiscount['discount_percent'], 1));
     $smarty->assign('coupon_discount', $coupon_discount_show);
     $smarty->assign("current_coupon", discount_coupon::getCurrentCoupon());
     if (isset($_SESSION['log'])) {
         $smarty->assign('shippingAddressID', regGetDefaultAddressIDByLogin($_SESSION['log']));
     }
     if (isset($_GET['min_order'])) {
         $smarty->assign('minOrder', 'error');
     }
     if (isset($_GET['jsgoto'])) {
         $smarty->assign('jsgoto', base64_decode($_GET['jsgoto']));
     }
     $smarty->assign('main_content_template', 'shopping_cart.html');
     $smarty->assign('main_body_style', 'style="' . (CONF_SHOPPING_CART_VIEW == 2 || $cart_view == CARTVIEW_FRAME ? '' : 'background:#FFFFFF;') . 'min-width:auto;width:auto;_width:auto;"');
 }