예제 #1
0
        Quantity
        FROM ' . SHOPPING_CARTS_TABLE . '
        WHERE customerID= ' . regGetIdByLogin($_SESSION['log']);
    $q = db_query($sql);
    unset($_SESSION['special_set']['cart']);
    while ($row = db_fetch_row($q)) {
        $sql = '
            SELECT
            productID
            FROM ' . SHOPPING_CART_ITEMS_TABLE . '
            WHERE itemID=' . $row['itemID'];
        $q1 = db_query($sql);
        $r1 = db_fetch_row($q1);
        if ($r1['productID']) {
            $_SESSION['special_set']['cart'][] = $r1['productID'];
            $variants = GetConfigurationByItemId($row['itemID']);
            $k += GetPriceProductWithOption($variants, $r1['productID']) * $row['Quantity'];
            $cnt += $row['Quantity'];
        }
    }
} else {
    //...session vars
    if (isset($_SESSION['gids'])) {
        $_SESSION['special_set']['cart'] = array_unique($_SESSION['gids']);
        for ($i = 0; $i < count($_SESSION['gids']); $i++) {
            if ($_SESSION['gids'][$i]) {
                $sql = '
                    SELECT
                    Price
                    FROM ' . PRODUCTS_TABLE . '
                    WHERE productID=' . (int) $_SESSION['gids'][$i];
예제 #2
0
function _sendOrderNotifycationToAdmin($orderID, &$smarty_mail, $tax)
{
    $order = _getOrderById($orderID);
    $smarty_mail->assign('customer_firstname', $order['customer_firstname']);
    $smarty_mail->assign('customer_lastname', $order['customer_lastname']);
    $smarty_mail->assign('customer_email', $order['customer_email']);
    $smarty_mail->assign('customer_ip', $order['customer_ip']);
    $smarty_mail->assign('order_time', format_datetime($order['order_time']));
    $smarty_mail->assign('customer_comments', $order['customers_comment']);
    $smarty_mail->assign('discount', $order['order_discount']);
    $smarty_mail->assign('shipping_type', $order['shipping_type']);
    $smarty_mail->assign('shipping_cost', _formatPrice(roundf($order['currency_value'] * $order['shipping_cost']), $order['currency_round']) . ' ' . $order['currency_code']);
    $smarty_mail->assign('payment_type', $order['payment_type']);
    $smarty_mail->assign('shipping_firstname', $order['shipping_firstname']);
    $smarty_mail->assign('shipping_lastname', $order['shipping_lastname']);
    $smarty_mail->assign('shipping_country', $order['shipping_country']);
    $smarty_mail->assign('shipping_state', $order['shipping_state']);
    $smarty_mail->assign('shipping_city', $order['shipping_city']);
    $smarty_mail->assign('shipping_address', chop($order['shipping_address']));
    $smarty_mail->assign('billing_firstname', $order['billing_firstname']);
    $smarty_mail->assign('billing_lastname', $order['billing_lastname']);
    $smarty_mail->assign('billing_country', $order['billing_country']);
    $smarty_mail->assign('billing_state', $order['billing_state']);
    $smarty_mail->assign('billing_city', $order['billing_city']);
    $smarty_mail->assign('billing_address', chop($order['billing_address']));
    $smarty_mail->assign('order_amount', _formatPrice(roundf($order['currency_value'] * $order['order_amount']), $order['currency_round']) . ' ' . $order['currency_code']);
    $smarty_mail->assign('orderID', $order['orderID']);
    $smarty_mail->assign('total_tax', _formatPrice(roundf($order['currency_value'] * $tax), $order['currency_round']) . ' ' . $order['currency_code']);
    $smarty_mail->assign('shippingServiceInfo', $order['shippingServiceInfo']);
    $smarty_mail->assign('tax', $tax);
    // clear cost ( without shipping, discount, tax )
    $q1 = db_query('select Price, Quantity from ' . ORDERED_CARTS_TABLE . ' where orderID=' . (int) $orderID);
    $clear_total_price = 0;
    while ($row = db_fetch_row($q1)) {
        $clear_total_price += $row['Price'] * $row['Quantity'];
    }
    $order_discount_ToShow = _formatPrice(roundf($order['currency_value'] * $clear_total_price * ((100 - $order['order_discount']) / 100)), $order['currency_round']) . ' ' . $order['currency_code'];
    $smarty_mail->assign('order_discount_ToShow', $order_discount_ToShow);
    //additional reg fields
    $addregfields = GetRegFieldsValuesByOrderID($orderID);
    $smarty_mail->assign('customer_add_fields', $addregfields);
    //fetch order content from the database
    $content = ordGetOrderContent($orderID);
    for ($i = 0; $i < count($content); $i++) {
        $productID = GetProductIdByItemId($content[$i]['itemID']);
        if ($productID == null || trim($productID) == '') {
            continue;
        }
        $q = db_query('select name, product_code, default_picture from ' . PRODUCTS_TABLE . ' where productID=' . (int) $productID);
        $product = db_fetch_row($q);
        $content[$i]['product_code'] = $product['product_code'];
        $content[$i]['product_idn'] = $productID;
        /*
        $qz = db_query('select filename FROM '.PRODUCT_PICTURES.' WHERE photoID='.$product['default_picture'].' AND productID='.$productID);
        $rowz = db_fetch_row($qz);
        if (strlen($rowz['filename'])>0 && file_exists( 'data/small/'.$rowz['filename']))
        $content[$i]['product_picture'] = $rowz['filename'];
        else $content[$i]['product_picture'] = null;
        */
        $variants = GetConfigurationByItemId($content[$i]['itemID']);
        $options = GetStrOptions($variants);
        if ($options != '') {
            $content[$i]['name'] = $product['name'] . '(' . $options . ')';
        } else {
            $content[$i]['name'] = $product['name'];
        }
    }
    $smarty_mail->assign('content', $content);
    $html = $smarty_mail->fetch('admin_order_notification.tpl');
    if (!CONF_ACTIVE_ORDER) {
        xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER . ' #' . $orderID . ' - ' . CONF_SHOP_NAME, $html);
    } else {
        xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER . ' #' . $orderID . ' (' . ADMIN_SEND_INACT_ORDER . ') - ' . CONF_SHOP_NAME, $html);
    }
}
/**
 * @return array
 */
function cartGetCartContent()
{
    $cart_content = array();
    $total_price = 0;
    $freight_cost = 0;
    $variants = '';
    $currencyEntry = Currency::getSelectedCurrencyInstance();
    $customerEntry = Customer::getAuthedInstance();
    if (!is_null($customerEntry)) {
        //get cart content from the database
        $q = db_phquery('
			SELECT t3.*, t1.itemID, t1.Quantity, t1.sample, t4.thumbnail FROM ?#SHOPPING_CARTS_TABLE t1
				LEFT JOIN ?#SHOPPING_CART_ITEMS_TABLE t2 ON t1.itemID=t2.itemID
				LEFT JOIN ?#PRODUCTS_TABLE t3 ON t2.productID=t3.productID
				LEFT JOIN ?#PRODUCT_PICTURES t4 ON t3.default_picture=t4.photoID
			WHERE customerID=?', $customerEntry->customerID);
        while ($cart_item = db_fetch_assoc($q)) {
            // get variants
            $variants = GetConfigurationByItemId($cart_item["itemID"]);
            LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $cart_item);
            if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) {
                $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $cart_item["productID"]);
                $sample_price = db_fetch_assoc($q_sample_price);
                $costUC = $sample_price["sample_price"];
                $quantity = 1;
                $free_shipping = 1;
            } else {
                $costUC = GetPriceProductWithOption($variants, $cart_item["productID"]);
                $quantity = $cart_item["Quantity"];
                $free_shipping = $cart_item["free_shipping"];
            }
            $tmp = array("productID" => $cart_item["productID"], "slug" => $cart_item["slug"], "id" => $cart_item["itemID"], "name" => $cart_item["name"], 'thumbnail_url' => $cart_item['thumbnail'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail']) ? URL_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail'] : '', "brief_description" => $cart_item["brief_description"], "quantity" => $quantity, "free_shipping" => $free_shipping, "costUC" => $costUC, "product_priceWithUnit" => show_price($costUC), "cost" => show_price($quantity * $costUC), "product_code" => $cart_item["product_code"]);
            if ($tmp['thumbnail_url']) {
                list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $cart_item['thumbnail']);
                list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE / 2), round(CONF_PRDPICT_THUMBNAIL_SIZE / 2));
            }
            $freight_cost += $cart_item["Quantity"] * $cart_item["shipping_freight"];
            $strOptions = GetStrOptions(GetConfigurationByItemId($tmp["id"]));
            if (trim($strOptions) != "") {
                $tmp["name"] .= "  (" . $strOptions . ")";
            }
            if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) {
                $tmp["name"] .= " [SAMPLE]";
            }
            if ($cart_item["min_order_amount"] > $cart_item["Quantity"]) {
                $tmp["min_order_amount"] = $cart_item["min_order_amount"];
            }
            if ($cart_item["min_order_amount"] > 1 && $cart_item["Quantity"] % $cart_item["min_order_amount"] != 0) {
                $tmp["multiplicity"] = $cart_item["min_order_amount"];
            }
            if (isset($cart_item["sample"]) && $cart_item["sample"] == 1) {
                unset($tmp["min_order_amount"]);
                unset($tmp["multiplicity"]);
                $tmp["sample"] = 1;
            }
            $total_price += $quantity * $costUC;
            $cart_content[] = $tmp;
        }
    } else {
        //unauthorized user - get cart from session vars
        $total_price = 0;
        //total cart value
        $cart_content = array();
        //shopping cart items count
        if (isset($_SESSION["gids"])) {
            for ($j = 0; $j < count($_SESSION["gids"]); $j++) {
                if ($_SESSION["gids"][$j]) {
                    $session_items[] = CodeItemInClient($_SESSION["configurations"][$j], $_SESSION["gids"][$j]);
                    $q = db_phquery("SELECT t1.*, p1.thumbnail FROM ?#PRODUCTS_TABLE t1 LEFT JOIN ?#PRODUCT_PICTURES p1 ON t1.default_picture=p1.photoID WHERE t1.productID=?", $_SESSION["gids"][$j]);
                    if ($r = db_fetch_row($q)) {
                        LanguagesManager::ml_fillFields(PRODUCTS_TABLE, $r);
                        if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) {
                            $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$j]);
                            $sample_price = db_fetch_assoc($q_sample_price);
                            $costUC = $sample_price["sample_price"];
                            $quantity = 1;
                            $free_shipping = 1;
                        } else {
                            $costUC = GetPriceProductWithOption($_SESSION["configurations"][$j], $_SESSION["gids"][$j]);
                            $quantity = $_SESSION["counts"][$j];
                            $free_shipping = $r["free_shipping"];
                        }
                        $id = $_SESSION["gids"][$j];
                        if (count($_SESSION["configurations"][$j]) > 0) {
                            for ($tmp1 = 0; $tmp1 < count($_SESSION["configurations"][$j]); $tmp1++) {
                                $id .= "_" . $_SESSION["configurations"][$j][$tmp1];
                            }
                        }
                        $tmp = array("productID" => $_SESSION["gids"][$j], "slug" => $r['slug'], "id" => $id, "name" => $r['name'], 'thumbnail_url' => $r['thumbnail'] && file_exists(DIR_PRODUCTS_PICTURES . '/' . $r['thumbnail']) ? URL_PRODUCTS_PICTURES . '/' . $r['thumbnail'] : '', "brief_description" => $r["brief_description"], "quantity" => $quantity, "free_shipping" => $free_shipping, "costUC" => $costUC, "product_priceWithUnit" => show_price($costUC), "cost" => show_price($costUC * $quantity));
                        if ($tmp['thumbnail_url']) {
                            list($thumb_width, $thumb_height) = getimagesize(DIR_PRODUCTS_PICTURES . '/' . $r['thumbnail']);
                            list($tmp['thumbnail_width'], $tmp['thumbnail_height']) = shrink_size($thumb_width, $thumb_height, round(CONF_PRDPICT_THUMBNAIL_SIZE / 2), round(CONF_PRDPICT_THUMBNAIL_SIZE / 2));
                        }
                        $strOptions = GetStrOptions($_SESSION["configurations"][$j]);
                        if (trim($strOptions) != "") {
                            $tmp["name"] .= "  (" . $strOptions . ")";
                        }
                        if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) {
                            $tmp["name"] .= " [SAMPLE]";
                        }
                        $q_product = db_query("select min_order_amount, shipping_freight from " . PRODUCTS_TABLE . " where productID=" . $_SESSION["gids"][$j]);
                        $product = db_fetch_row($q_product);
                        if ($product["min_order_amount"] > $_SESSION["counts"][$j]) {
                            $tmp["min_order_amount"] = $product["min_order_amount"];
                        }
                        if ($product["min_order_amount"] > 1 && $_SESSION["counts"][$j] % $product["min_order_amount"] != 0) {
                            $tmp["multiplicity"] = $product["min_order_amount"];
                        }
                        if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) {
                            unset($tmp["min_order_amount"]);
                            unset($tmp["multiplicity"]);
                            $tmp["sample"] = 1;
                        }
                        $freight_cost += $_SESSION["counts"][$j] * $product["shipping_freight"];
                        $cart_content[] = $tmp;
                        if (isset($_SESSION["sample"][$j]) && $_SESSION["sample"][$j] == 1) {
                            $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $_SESSION["gids"][$j]);
                            $sample_price = db_fetch_assoc($q_sample_price);
                            $total_price += $sample_price["sample_price"];
                        } else {
                            $total_price += GetPriceProductWithOption($_SESSION["configurations"][$j], $_SESSION["gids"][$j]) * $_SESSION["counts"][$j];
                        }
                    }
                }
            }
        }
    }
    return array("cart_content" => $cart_content, "total_price" => $total_price, "freight_cost" => $freight_cost);
}
 * Shopping cart brief info
 */
/*
 * @depracated: since 299
 */
$customerEntry = Customer::getAuthedInstance();
$k = 0;
$cnt = 0;
$variants = array();
if (!is_null($customerEntry)) {
    //taking products from database
    $q = db_phquery("SELECT itemID, Quantity, sample FROM ?#SHOPPING_CARTS_TABLE WHERE customerID=?", $customerEntry->customerID);
    while ($row = db_fetch_assoc($q)) {
        $q1 = db_query("select productID from " . SHOPPING_CART_ITEMS_TABLE . " where itemID='" . $row["itemID"] . "'");
        $r1 = db_fetch_row($q1);
        $variants = GetConfigurationByItemId($row["itemID"]);
        if ($row["sample"]) {
            $quantity = 1;
            $q_sample_price = db_phquery('SELECT sample_price FROM SC_categories WHERE categoryID=(SELECT categoryID FROM SC_products WHERE productID=?)', $r1["productID"]);
            $sample_price = db_fetch_assoc($q_sample_price);
            $price = $sample_price["sample_price"];
        } else {
            $quantity = $row["Quantity"];
            $price = GetPriceProductWithOption($variants, $r1["productID"]) * $quantity;
        }
        $k += $price;
        $cnt += $quantity;
    }
} elseif (isset($_SESSION["gids"])) {
    //...session vars
    for ($i = 0; $i < count($_SESSION["gids"]); $i++) {
예제 #5
0
function moveCartFromSession2DB()
{
    if (isset($_SESSION["gids"]) && isset($_SESSION["log"])) {
        $customerID = regGetIdByLogin($_SESSION["log"]);
        $q = db_query("select itemID from " . SHOPPING_CARTS_TABLE . " where customerID=" . $customerID);
        $items = array();
        while ($item = db_fetch_row($q)) {
            $items[] = $item["itemID"];
        }
        //$i=0;
        foreach ($_SESSION["gids"] as $key => $productID) {
            if ($productID == 0) {
                continue;
            }
            // search product in current user's shopping cart content
            $itemID = null;
            for ($j = 0; $j < count($items); $j++) {
                $q = db_query("select count(*) from " . SHOPPING_CART_ITEMS_TABLE . " where productID=" . $productID . " AND " . " itemID=" . $items[$j]);
                $count = db_fetch_row($q);
                $count = $count[0];
                if ($count != 0) {
                    // compare configuration
                    $configurationFromSession = $_SESSION["configurations"][$key];
                    $configurationFromDB = GetConfigurationByItemId($items[$j]);
                    if (CompareConfiguration($configurationFromSession, $configurationFromDB)) {
                        $itemID = $items[$j];
                        break;
                    }
                    $itemID = $items[$j];
                }
            }
            if ($itemID == null) {
                // create new item
                db_query("insert into " . SHOPPING_CART_ITEMS_TABLE . " (productID) values('" . $productID . "')\n");
                $itemID = db_insert_id();
                // set content item
                foreach ($_SESSION["configurations"][$key] as $var) {
                    db_query("insert into " . SHOPPING_CART_ITEMS_CONTENT_TABLE . " ( itemID, variantID ) " . " values( '" . $itemID . "', '" . $var . "' )\n");
                }
                if ($_SESSION["sample"][$key]) {
                    $quantity = 1;
                    $sample = 1;
                } else {
                    $quantity = $_SESSION["counts"][$key];
                    $sample = 0;
                }
                // insert item into cart
                db_query("insert " . SHOPPING_CARTS_TABLE . "(customerID, itemID, Quantity, sample)" . "values( '" . $customerID . "', '" . $itemID . "', '" . $quantity . "', '" . $sample . "' )\n");
            } else {
                if (!$_SESSION["sample"][$key]) {
                    db_query("update " . SHOPPING_CARTS_TABLE . " set Quantity=Quantity + " . $_SESSION["counts"][$key] . " " . " where customerID=" . $customerID . " and itemID=" . $itemID . "\n");
                }
            }
        }
        unset($_SESSION["gids"]);
        unset($_SESSION["counts"]);
        unset($_SESSION["configurations"]);
        unset($_SESSION["sample"]);
    }
}
예제 #6
0
function cartGetCartContent()
{
    $cart_content = array();
    $total_price = 0;
    $freight_cost = 0;
    if (isset($_SESSION['log'])) {
        //get cart content from the database
        $sql = '
            SELECT
            itemID,
            Quantity
            FROM ' . SHOPPING_CARTS_TABLE . '
            WHERE customerID=' . (int) regGetIdByLogin($_SESSION['log']);
        $q = db_query($sql);
        while ($cart_item = db_fetch_row($q)) {
            // get variants
            $variants = GetConfigurationByItemId($cart_item['itemID']);
            // shopping cart item
            $sql = '
               SELECT
               productID
               FROM ' . SHOPPING_CART_ITEMS_TABLE . '
               WHERE itemID=' . (int) $cart_item['itemID'];
            $q_shopping_cart_item = db_query($sql);
            $shopping_cart_item = db_fetch_row($q_shopping_cart_item);
            $sql = '
                SELECT
                name,
                productID,
                min_order_amount,
                shipping_freight,
                free_shipping,
                product_code,
                categoryID,
                opt_margin,
                uri,
                uri_opt_val
                FROM ' . PRODUCTS_TABLE . '
                WHERE productID=' . (int) $shopping_cart_item['productID'];
            $q_products = db_query($sql);
            if ($product = db_fetch_row($q_products)) {
                $costUC = GetPriceProductWithOption($variants, $shopping_cart_item['productID']);
                $tmp = array('productID' => $product['productID'], 'categoryID' => $product['categoryID'], 'uri' => $product['uri'], 'uri_opt_val' => $product['uri_opt_val'], 'id' => $cart_item['itemID'], 'name' => $product['name'], 'quantity' => $cart_item['Quantity'], 'free_shipping' => $product['free_shipping'], 'costUC' => $costUC, 'cost' => show_price($cart_item['Quantity'] * GetPriceProductWithOption($variants, $shopping_cart_item['productID'])), 'product_code' => $product['product_code'], 'opt_margin' => $product['opt_margin']);
                $freight_cost += $cart_item['Quantity'] * $product['shipping_freight'];
                $strOptions = GetStrOptions(GetConfigurationByItemId($tmp['id']));
                if (trim($strOptions) != '') {
                    $tmp['name'] .= '  (' . $strOptions . ')';
                }
                if ($product['min_order_amount'] > $cart_item['Quantity']) {
                    $tmp['min_order_amount'] = $product['min_order_amount'];
                }
                $cart_content[] = $tmp;
                $total_price += $cart_item['Quantity'] * GetPriceProductWithOption($variants, $shopping_cart_item['productID']);
            }
        }
    } else {
        //unauthorized user - get cart from session vars
        $total_price = 0;
        //total cart value
        $cart_content = array();
        //shopping cart items count
        if (isset($_SESSION['gids'])) {
            for ($j = 0; $j < count($_SESSION['gids']); $j++) {
                if ($_SESSION['gids'][$j]) {
                    $session_items[] = CodeItemInClient($_SESSION['configurations'][$j], $_SESSION['gids'][$j]);
                    $sql = '
                        SELECT
                        name,
                        shipping_freight,
                        free_shipping,
                        product_code,
                        categoryID,
                        opt_margin,
                        uri,
                        uri_opt_val
                        FROM ' . PRODUCTS_TABLE . '
                        WHERE productID=' . (int) $_SESSION['gids'][$j];
                    $q = db_query($sql);
                    if ($r = db_fetch_row($q)) {
                        /*                         * $_SESSION['counts'][$j] */
                        $costUC = GetPriceProductWithOption($_SESSION['configurations'][$j], $_SESSION['gids'][$j]);
                        $id = $_SESSION['gids'][$j];
                        if (count($_SESSION['configurations'][$j]) > 0) {
                            for ($tmp1 = 0; $tmp1 < count($_SESSION['configurations'][$j]); $tmp1++) {
                                $id .= '_' . $_SESSION['configurations'][$j][$tmp1];
                            }
                        }
                        $tmp = array('productID' => $_SESSION['gids'][$j], 'categoryID' => $r['categoryID'], 'uri' => $r['uri'], 'uri_opt_val' => $r['uri_opt_val'], 'id' => $id, 'name' => $r[0], 'quantity' => $_SESSION['counts'][$j], 'free_shipping' => $r['free_shipping'], 'costUC' => $costUC, 'cost' => show_price($costUC * $_SESSION['counts'][$j]), 'product_code' => $r['product_code'], 'opt_margin' => $r['opt_margin']);
                        $strOptions = GetStrOptions($_SESSION['configurations'][$j]);
                        if (trim($strOptions) != '') {
                            $tmp['name'] .= '  (' . $strOptions . ')';
                        }
                        $sql = '
                            SELECT
                            min_order_amount,
                            shipping_freight,
                            categoryID,
                            uri,
                            uri_opt_val
                            FROM ' . PRODUCTS_TABLE . '
                            WHERE productID=' . (int) $_SESSION['gids'][$j];
                        $q_product = db_query($sql);
                        $product = db_fetch_row($q_product);
                        if ($product['min_order_amount'] > $_SESSION['counts'][$j]) {
                            $tmp['min_order_amount'] = $product['min_order_amount'];
                        }
                        $freight_cost += $_SESSION['counts'][$j] * $product['shipping_freight'];
                        $cart_content[] = $tmp;
                        $total_price += GetPriceProductWithOption($_SESSION['configurations'][$j], $_SESSION['gids'][$j]) * $_SESSION['counts'][$j];
                    }
                }
            }
        }
    }
    return array('cart_content' => $cart_content, 'total_price' => $total_price, 'freight_cost' => $freight_cost);
}
    function loadCurrentCustomerCart($customerID)
    {
        $this->Items = new xmlNodeX('items');
        /**
         * Select all items from SHOPPING_CARTS_TABLE
         */
        $dbq = '
				SELECT itemID, Quantity, sample FROM ?#SHOPPING_CARTS_TABLE WHERE customerID=?
			';
        $q_items = db_phquery($dbq, $customerID);
        while ($item = db_fetch_assoc($q_items)) {
            $productID = GetProductIdByItemId($item["itemID"]);
            if ($productID == null || trim($productID) == "") {
                continue;
            }
            $dbr = db_phquery('SELECT * FROM ?#PRODUCTS_TABLE WHERE productID=?', $productID);
            if (!db_num_rows($dbr['resource'])) {
                continue;
            }
            $product = db_fetch_assoc($dbr);
            if ($item['sample']) {
                $product['free_shipping'] = 1;
            }
            $aItem =& $this->Items->child('item');
            $aItem->attribute('id', $item['itemID']);
            $aProduct =& $aItem->child('product', array('id' => $productID, 'free-shipping' => $product['free_shipping']));
            if ($product['shipping_freight']) {
                $aProduct->child('freight', array('currency' => ''), $product['shipping_freight']);
            }
            $aItem->child('quantity', null, $item['Quantity']);
            $aItem->child('sample', null, $item['sample']);
            $variants = array();
            $variants = GetConfigurationByItemId($item["itemID"]);
            $aVariants =& $aItem->child('variants');
            foreach ($variants as $v) {
                $aVariants->child('variant', array('id' => $v));
            }
            $aPrice =& $aItem->child('price');
            $aPrice->attribute('currency', '');
            $aPrice->setData(GetPriceProductWithOption($variants, $productID));
        }
    }
예제 #8
0
파일: functions.php 프로젝트: gblok/rsc
function moveCartFromSession2DB()
{
    //all products in shopping cart, which are in session vars, move to the database
    if (isset($_SESSION["gids"]) && isset($_SESSION["log"])) {
        $customerID = regGetIdByLogin($_SESSION["log"]);
        $q = db_query("select itemID from " . SHOPPING_CARTS_TABLE . " where customerID=" . (int) $customerID);
        $items = array();
        while ($item = db_fetch_row($q)) {
            $items[] = (int) $item["itemID"];
        }
        //$i=0;
        foreach ($_SESSION["gids"] as $key => $productID) {
            if ($productID == 0) {
                continue;
            }
            // search product in current user's shopping cart content
            $itemID = null;
            for ($j = 0; $j < count($items); $j++) {
                $q = db_query("select count(*) from " . SHOPPING_CART_ITEMS_TABLE . " where productID=" . (int) $productID . " AND itemID=" . (int) $items[$j]);
                $count = db_fetch_row($q);
                $count = $count[0];
                if ($count != 0) {
                    // compare configuration
                    $configurationFromSession = $_SESSION["configurations"][$key];
                    $configurationFromDB = GetConfigurationByItemId($items[$j]);
                    if (CompareConfiguration($configurationFromSession, $configurationFromDB)) {
                        $itemID = $items[$j];
                        break;
                    }
                }
            }
            if ($itemID == null) {
                // create new item
                db_query("insert into " . SHOPPING_CART_ITEMS_TABLE . " (productID) values(" . (int) $productID . ")");
                $itemID = db_insert_id();
                // set content item
                foreach ($_SESSION["configurations"][$key] as $vars) {
                    db_query("insert into " . SHOPPING_CART_ITEMS_CONTENT_TABLE . " ( itemID, variantID ) " . " values( " . (int) $itemID . ", " . (int) $vars . " )");
                }
                // insert item into cart
                db_query("insert " . SHOPPING_CARTS_TABLE . " (customerID, itemID, Quantity) values ( " . (int) $customerID . ", " . (int) $itemID . ", " . (int) $_SESSION["counts"][$key] . " )");
            } else {
                db_query("update " . SHOPPING_CARTS_TABLE . " set Quantity=Quantity + " . (int) $_SESSION["counts"][$key] . " where customerID=" . (int) $customerID . " and itemID=" . (int) $itemID);
            }
        }
        unset($_SESSION["gids"]);
        unset($_SESSION["counts"]);
        unset($_SESSION["configurations"]);
        session_unregister("gids");
        //calling session_unregister() is required since unset() may not work on some systems
        session_unregister("counts");
        session_unregister("configurations");
    }
}