X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Add addition product to the cart when click on buy. (https://forum.x-cart.com/showthread.php?t=19803)

KooLisM 02-07-2006 07:23 PM

Add addition product to the cart when click on buy.
 
Hi people! This addon I have done allows you to link a product with another product. Hence when you click on the buy button on product A product B will be added to the cart.
In cart section ->
1. When you click on delete for product A or B it will work out the total you have left for prdocut B if its zero it deletes that product from the cart.
2. When more Quantity to Product A product B will be added too however product B will not acceft product A Quantity.
3. You can have alot of product link with product B.
3. When deleting either Product A it works quantity value of B by product B minus product A and deletes product A.

Basically what it does is allows merchant to sell a product which force the customer to buy the other product.

cart.php
Code:

<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2005 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2005          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: cart.php,v 1.6.2.57 2005/09/01 11:18:48 svowl Exp $
#
# This script implements shopping cart facility
#

require "./auth.php";
include $xcart_dir."/shipping/shipping.php";

//include "./nocookie_warning.php";

x_session_register("cart");
x_session_register("intershipper_rates");
x_session_register("intershipper_recalc");
x_session_unregister("secure_oid");
x_session_register("extended_userinfo");
x_session_register("anonymous_checkout");
x_session_register("payment_cc_fields");
x_session_register("current_carrier","UPS");
x_session_register("is_sns_action");

$intershipper_recalc = "Y";

x_session_register("arb_account_used");
x_session_register("airborne_account");

function check_payment_methods($membership) {
        global $sql_tbl, $config, $cart;

        $gc_condition = ((@empty($cart["products"]) && @!empty($cart["giftcerts"]))?" AND pm.paymentid != 14 ":"");
        $payment_methods=func_query("select pm.*,cc.module_name,cc.processor,cc.type from $sql_tbl[payment_methods] as pm left join $sql_tbl[ccprocessors] as cc on pm.paymentid=cc.paymentid where pm.active='Y' AND (pm.membership='' OR  pm.membership='".addslashes($membership)."') $gc_condition order by pm.orderby");
       
        $payment_methods = test_payment_methods($payment_methods,($config["General"]["hide_disfunctional_payments"]=="Y"));
       
        return $payment_methods;
}

#
# Stop list module: check transaction
#
if (!empty($active_modules["Stop_List"]) and !func_is_allowed_trans()) {
        if($mode == "checkout" || $mode == "auth") {
                $top_message["content"] = func_get_langvar_by_name("txt_stop_list_customer_note");       
                $top_message["type"] = "E";
                func_header_location("cart.php");
        }
        $smarty->assign("unallowed_transaction", "Y");
}

#
# Normalize cart content
#
if(!func_is_cart_empty($cart) && $REQUEST_METHOD == 'GET' && !in_array($mode, array('wishlist','wl2cart'))) {
        $hash = array();
        if(!empty($cart['products'])) {
                foreach($cart['products'] as $k => $p) {
                        if($p['hidden'] || !empty($p['pconf_data']))
                                continue;
                        $po = (!empty($p['options']) && is_array($p['options'])?serialize($p['options']):"");
                        $key = $p['productid'].$po.$p['free_price'];

                        if (isset($p['free_amount'])) {
                                # for X-SpecialOffers
                                $key .= '-fa'.$p['free_amount'];
                        }

                        if(isset($hash[$key])) {
                                if(empty($p['distribution'])) {
                                        $cart['products'][$hash[$key]]['amount'] += $p['amount'];
                                } else {
                                        $cart['products'][$hash[$key]]['amount'] = 1;
                                }
                                unset($cart['products'][$k]);
                        } else {
                                $hash[$key] = $k;
                        }
                }
        }
        unset($hash);
}

if ($mode == "checkout" || $mode == "auth") {
#
# Calculate total number of checkout process steps
#
        $total_checkout_steps = 2;
        $checkout_step_modifier["anonymous"] = 0;
        $checkout_step_modifier["payment_methods"] = 0;
        if ($login == "" or $anonymous_checkout) {
                $total_checkout_steps++;
                $checkout_step_modifier["anonymous"] = 1;
        }
        $payment_methods = check_payment_methods(@$user_account["membership"]);
        if(empty($payment_methods)) {
                $top_message['content'] = func_get_langvar_by_name("txt_no_payment_methods");
                $top_message['type'] = 'E';
                func_header_location("cart.php");
        } elseif (count($payment_methods) == 1) {
                $total_checkout_steps--;
                $checkout_step_modifier["payment_methods"] = 1;
        }
}
else
        $anonymous_checkout = false;

#
# $order_secureid (for security reasons)
#
x_session_register("order_secureid");

if ($mode == "clear_cart") {
        if(!empty($active_modules['SnS_connector']) && !empty($cart['products'])) {
                foreach($cart['products'] as $p) {
                        $is_sns_action['DeleteFromCart'][] = $p['productid'];
                }
        }
        $cart = "";
        func_header_location("cart.php");
}

#
# UNSET GIFT CERTIFICATE
#
if ($mode == "unset_gc" && $gcid) {

    foreach ($cart["applied_giftcerts"] as $k=>$v) {
        if ($v["giftcert_id"] == $gcid) {
            $cart["total_cost"] = $cart["total_cost"] - $v["giftcert_cost"];
            continue;
        }
        $tmp[] = $v;
    }
    $cart["applied_giftcerts"] = @$tmp;

    db_query("UPDATE $sql_tbl[giftcerts] SET status='A' WHERE gcid='$gcid'");
    func_header_location("cart.php?mode=checkout");

}

#
# Register member if not registerred yet
# (not a newbie - do not show help messages)
#
$smarty->assign("register_script_name",(($config["General"]["use_https_login"]=="Y")?$xcart_catalogs_secure['customer']."/":"")."cart.php");

if ($mode == "checkout") {
        $usertype = "C";
        $old_action = $action;
        $action = "cart";
        $smarty->assign("action", $action);
        if (empty($login))
                include $xcart_dir."/include/register.php";
        if (!empty($auto_login)) {
            func_header_location("cart.php?mode=checkout&registered=");
        }
        $saved_userinfo = $userinfo;
        $action = $old_action;
}

if (!empty($login)) $userinfo = func_userinfo($login, $current_area, true);
if (!empty($extended_userinfo))
        $userinfo = func_array_merge($userinfo, $extended_userinfo);

#
# Add to cart
#
if($mode=="add" && $productid!="") {

        $added_product = func_select_product($productid, (!empty($user_account['membership'])?$user_account['membership']:""), false, true);

        if ($added_product["forsale"] == "B") {
                $top_message["content"] = func_get_langvar_by_name("txt_pconf_product_is_bundled");
                $top_message["type"] = "W";
                func_header_location($HTTP_REFERER);
        }

        if(!empty($active_modules['Egoods']) && !empty($added_product['distribution'])) {
                $amount = 1;
        }
       
        $amount = abs(intval($amount));

#
# Do addition to cart with options
#
        if($active_modules["Product_Options"]) {
                if (!empty($product_options)) {
                        if(!func_check_product_options ($productid, $product_options)) {
                        if (!empty($active_modules["Product_Configurator"]) and $added_product["product_type"] == "C")
                                  func_header_location("pconf.php?productid=$productid&err=options");
                              else
                            func_header_location("product.php?productid=$productid&err=options");
                        }
                } else {
                        $product_options = func_get_default_options($productid, $amount, @$user_account['membership']);
                        if($product_options === false) {
                                func_header_location ("error_message.php?access_denied&id=30");
                        } elseif($product_options === true) {
                                $product_options = "";
                                unset($product_options);
                        }
                }

                $variantid = func_get_variantid($product_options);
                if(!empty($cart['products']) && !empty($variantid)) {
                        $added_product["avail"] = func_get_options_amount($product_options, $productid);
                        foreach($cart['products'] as $k => $v) {
                                if($v['productid'] == $productid) {
                                        if($variantid == func_get_variantid($v['options'])) {
                                                $added_product["avail"] -= $v['amount'];
                                        }
                                }
                        }
                }
        }

#
# Add to cart amount of items that is not much than in stock
#
        if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C")
                if ($amount > $added_product["avail"])
                        $amount = $added_product["avail"];
       
        if ($productid && $amount) {

                if ($amount < $added_product["min_amount"]) {
                        func_header_location ("error_message.php?access_denied&id=31");
                }

                $found = false;
                $product_distribution = func_query_first_cell("SELECT distribution FROM $sql_tbl[products] WHERE productid='$productid'");
                if (!empty($cart) and @$cart["products"] and $added_product["product_type"]!="C") {
                        foreach ($cart["products"] as $k=>$v) {
                                if (($v["productid"] == $productid) && (!$found) && ($v["options"] == $product_options) && empty($v["hidden"])) {
                                        if ((float)$v["free_price"] != $price)
                                                continue;
                                        $found = true;
                                        if (($cart["products"][$k]["amount"] >=1) && !empty($product_distribution))        {
                                                $cart["products"][$k]["amount"]=1;
                                                $amount=0;
                                        }
                                        $cart["products"][$k]["amount"] += $amount;
                                        if (func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$productid' AND add_product = '1'")) {
                                                $bp_add_product = func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$productid' AND add_product = '1'");
                                                $bp_product_distribution = func_query_first_cell("SELECT distribution FROM $sql_tbl[products] WHERE productid='$bp_add_product'");
                                                $cart["products"][]=array("cartid"=>$cartid+1, "productid"=>$bp_add_product,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$bp_product_distribution);
                                        }
                                }
                        }
                }
               
                if (!$found) {
                #
                # Add product to the cart
                #
                        if (!empty($price))
                        # price value is defined by customer if admin set it to '0.00'
                                $free_price = abs(doubleval($price));

                        $cartid = func_generate_cartid($cart["products"]);
                        if(empty($cart["products"]))
                                $add_to_cart_time = time();
                        $cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$product_distribution);
                       
                        if (func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$productid' AND add_product = '1'")) {
                                $cartid = func_generate_cartid($cart["products"]);
                                $bp_add_product = func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$productid' AND add_product = '1'");
                                $bp_product_distribution = func_query_first_cell("SELECT distribution FROM $sql_tbl[products] WHERE productid='$bp_add_product'");
                                $cart["products"][]=array("cartid"=>$cartid, "productid"=>$bp_add_product,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$bp_product_distribution);
                        }
                        if(!empty($active_modules["Product_Configurator"]))
                                include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
                }

               
                $intershipper_recalc = "Y";

        } elseif($from == 'partner' && $productid) {
                func_header_location($xcart_catalogs['customer']."/product.php?productid=".$productid);
        }
}

#
# DELETE PRODUCT FROM THE CART
#
if ($mode=="delete" && $productindex!="") {
        #
        # RESITRICT USER FROM DELETE PRODUCT THAT IS LINK TO A PRODUCT IN PRODUCT_LINKS ADD_PRODUCT=1
        #
        foreach ($cart["products"] as $k=>$v) {
                if (func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$v[productid]' AND add_product = '1'")) {
                        $bp_productindexes1 = $v[productid];
                        $bp_productindexes2 = func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$v[productid]' AND add_product = '1'");
                }
                if ($v["productid"] == $bp_productindexes1) {
                        $bp_product1["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$v["new_quantity"], "link_table"=>$bp_productindexes2, "cartid"=>$v["cartid"]);
                }
                if ($v["productid"] == $bp_productindexes2) {
                        $bp_product2["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$v["new_quantity"], "link_table"=>$bp_productindexes2, "cartid"=>$v["cartid"]);
                }
        }

        #
        # Get product new quantity and pass amount to array
        #       
        foreach ($bp_product1["products"] as $a=>$b) {
                if (!isset($bp_new_product1_mod)) {
                        $bp_new_product1_mod[] = array("productid"=>$b["productid"], "amount"=>$b["amount"], "new_quantity"=>$b["new_quantity"], "link_table"=>$b["link_table"], "cartid"=>$b["cartid"]);
                } else {
                        foreach ($bp_new_product1_mod as $k=>$v) {
                                if ($b["link_table"] == $v['link_table']) {
                                        $bp_new_product1_mod[$k]['amount'] = $bp_new_product1_mod[$k]['amount'] + $b['amount'];
                                        $bp_new_product1_mod[$k]['new_quantity'] = $bp_new_product1_mod[$k]['new_quantity'] + $b['new_quantity'];
                                        break;
                                } else {
                                        $bp_new_product1_mod[] = array("productid"=>$b["productid"], "amount"=>$b["amount"], "new_quantity"=>$b["new_quantity"], "link_table"=>$b["link_table"], "cartid"=>$b["cartid"]);
                                }
                        }
                }
        }
       
        foreach ($bp_product1["products"] as $k=>$v) {
                        if ($v['cartid'] == $productindex) {
                                $bp_delete_amount = $v["amount"];
                                $bp_delete_link = $v["link_table"];
                }
        }
        if ($bp_delete_amount && $bp_delete_link) {
                foreach ($cart["products"] as $k=>$v) {
                        if ($v['productid'] == $bp_delete_link) {
                                $cart["products"][$k]["amount"] = intval($cart["products"][$k]["amount"]) - intval($bp_delete_amount);
                        }
                }
        }
        if (!$bp_delete_amount && !$bp_delete_link) {
                foreach ($cart["products"] as $k=>$v) {
                        foreach ($bp_new_product1_mod as $k2=>$v2) {
                                if ($v['cartid'] == $productindex &&  $v['productid'] == $v2["link_table"]) {
                                        $cart["products"][$k]["amount"] = $v2["amount"];
                                }
                        }
                }
                foreach ($cart["products"] as $k=>$v) {
                        foreach ($bp_new_product1_mod as $k2=>$v2) {
                                if ($v['cartid'] == $productindex &&  $v['productid'] == $v2["link_table"]) {
                                        echo "
                                                <SCRIPT LANGUAGE='javascript'> <!--
                                                        alert('You can not delete this product becuase it is link with another product')
                                                --> </SCRIPT>";
                                        func_header_location("cart.php");
                                        exit;
                                }
                        }
                }
        }
       
                #
                # Delete product from cart
                #
                if(!empty($active_modules["Product_Configurator"]))
                        include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
       
                foreach ($cart["products"] as $k=>$v)
                        if ($v["cartid"] == $productindex) {
                                $productid = $v["productid"];
                                if(!empty($active_modules["Advanced_Statistics"]))
                                        @include $xcart_dir."/modules/Advanced_Statistics/prod_del.php";
                                array_splice($cart["products"],$k,1);
                                break;
                        }
                if (!empty($active_modules['SnS_connector']) && !empty($productid)) {
                        $is_sns_action['DeleteFromCart'][] = $productid;
                }
                if (func_is_cart_empty($cart)) {
                        $cart = "";
                }
                $intershipper_recalc = "Y";
                func_header_location("cart.php");
        }

elseif (!empty($shippingid)) {
        $cart["shippingid"]=$shippingid;
}

if (empty($action)) $action = "";

#
# UPDATES PRODUCTS QUANTITY IN THE CART
#
if ($action=="update") {
        if(!empty($productindexes)) {
        #
        # BP UPDATE QUANTITY THAT IS LINK TO A PRODUCT IN PRODUCT_LINKS ADD_PRODUCT=1
        #       
       
                #
                # Get product amount if product is in product links table
                #
                foreach ($cart["products"] as $k=>$v) {
                        if (func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$v[productid]' AND add_product = '1'")) {
                                $bp_productindexes1 = $v[productid];
                                $bp_productindexes2 = func_query_first_cell("SELECT productid2 FROM $sql_tbl[product_links] WHERE productid1 = '$v[productid]' AND add_product = '1'");
                        }
                        if ($v["productid"] == $bp_productindexes1) {
                                $bp_product1["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$v["new_quantity"], "link_table"=>$bp_productindexes2);
                               
                        }
                        if ($v["productid"] == $bp_productindexes2) {
                                $bp_product2["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$v["new_quantity"], "link_table"=>$bp_productindexes2);
                        }
                }
                foreach($productindexes as $_cartid=>$new_quantity) {
                        foreach ($cart["products"] as $k=>$v) {
                                if ($v["cartid"] == $_cartid) {
                                        $productindexes_tmp[$k] = $new_quantity;
                                        break;
                                }
                        }
                        #
                        # Get product new quantity and pass amount to array
                        #
                        foreach ($bp_product1["products"] as $a=>$b) {
                                if ($v["productid"] == $b["productid"]) {
                                        $i1=$i1+1;
                                        $bp_new_product1["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$new_quantity, "link_table"=>$b["link_table"], "if_match"=>$i1);
                                }
                        }
                        foreach ($bp_product2["products"] as $a=>$b) {
                                if ($v["productid"] == $b["productid"]) {
                                        $i2=$i2+1;
                                        $bp_new_product2["products"][] = array("productid"=>$v["productid"], "amount"=>$v["amount"], "new_quantity"=>$new_quantity, "link_table"=>$b["link_table"], "if_match"=>$i2);
                                }
                        }
                }
               
                foreach ($bp_new_product1["products"] as $a=>$b) {
                        if (!isset($bp_new_product1_mod)) {
                                $bp_new_product1_mod[] = array("productid"=>$b["productid"], "amount"=>$b["amount"], "new_quantity"=>$b["new_quantity"], "link_table"=>$b["link_table"], "if_match"=>$b["if_match"]);
                        } else {
                                foreach ($bp_new_product1_mod as $k=>$v) {
                                        if ($b["link_table"] == $v['link_table']) {
                                                $bp_new_product1_mod[$k]['amount'] = $bp_new_product1_mod[$k]['amount'] + $b['amount'];
                                                $bp_new_product1_mod[$k]['new_quantity'] = $bp_new_product1_mod[$k]['new_quantity'] + $b['new_quantity'];
                                                break;
                                        } else {
                                                $bp_new_product1_mod[] = array("productid"=>$b["productid"], "amount"=>$b["amount"], "new_quantity"=>$b["new_quantity"], "link_table"=>$b["link_table"], "if_match"=>$b["if_match"]);
                                        }
                                }
                        }
                }
               
                foreach ($bp_new_product1_mod as $b1) {
               
                        foreach ($bp_new_product2["products"] as $a2=>$b2) {
                       
                                if ($b1["link_table"] == $b2["productid"]) {
                                        $bp_new_quantity=0;
                                        $bp_difference=0;
                                        if ($b1["amount"] < $b1['new_quantity']) {
                                                $bp_difference = intval($b1['new_quantity']) - intval($b1['amount']);
                                                $bp_new_quantity = intval($b2['new_quantity']) + $bp_difference;
                                               
                                        }
                                        elseif ($b1["amount"] > $b1['new_quantity']) {
                                                $bp_difference = intval($b1['amount']) - intval($b1['new_quantity']);
                                                $bp_new_quantity = intval($b2['new_quantity']) - $bp_difference;
                                        }
                                        elseif ($b1["new_quantity"] > $b2["new_quantity"]) {
                                                $bp_new_quantity = $b1["new_quantity"];
                                                echo "
                                                <SCRIPT LANGUAGE='javascript'> <!--
                                                        alert('One of the product can not be lesser than the connecting product')
                                                --> </SCRIPT>";
                                       
                                        }
                                        foreach($productindexes as $_cartid=>$new_quantity) {
                                                foreach ($cart["products"] as $k=>$v) {
                                                        if ($b2["productid"] == $v['productid'] && $bp_new_quantity) {
                                                                $productindexes_tmp[$k] = $bp_new_quantity;
                                                                break;
                                                        }
                                                }
                                        }
                                }
                        }
                }
               
                $productindexes = $productindexes_tmp;
                unset($productindexes_tmp);
       
                if(!empty($active_modules["Product_Configurator"]))
                        include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
       
                foreach($cart["products"] as $k=>$v) {
                        $tot = 0;
                        $tot_amount = 0;
                        $min_amount = func_query_first_cell("SELECT min_amount FROM $sql_tbl[products] WHERE productid = '$v[productid]'");
                        if($active_modules['Product_Options'] && !empty($v['options']))
                                $vid = func_get_variantid($v['options']);
                        $top_message['content'] = '';
                        foreach($productindexes as $productindex=>$new_quantity) {
                                if (!is_numeric($new_quantity)) continue;
                                if($active_modules['Product_Options'] && !empty($cart["products"][$productindex]['options']))
                                        $lvid = func_get_variantid($cart["products"][$productindex]['options']);
                                if ($cart["products"][$productindex]["productid"] == $v["productid"] && $vid == $lvid) {
                                        if ($new_quantity < $min_amount && $new_quantity > 0) {
                                                $productindexes[$productindex] = $new_quantity = $v['amount'];
                                                if (!isset($min_amount_warns[$v['productid']])) {
                                                        $product_name = func_query_first_cell("SELECT IF($sql_tbl[products_lng].product IS NULL OR $sql_tbl[products_lng].product = '', $sql_tbl[products].product, $sql_tbl[products_lng].product) as product FROM $sql_tbl[products] LEFT JOIN $sql_tbl[products_lng] ON $sql_tbl[products].productid = $sql_tbl[products_lng].productid AND $sql_tbl[products_lng].code = '$shop_language' WHERE $sql_tbl[products].productid = '$v[productid]'");
                                                        $top_message['content'] .= (empty($top_message['content']) ? "" : "
\n").func_get_langvar_by_name("lbl_cannot_buy_less_X", array("quantity" => $min_amount, "product" => $product_name));
                                                        $top_message['type'] = "W";
                                                        $min_amount_warns[$v['productid']] = true;
                                                }
                                        }
                                        $tot += floor($new_quantity);
                                }
                        }
                        foreach($cart["products"] as $k2 => $v2) {
                                if($active_modules['Product_Options'] && !empty($cart["products"][$k2]['options']))
                                        $lvid = func_get_variantid($cart["products"][$k2]['options']);
                                if ($v["productid"] == $v2["productid"] && $vid == $lvid)
                                        $tot_amount += $v2['amount'];
                        }
                        $updates_array[$k] = array("quantity"=>$v["amount"], "total_quantity"=>$tot, "total_amount" => $tot_amount);
                }

# Create hash array with variants
        $hash = array();
        if(!empty($active_modules['Product_Options'])) {
                foreach($productindexes as $productindex => $new_quantity) {
                        if(!empty($cart["products"][$productindex]['options'])) {
                                $variantid = func_get_variantid($cart["products"][$productindex]['options']);
                                if($variantid) {
                                        if(!isset($hash[$variantid])) {
                                                $hash[$variantid]['avail'] = func_get_options_amount($cart["products"][$productindex]['options'], $cart["products"][$productindex]['productid']);
                                        }
                                        $hash[$variantid]['old'] += $cart["products"][$productindex]['amount'];
                                        $hash[$variantid]['new'] += $new_quantity;
                                        $hash[$variantid]['ids'][] = $cart["products"][$productindex]['productid'];
                                        $cart["products"][$productindex]['variantid'] = $variantid;
                                }
                        }
                }
        }

# Check&set new quantity
        foreach($productindexes as $productindex => $new_quantity) {
       
                if (!is_numeric($new_quantity) || empty($cart["products"][$productindex]))
                        continue;
               
                $new_quantity = floor($new_quantity);
                $productid=$cart["products"][$productindex]["productid"];
                $total_quantity = $updates_array[$productindex]["total_quantity"];
                $total_amount = $updates_array[$productindex]["total_amount"];
                if ($config["General"]["unlimited_products"]=="N" && $cart["products"][$productindex]["product_type"] != "C")
                        if(!empty($cart["products"][$productindex]['variantid'])) {
                                $amount_max = $hash[$cart["products"][$productindex]['variantid']]['avail'];
                                $total_quantity = $hash[$cart["products"][$productindex]['variantid']]['old'];
                        } else {
                                $amount_max=func_query_first_cell("select avail from $sql_tbl[products] where productid='$productid'");
                        }
                else
                        $amount_max=$total_quantity+1;
                $amount_min=func_query_first_cell("select min_amount from $sql_tbl[products] where productid='$productid'");

                #
                # Do not change
                #
                if ($config["General"]["unlimited_products"] == "Y") {
                        $cart["products"][$productindex]["amount"] = $new_quantity;
                        continue;
                }

                if (($new_quantity >= $amount_min ) && ($products[$productindex]["distribution"]))
                        $cart["products"][$productindex]["amount"] = 1;       
                elseif (($new_quantity >= $amount_min) && ($new_quantity <= ($amount_max-$total_amount+$cart["products"][$productindex]["amount"]))) {
                        $cart["products"][$productindex]["amount"] = $new_quantity;
                        if(!empty($cart["products"][$productindex]['variantid'])) {
                                $hash[$cart["products"][$productindex]['variantid']]['old'] += ($new_quantity-$cart["products"][$productindex]["amount"]);
                        } else {
                                $updates_array[$productindex]["total_amount"] += ($new_quantity-$cart["products"][$productindex]["amount"]);
                        }
                } elseif  ($new_quantity >= $amount_min) {
                        $old_amount = $cart["products"][$productindex]["amount"];
                        $cart["products"][$productindex]["amount"] = ($amount_max-$total_amount+$cart["products"][$productindex]["amount"]);
                        if(!empty($cart["products"][$productindex]['variantid'])) {
                                $hash[$cart["products"][$productindex]['variantid']]['old'] += ($amount_max-$total_amount+$cart["products"][$productindex]["amount"]-$old_amount);
                        } else {
                                $updates_array[$productindex]["total_amount"] += ($amount_max-$total_amount+$cart["products"][$productindex]["amount"]-$old_amount);
                        }
                } else
                        $cart["products"][$productindex]["amount"] = 0;
                if($cart["products"][$productindex]["amount"] < 0)
                        $cart["products"][$productindex]["amount"] = 0;
        }
       
        if(!empty($active_modules["Product_Configurator"])) {
                $pconf_update = "post_update";
                include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
        }

    foreach($cart["products"] as $index => $product) {
            if($product["amount"] > 0) {
                        $products[] = $product;
                }
                $cart["products"] = $products;
        }
        $intershipper_recalc = "Y";
        }
#
# Update shipping method
#
        if ($config["Shipping"]["realtime_shipping"] == "Y" and !empty($active_modules["UPS_OnLine_Tools"]) and $config["Shipping"]["use_intershipper"] != "Y")
                $current_carrier = $selected_carrier;
       
        if($shippingid!="") $cart["shippingid"]=$shippingid;

        $airborne_account = $arb_account;
        if(!empty($active_modules['SnS_connector']) && !empty($productindexes))
                func_generate_sns_action("CartChanged");
       

       
        $redirect_url = "cart.php".(!empty($mode) ? "?mode=$mode" : "");
}


if (!func_is_cart_empty($cart)) {

        $products = func_products_in_cart($cart, (!empty($userinfo["membership"])?$userinfo["membership"]:""));
    if (is_array($products))
    if (!empty($cart["products"]) and count($products) != count($cart["products"])) {
        foreach($products as $k=>$v) {
            $prodids[] = $v["productid"];
                        $prodids_opts[] = $v['options'];
                }
        if (is_array($prodids)) {
            foreach($cart["products"] as $k=>$v)
                if (in_array($v["productid"], $prodids) && in_array($v["options"], $prodids_opts))
                    $cart_prods[$k] = $v;
                        $cart["products"] = $cart_prods;
        }
                else
                        $cart = "";
                func_header_location("cart.php?$QUERY_STRING");
    }

        if(!empty($active_modules["Subscriptions"])) {
            include $xcart_dir."/modules/Subscriptions/subscription.php";
        }

        if (empty($login) && $config["General"]["apply_default_country"]=="Y") {
                $userinfo["s_country"] = $config["General"]["default_country"];
                $userinfo["s_state"] = $config["General"]["default_state"];
                $userinfo["s_zipcode"] = $config["General"]["default_zipcode"];
                $userinfo["s_city"] = $config["General"]["default_city"];
                $userinfo["s_countryname"] = func_get_country($userinfo["s_country"]);
                $userinfo["s_statename"] = func_get_state($userinfo["s_state"], $userinfo["s_country"]);
        }

#
# Check if only downloadable products placed in cart
#
        $need_shipping = false;
        if ($config["Shipping"]["disable_shipping"]!="Y") {
                if (is_array($products))
                        foreach ($products as $product)
                                if ($product["free_shipping"] == "Y" or ($active_modules["Egoods"] and  $product["distribution"] != "") or ($config["Shipping"]["replace_shipping_with_freight"] == "Y" and $product["shipping_freight"] > 0))
                                        continue;
                                else
                                        $need_shipping = true;
        }

        $smarty->assign("need_shipping", $need_shipping);

        if ($need_shipping) {
        #
        # Get the allowed shipping methods list
        #
                $shipping = func_get_shipping_methods_list($cart, $products, $userinfo);
                $smarty->assign("shipping", $shipping);
                $smarty->assign("current_carrier", $current_carrier);
        }
}

if (!empty($need_shipping)) {
#
# If current shipping is empty set it to default (first in shipping array)
#
        $shipping_matched = false;

        if(!empty($shipping))
                foreach($shipping as $shipping_method)
                        if(@$cart["shippingid"]==$shipping_method["shippingid"]) $shipping_matched=true;

        if(!$shipping_matched && !empty($shipping))
                $cart["shippingid"] = $shipping[0]["shippingid"];

        $cart["delivery"]=func_query_first_cell("select shipping from $sql_tbl[shipping] where shippingid='$cart[shippingid]'");

}
else {
        $cart["delivery"] = "";
        $cart["shippingid"] = 0;
}
               
$smarty->assign("main","cart");

#
# If cart is not empty put products' details into products array
#
if (!func_is_cart_empty($cart)) {
#
# Discount coupons
#
        if($active_modules["Discount_Coupons"])
                include $xcart_dir."/modules/Discount_Coupons/discount_coupons.php";

#
# Calculate all prices
#
        $cart = func_array_merge ($cart, func_calculate($cart, $products, $login, $current_area));

        if (func_is_cart_empty($cart)) {
                $cart = "";
                func_header_location($xcart_web_dir.DIR_CUSTOMER."/error_message.php?product_in_cart_expired");
        } else {
                $products = func_products_in_cart($cart, (!empty($userinfo["membership"])?$userinfo["membership"]:""));
        }

        $smarty->assign("cart",$cart);

}

#
# Redirect
#
if($mode=="add" and $productid) {
        if(!empty($active_modules['SnS_connector'])) {
                $sns_do_action = array("AddToCart", $productid);
        }
        if($config["General"]["redirect_to_cart"]=="Y") {
                func_header_location("cart.php");
        } else{
                if(!empty($HTTP_REFERER)) {
                        func_header_location($HTTP_REFERER);
                } else {
                        func_header_location("home.php?cat=$cat&page=$page");
                }
        }
} elseif (!empty($is_sns_action)) {
        foreach ($is_sns_action as $a => $v) {
                foreach ($v as $v2) {
                        func_generate_sns_action($a, $v2);
                }

        }
        $is_sns_action = array();
}

if ($redirect_url)
        func_header_location($redirect_url);

#
# Wishlist facility
#
if (!empty($active_modules["Wishlist"]) && $mode != "checkout") {
        @include $xcart_dir."/modules/Wishlist/wishlist.php";
}
if ($mode != "wishlist") {
        if ($mode == "checkout")
                $location[] = array(func_get_langvar_by_name("lbl_checkout"), "");
        else
                $location[] = array(func_get_langvar_by_name("lbl_your_shopping_cart"), "");
}

#
# SHOPPING CART FEATURE
#

if (($mode=="checkout") && (!empty($cart["products"])) && (empty($shipping)) && ($login) && $need_shipping && $config["Shipping"]["disable_shipping"]!="Y") {
        func_header_location("error_message.php?error_no_shipping");
}

if ($mode=="checkout" && !func_is_cart_empty($cart) && ($cart["subtotal"]<$config["General"]["minimal_order_amount"]) && $config["General"]["minimal_order_amount"] > 0) {
        func_header_location("error_message.php?error_min_order");
}

if($mode=="checkout" && $login=="" && !func_is_cart_empty($cart)) {
#
# Anonimous checkout
#
        $smarty->assign("main","anonymous_checkout");
        $smarty->assign("anonymous","Y");
        if(empty($userinfo) && !empty($saved_userinfo)) {
                $userinfo = $saved_userinfo;
        }
        $checkout_step = 1;
        $anonymous_checkout = true;

        $location[] = array(func_get_langvar_by_name("lbl_your_order"), "");

#
# For PayPal ExpressCheckout
#
        if (!empty($httpsmod_active)) {
                # detect active PayPal Pro
                $tmp = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[ccprocessors], $sql_tbl[payment_methods] WHERE $sql_tbl[ccprocessors].processor='ps_paypal_pro.php' AND $sql_tbl[ccprocessors].paymentid=$sql_tbl[payment_methods].paymentid AND active='Y' ORDER BY $sql_tbl[payment_methods].protocol DESC LIMIT 1");
                $smarty->assign("paypal_express_active", $tmp);
                x_session_unregister('paypal_begin_express');
        }

} elseif($mode=="checkout" && empty($paymentid) && !func_is_cart_empty($cart) && $cart["total_cost"] == 0) {
        x_session_unregister('paypal_begin_express');
        func_header_location($current_location."/payment/payment_offline.php");
} elseif($mode=="checkout" && $paymentid!="" && !func_is_cart_empty($cart)) {
#         
# Check if paymentid isn't faked
#
        $is_egoods = false;
        if($config['Modules']['egoods_manual_cc_processing'] == 'Y') {
                $is_egoods = func_esd_in_cart($cart);
        }
    $membership = $user_account["membership"];
    $is_valid_paymentid = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[payment_methods] WHERE paymentid='$paymentid'".(($is_egoods && $paymentid == 1)?"":" AND active='Y'")." AND (membership='' OR  membership='".addslashes($membership)."') ");
    if (!$is_valid_paymentid) {
        func_header_location("cart.php?mode=checkout&err=paymentid");
        }

        $paypal_expressid = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[payment_methods], $sql_tbl[ccprocessors] WHERE $sql_tbl[payment_methods].processor_file='ps_paypal_pro.php' AND $sql_tbl[payment_methods].processor_file=$sql_tbl[ccprocessors].processor AND $sql_tbl[payment_methods].paymentid=$sql_tbl[ccprocessors].paymentid AND $sql_tbl[payment_methods].active='Y'");

        if (!empty($paypal_expressid) && $paypal_expressid == $paymentid) {
                x_session_register('paypal_begin_express');
                if ($paypal_begin_express !== false) {
                        $paypal_begin_express = true;
                        func_header_location($current_location.'/payment/ps_paypal_pro.php?payment_id='.$paymentid.'&mode=express');
                }
        }

#
# Generate uniq orderid which will identify order session
#
        $order_secureid = md5(uniqid(rand()));
#
# Show payment details checkout page
#
        $payment_cc_data = func_query_first("SELECT * FROM $sql_tbl[ccprocessors] WHERE paymentid='$paymentid'");
        if($is_egoods && $paymentid != 1 && !empty($payment_cc_data)) {
                $paymentid = 1;
                $payment_cc_data = array();
        }
        $smarty->assign("payment_cc_data", $payment_cc_data);
#
# Generate payment script URL depending on HTTP/HTTPS settings
#
        $payment_data = func_query_first("select * from $sql_tbl[payment_methods] where paymentid='$paymentid'");
        $payment_data["payment_script_url"] = ($payment_data["protocol"]=="https"?$https_location:$http_location)."/payment/".$payment_data["payment_script"];

        if (x_session_is_registered('paypal_begin_express')) {
                $tmp = func_query_first_cell("SELECT $sql_tbl[payment_methods].paymentid FROM $sql_tbl[ccprocessors], $sql_tbl[payment_methods] WHERE $sql_tbl[ccprocessors].processor='ps_paypal_pro.php' AND $sql_tbl[ccprocessors].paymentid=$sql_tbl[payment_methods].paymentid AND $sql_tbl[payment_methods].paymentid='$paymentid' ORDER BY $sql_tbl[payment_methods].protocol DESC LIMIT 1");
                $smarty->assign('paypal_express_active', $tmp);
        }
        $smarty->assign("payment_data",$payment_data);
        if(!empty($payment_cc_fields)) {
                $userinfo = func_array_merge($userinfo, $payment_cc_fields);
        }
        $smarty->assign("userinfo",$userinfo);
        $smarty->assign("main","checkout");

        if ($checkout_step_modifier["payment_methods"] == 1)
                $smarty->assign("ignore_payment_method_selection", 1);
       
        $checkout_step = 2 + $checkout_step_modifier["anonymous"] - $checkout_step_modifier["payment_methods"];

        $location[] = array(func_get_langvar_by_name("lbl_payment_details"), "");

} elseif($mode=="checkout" && !func_is_cart_empty($cart)) {
#
# Show checkout page with payment options only methods availiable to current
#  membership level are displayed
#
        $payment_methods = check_payment_methods(@$user_account["membership"]);
        if (count($payment_methods) == 1)
                func_header_location("cart.php?paymentid=".$payment_methods[0]["paymentid"]."&mode=checkout");

        if (!empty($payment_methods))
                $payment_methods[0]["is_default"] = 1;

        $checkout_step = 1 + $checkout_step_modifier["anonymous"] - $checkout_step_modifier["payment_methods"];

        $smarty->assign("payment_methods",$payment_methods);
        $smarty->assign("main","checkout");

        $location[] = array(func_get_langvar_by_name("lbl_payment_details"), "");

        x_session_unregister('paypal_begin_express');
}
elseif ($mode=="order_message") {
        $smarty->assign("main","order_message");
        $location[] = array(func_get_langvar_by_name("lbl_order_processed"), "");

}
elseif ($mode=="auth") {
        $smarty->assign("main","checkout");
        $checkout_step = 1;
}

require $xcart_dir."/include/categories.php";

if($active_modules["Manufacturers"])
    include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";

$giftcerts = (!empty($cart["giftcerts"])? $cart["giftcerts"] : array());

#
# In this mode cart.php show info about existing order (order_message)
#
if (!empty($orderids)) {

        if (empty($login))
                func_header_location("error_message.php?access_denied&id=32");

        $orders = array ();
        $_orderids = split (",",$orderids);

        foreach ($_orderids as $orderid) {
                $order_data = func_order_data($orderid);
                if (empty($order_data))
                        continue;
                $order_data['products'] = func_translate_products($order_data['products'], $shop_language);
#
# Security check if current customer is not order's owner
#
                if ($order_data["order"]["login"]!=$login) unset($order_data);

                $orders[] = $order_data;
        }

        $smarty->assign("orders", $orders);
        if ($action == "print") {
                $smarty->assign("template", "customer/main/order_message.tpl");
                func_display("customer/preview.tpl",$smarty);
                exit;
        }
        $smarty->assign("orderids", $orderids);
}

include "./minicart.php";

if(!empty($payment_cc_fields)) {
        $userinfo = func_array_merge($userinfo, $payment_cc_fields);
}
if(!empty($login) || $mode != 'checkout') {
        $smarty->assign("userinfo",@$userinfo);
}
$smarty->assign("products",@$products);
$smarty->assign("giftcerts",$giftcerts);

if ($mode == "checkout" || $mode == "auth") {
        $smarty->assign("checkout_step",$checkout_step);
        $smarty->assign("total_checkout_steps",$total_checkout_steps);       
}

if (!empty($order))
        $smarty->assign("order",$order);

if (!empty($login))
    db_query("UPDATE $sql_tbl[customers] SET cart='".addslashes(serialize($cart))."' WHERE login='$login'");
       
if (func_use_arb_account()) {
        $smarty->assign("use_airborne_account", true);
        $smarty->assign("airborne_account", $airborne_account);
}
x_session_save();

# Assign the current location line
$smarty->assign("location", $location);

func_display("customer/home.tpl",$smarty);

?>


skin1_original\modules\Upselling_Products\product_ links.tpl

Code:

{* $Id: product_links.tpl,v 1.15.2.1 2004/12/27 07:26:28 max Exp $ *}
{if $active_modules.Upselling_Products ne ""}
{include file="main/popup_product_js.tpl"}

{$lng.txt_upselling_links_top_text}





{capture name=dialog}

<TABLE border="0" {if $productids ne ''}cellspacing="0" cellpadding="4"{else}cellspacing="1" cellpadding="2"{/if} width="100%">

<FORM action="product_modify.php" name="upsales" method="POST">

<INPUT type="hidden" name="productid" value="{$product.productid}">
<INPUT type="hidden" name="selected_productid" value="">
<INPUT type="hidden" name="mode" value="upselling_links">

{if $productids ne ''}
<TR>
    <TD width="15" class="TableSubHead"></TD>
    <TD class="TableSubHead" colspan="5">* {$lng.lbl_note}: {$lng.txt_edit_product_group}</TD>
</TR>
{/if}
<TR class="TableHead">
{if $productids ne ''}<TD width="15" class="TableSubHead"></TD>{/if}
<TD width="20">{$lng.lbl_pos}</TD>
<TD width="15%">{$lng.lbl_product_id}</TD>
<TD width="15%">{$lng.lbl_sku}</TD>
<TD width="70%" colspan="2">{$lng.lbl_product}</TD>
</TR>

{if $product_links}

{section name=cat_num loop=$product_links}

<TR{cycle values=", class='TableSubHead'"}>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[u_product][{$product_links[cat_num].productid}]"></TD>{/if}
<TD><INPUT type="text" value="{$product_links[cat_num].orderby}" name="upselling[{$product_links[cat_num].productid}]" size="4"></TD>
<TD>#{$product_links[cat_num].productid}</TD>
<TD>{$product_links[cat_num].productcode}</TD>
<TD><FONT class="ItemsList">{ $product_links[cat_num].product|escape|truncate:35:"...":false}</FONT></TD>
<TD><INPUT type="button" value="{$lng.lbl_delete}" onClick="self.location='product_modify.php?mode=del_upsale_link&product_link={$product_links[cat_num].productid}&productid={$product.productid}'"></TD>
</TR>
{/section}

{else}

<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"></TD>{/if}
<TD colspan="5" align="center">{$lng.lbl_no_products}</TD>
</TR>

{/if}

<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"></TD>{/if}
<TD colspan="5" class="SubHeader2">
{$lng.lbl_add_new_link}</TD>
</TR>

<TR>
{if $productids ne ''}<TD width="15" class="TableSubHead"><INPUT type="checkbox" value="Y" name="fields[new_u_product]"></TD>{/if}
<TD colspan="5">
{$lng.lbl_product}: <INPUT type="text" name="prod_name" size="40" style="width=50%" disabled>
<INPUT type="button" value="{$lng.lbl_browse_}" onClick="popup_product('upsales.selected_productid', 'upsales.prod_name');">


{$lng.lbl_bidirectional_link}
<INPUT type="checkbox" name="bi_directional">


Add Product to Cart
<INPUT type="checkbox" name="add_product_to_cart">



<INPUT type="submit" value="{$lng.lbl_add_update}">
</TD>
</TR>

</FORM>

</TABLE>

{/capture}
{include file="dialog.tpl" title=$lng.lbl_upselling_links content=$smarty.capture.dialog extra="width=100%"}
{/if}


KooLisM 02-07-2006 07:27 PM

modules\Upselling_Products\edit_upsales.php
Code:

<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2005 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2005          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: edit_upsales.php,v 1.17.2.2 2005/01/12 07:42:51 svowl Exp $
#
# Module process adding and deleting upsales links
#

if ( !defined('XCART_SESSION_START') ) { header("Location: ../../"); die("Access denied"); }

#
# Insert upsales link into database
#
if ($REQUEST_METHOD=="POST" && $mode == "upselling_links") {
        if ($add_product_to_cart == "on") {
                $flag = false;
                if(!empty($upselling)) {
                        foreach($upselling as $pid => $v) {
                                db_query("UPDATE $sql_tbl[product_links] SET orderby = '$v' WHERE productid2='$pid' AND productid1 = '$productid'");
                                $flag = true;
                        }
                }
       
                if($fields['u_product'] && $productids) {
                        foreach($fields['u_product'] as $pid => $v0) {
                                $s_orderby = func_query_first_cell("SELECT orderby FROM $sql_tbl[product_links] WHERE productid2 = '$pid' AND productid1 = '$productid'");
                                foreach($productids as $k => $v) {
                                        if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid1 = '$k' AND productid2 = '$pid'"))
                                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby, add_product) VALUES ('$k', '$pid', '$s_orderby', '1')");
                                }
                        }
                }
       
                if ($selected_productid && $productid!=$selected_productid) {
                        $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$productid'")+1;
                        db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby, add_product) VALUES ('$productid', '$selected_productid', '$orderby', '1')");
       
                        if ($bi_directional == "on") {
                                $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$selected_productid'")+1;
                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby, add_product) VALUES ('$selected_productid', '$productid', '$orderby', '1')");
                        }
                        if($fields['new_u_product'] && $productids) {
       
                                foreach($productids as $k => $v) {
                                        if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid1 = '$k' AND productid2 = '$selected_productid'")) {
                                                $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$k'")+1;
                                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby, add_product) VALUES ('$k', '$selected_productid', '$orderby', '1')");
                                        }
                                        if ($bi_directional == "on")
                                                if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid2 = '$k' AND productid1 = '$selected_productid'")) {
                                                        $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$selected_productid'")+1;
                                                        db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby, add_product) VALUES ('$selected_productid', '$k', '$orderby', '1')");
                                                }
                                }
                        }
                        $flag = true;
                }
       
                if ($flag) {
                        $top_message["content"] = func_get_langvar_by_name("msg_adm_product_upselling_upd");
                        $top_message["type"] = "I";
                }
       
                func_header_location("product_modify.php?mode=return&productid=$productid&section=upselling");
        } else {
                $flag = false;
                if(!empty($upselling)) {
                        foreach($upselling as $pid => $v) {
                                db_query("UPDATE $sql_tbl[product_links] SET orderby = '$v' WHERE productid2='$pid' AND productid1 = '$productid'");
                                $flag = true;
                        }
                }
       
                if($fields['u_product'] && $productids) {
                        foreach($fields['u_product'] as $pid => $v0) {
                                $s_orderby = func_query_first_cell("SELECT orderby FROM $sql_tbl[product_links] WHERE productid2 = '$pid' AND productid1 = '$productid'");
                                foreach($productids as $k => $v) {
                                        if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid1 = '$k' AND productid2 = '$pid'"))
                                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby) VALUES ('$k', '$pid', '$s_orderby')");
                                }
                        }
                }
       
                if ($selected_productid && $productid!=$selected_productid) {
                        $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$productid'")+1;
                        db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby) VALUES ('$productid', '$selected_productid', '$orderby')");
       
                        if ($bi_directional == "on") {
                                $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$selected_productid'")+1;
                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby) VALUES ('$selected_productid', '$productid', '$orderby')");
                        }
                        if($fields['new_u_product'] && $productids) {
       
                                foreach($productids as $k => $v) {
                                        if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid1 = '$k' AND productid2 = '$selected_productid'")) {
                                                $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$k'")+1;
                                                db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby) VALUES ('$k', '$selected_productid', '$orderby')");
                                        }
                                        if ($bi_directional == "on")
                                                if(!func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[product_links] WHERE productid2 = '$k' AND productid1 = '$selected_productid'")) {
                                                        $orderby = func_query_first_cell("SELECT MAX(orderby) FROM $sql_tbl[product_links] WHERE productid1 = '$selected_productid'")+1;
                                                        db_query("INSERT INTO $sql_tbl[product_links] (productid1, productid2, orderby) VALUES ('$selected_productid', '$k', '$orderby')");
                                                }
                                }
                        }
                        $flag = true;
                }
       
                if ($flag) {
                        $top_message["content"] = func_get_langvar_by_name("msg_adm_product_upselling_upd");
                        $top_message["type"] = "I";
                }
       
                func_header_location("product_modify.php?mode=return&productid=$productid&section=upselling");
        }
}

#
# Deleting upsales link from database
#
if ($mode == "del_upsale_link"){
        db_query("DELETE FROM $sql_tbl[product_links] WHERE productid1='$productid' AND productid2='$product_link'");
        $top_message["content"] = func_get_langvar_by_name("msg_adm_product_upselling_del");
        $top_message["type"] = "I";
        func_header_location("product_modify.php?mode=return&productid=$productid&section=upselling");
}

#
# Select all linked products
#
$product_links = func_query("select $sql_tbl[product_links].orderby, $sql_tbl[products].productid, $sql_tbl[products].product, $sql_tbl[products].productcode from $sql_tbl[products], $sql_tbl[product_links] where ($sql_tbl[products].productid=$sql_tbl[product_links].productid2) and ($sql_tbl[product_links].productid1='$productid') ORDER BY $sql_tbl[product_links].orderby, $sql_tbl[products].product");

$smarty->assign("product_links",$product_links);
?>


Lastly add a field "add_product" to the "product_link" table
ok to link the sales for the product go to upsell link in the backend/admin side

balinor 02-08-2006 03:29 AM

Moving to Custom Mods...the Add-Ons forum is for discussion of the official X-Cart add-ons. Thanks :)

Lucent88 02-13-2006 02:53 PM

can you provide example link? thanks

KooLisM 02-13-2006 05:54 PM

whats your email address?
i have to create an account so you can login to see it.

xcell67 07-12-2006 06:18 PM

This is interesting, does it work like Amazon's "why buy one, buy two and save?"

For example, you're looking at Mighty Ducks 1 Dvd product page. And then somewhere on the page, it asks you to purchase Mighty Ducks 1 and 2 to save some cash. When you click on add to cart, it adds both items.

alru111 07-23-2006 02:44 PM

I don't think it is ethical to add something to the cardt without customer knowing about it. This will definitely cause chargebacks or at least unhappy customers as some might not notice added products in the cart at checkout.

If instead you advise the customer about certain product when he purchases something, that would be more appropriate.


All times are GMT -8. The time now is 09:49 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.