function restore_contents()
 {
     /* ** Altered for CCGV **
           global $customer_id;
     */
     global $customer_id, $gv_id, $REMOTE_ADDR;
     /* ** EOF alterations for CCGV ** */
     if (!tep_session_is_registered('customer_id')) {
         return false;
     }
     // insert current cart contents in database
     if (is_array($this->contents)) {
         reset($this->contents);
         while (list($products_id, ) = each($this->contents)) {
             $qty = $this->contents[$products_id]['qty'];
             $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             if (!tep_db_num_rows($product_query)) {
                 tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
                 if (isset($this->contents[$products_id]['attributes'])) {
                     reset($this->contents[$products_id]['attributes']);
                     while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                         tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . (int) $option . "', '" . (int) $value . "')");
                     }
                 }
             } else {
                 tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             }
         }
         /* ** Altered for CCGV ** */
         if (tep_session_is_registered('gv_id')) {
             $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_id . "', '" . (int) $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
             $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'Y' where coupon_id = '" . $gv_id . "'");
             tep_gv_account_update($customer_id, $gv_id);
             tep_session_unregister('gv_id');
         }
         /* ** EOF alterations for CCGV ** */
     }
     // reset per-session cart contents, but not the database contents
     $this->reset(false);
     $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "'");
     while ($products = tep_db_fetch_array($products_query)) {
         $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
         // attributes
         $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
         while ($attributes = tep_db_fetch_array($attributes_query)) {
             $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
         }
     }
     $this->cleanup();
     // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
 }
Example #2
0
 function restore_contents()
 {
     // ############Added CCGV Contribution ##########
     global $customer_id, $gv_id, $REMOTE_ADDR;
     //      global $customer_id;
     // ############ End Added CCGV Contribution ##########
     //      global $customer_id;
     $mydb =& XoopsDatabaseFactory::getDatabaseConnection();
     if (!tep_session_is_registered('customer_id')) {
         return false;
     }
     // insert current cart contents in database
     if (is_array($this->contents)) {
         reset($this->contents);
         while (list($products_id, ) = each($this->contents)) {
             $qty = $this->contents[$products_id]['qty'];
             $product_query = $mydb->queryF("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             if (!$mydb->getRowsNum($product_query)) {
                 $mydb->query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')");
                 if (isset($this->contents[$products_id]['attributes'])) {
                     reset($this->contents[$products_id]['attributes']);
                     while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                         $mydb->queryF("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . (int) $option . "', '" . (int) $value . "')");
                     }
                 }
             } else {
                 $mydb->queryF("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             }
         }
         // ############ Added CCGV Contribution ##########
         if (tep_session_is_registered('gv_id')) {
             $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_id . "', '" . (int) $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
             $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_id . "'");
             tep_gv_account_update($customer_id, $gv_id);
             tep_session_unregister('gv_id');
         }
         // ############ End Added CCGV Contribution ##########
     }
     // reset per-session cart contents, but not the database contents
     $this->reset(false);
     $products_query = $mydb->query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "'");
     while ($products = $mydb->fetchArray($products_query)) {
         $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
         // attributes
         $attributes_query = $mydb->query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
         while ($attributes = $mydb->fetchArray($attributes_query)) {
             $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
         }
     }
     $this->cleanup();
 }
 function restore_contents()
 {
     // Start - CREDIT CLASS Gift Voucher Contribution
     //    global $customer_id;
     global $customer_id, $gv_id, $_SERVER;
     // End - CREDIT CLASS Gift Voucher Contribution
     if (!tep_session_is_registered('customer_id')) {
         return false;
     }
     // insert current cart contents in database
     if (is_array($this->contents)) {
         reset($this->contents);
         while (list($products_id, ) = each($this->contents)) {
             $qty = $this->contents[$products_id]['qty'];
             $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "' ORDER BY customers_basket_id asc");
             if (!tep_db_num_rows($product_query)) {
                 tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
                 if (isset($this->contents[$products_id]['attributes'])) {
                     reset($this->contents[$products_id]['attributes']);
                     while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                         tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . (int) $option . "', '" . (int) $value . "')");
                     }
                 }
             } else {
                 tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             }
         }
         // Start - CREDIT CLASS Gift Voucher Contribution
         if (tep_session_is_registered('gv_id')) {
             $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_id . "', '" . (int) $customer_id . "', now(),'" . $_SERVER['REMOTE_ADDR'] . "')");
             $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_id . "'");
             tep_gv_account_update($customer_id, $gv_id);
             tep_session_unregister('gv_id');
         }
         // End - CREDIT CLASS Gift Voucher Contribution
     }
     // reset per-session cart contents, but not the database contents
     $this->reset(false);
     $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' ORDER BY customers_basket_id asc");
     while ($products = tep_db_fetch_array($products_query)) {
         $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity']);
         // attributes
         $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
         while ($attributes = tep_db_fetch_array($attributes_query)) {
             $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
         }
     }
     $this->cleanup();
 }
Example #4
0
            if (!tep_session_is_registered('gv_id')) {
                tep_session_register('gv_id');
            }
            $gv_id = $coupon['coupon_id'];
            $error = false;
        } else {
            $error = true;
        }
    }
} else {
    tep_redirect(FILENAME_DEFAULT);
}
if (!$error && tep_session_is_registered('customer_id')) {
    $gv_query = tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $customer_id . "', now(),'" . $_SERVER['REMOTE_ADDR'] . "')");
    $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
    tep_gv_account_update($customer_id, $gv_id);
    tep_session_unregister('gv_id');
}
$breadcrumb->add(Translate('Redeem Gift Certificate'));
require DIR_WS_INCLUDES . 'header.php';
require DIR_WS_INCLUDES . 'column_left.php';
?>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
	<tr>
		<td>
			<h1><?php 
echo Translate('Validate Cadeaubon');
?>
</h1>
		</td>
	</tr>
Example #5
0
****  create_account.php  ***********************************
*******************************************************/
//before: tep_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
//---------
//add these:
if (tep_session_is_registered('floating_gv_code')) {
    $gv_query = tep_db_query("SELECT c.coupon_id, c.coupon_amount, IF(rt.coupon_id>0, 'true', 'false') AS redeemed FROM " . TABLE_COUPONS . " c LEFT JOIN " . TABLE_COUPON_REDEEM_TRACK . " rt USING(coupon_id), " . TABLE_COUPON_EMAIL_TRACK . " et WHERE c.coupon_code = '" . $floating_gv_code . "' AND c.coupon_id = et.coupon_id");
    // check if coupon exist
    if (tep_db_num_rows($gv_query) > 0) {
        $coupon = tep_db_fetch_array($gv_query);
        // check if coupon_id exist and coupon not redeemed
        if ($coupon['coupon_id'] > 0 && $coupon['redeemed'] == 'false') {
            tep_session_unregister('floating_gv_code');
            $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
            $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
            tep_gv_account_update($customer_id, $coupon['coupon_id']);
        }
    }
}
/*******************************************************
****  /includes/languages/english/gv_redeem.php ******************
*******************************************************/
// add:
define('TEXT_NEEDS_TO_LOGIN', 'We are sorry but we are unable to process your Gift Voucher claim at this time. You need to login first or create an account with us, if you don\'t already have one, before you can claim your Gift Voucher. Please <a href="' . tep_href_link(FILENAME_LOGIN, '', 'SSL') . '">click here to login or create an account.</a> ');
$breadcrumb->add(NAVBAR_TITLE);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php 
echo HTML_PARAMS;
?>
>
    function redeemCoupon($code)
    {
        //BOF KGT
        if (MODULE_ORDER_TOTAL_COUPON_STATUS == 'true') {
            //EOF KGT
            global $customer_id, $order;
            $error = false;
            if ($code) {
                // get some info from the coupon table
                $coupon_query = tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='" . $code . "' and coupon_active='Y'");
                $coupon_result = tep_db_fetch_array($coupon_query);
                if ($coupon_result['coupon_type'] != 'G') {
                    if (MODULE_ORDER_TOTAL_COUPON_STATUS == 'true') {
                        if (tep_db_num_rows($coupon_query) == 0) {
                            $error = true;
                            $errMsg = ERROR_NO_INVALID_REDEEM_COUPON;
                        }
                        $date_query = tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='" . $code . "'");
                        if (tep_db_num_rows($date_query) == 0) {
                            $error = true;
                            $errMsg = ERROR_INVALID_STARTDATE_COUPON;
                        }
                        $date_query = tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='" . $code . "'");
                        if (tep_db_num_rows($date_query) == 0) {
                            $error = true;
                            $errMsg = ERROR_INVALID_FINISDATE_COUPON;
                        }
                        $coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "'");
                        $coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "' and customer_id = '" . $customer_id . "' and customer_id>0");
                        if (tep_db_num_rows($coupon_count) >= $coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {
                            $error = true;
                            $errMsg = ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES;
                        }
                        if (tep_db_num_rows($coupon_count_customer) >= $coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {
                            $error = true;
                            $errMsg = ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES;
                        }
                        if ($error === false) {
                            global $order_total_modules, $cc_id;
                            $cc_id = $coupon_result['coupon_id'];
                            if (!tep_session_is_registered('cc_id')) {
                                tep_session_register('cc_id');
                            }
                            $order_total_modules->pre_confirmation_check();
                            return '{
				  "success": "true"
				}';
                        }
                    }
                } else {
                    if ($coupon_result['coupon_type'] == 'G') {
                        if (MODULE_ORDER_TOTAL_GV_STATUS == 'true') {
                            $date_query = tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='" . $code . "'");
                            $coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "'");
                            $coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id'] . "' and customer_id = '" . $customer_id . "' and customer_id>0");
                            if (tep_db_num_rows($coupon_count) >= $coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {
                                $error = true;
                                $errMsg = ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES;
                            }
                            if (tep_db_num_rows($coupon_count_customer) >= $coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {
                                $error = true;
                                $errMsg = ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES;
                            }
                            if ($error === false) {
                                $voucher_number = tep_db_prepare_input($code);
                                $gv_query = tep_db_query("select c.coupon_id, c.coupon_amount from " . TABLE_COUPONS . " c, " . TABLE_COUPON_EMAIL_TRACK . " et where coupon_code = '" . addslashes($voucher_number) . "' and c.coupon_id = et.coupon_id");
                                if (tep_db_num_rows($gv_query) > 0) {
                                    $coupon = tep_db_fetch_array($gv_query);
                                    $redeem_query = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon['coupon_id'] . "'");
                                    if (tep_db_num_rows($redeem_query) == 0) {
                                        // check for required session variables
                                        if (!tep_session_is_registered('gv_id')) {
                                            tep_session_register('gv_id');
                                        }
                                        $gv_id = $coupon['coupon_id'];
                                        $error = false;
                                    } else {
                                        $error = true;
                                    }
                                }
                                if (!$error && tep_session_is_registered('customer_id')) {
                                    // Update redeem status
                                    $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
                                    $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
                                    tep_gv_account_update($customer_id, $gv_id);
                                    return '{
						"success": "gift"
					}';
                                }
                            }
                        }
                    }
                }
            }
            //BOF KGT
        } else {
            if (MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true') {
                global $customer_id, $order;
                $check_code_query = tep_db_query($sql = "SELECT dc.*\n                                                  FROM " . TABLE_DISCOUNT_COUPONS . " dc\n                                                  WHERE coupons_id = '" . tep_db_input($code) . "'\n                                                    AND ( coupons_date_start <= CURDATE() OR coupons_date_start IS NULL )\n                                                    AND ( coupons_date_end >= CURDATE() OR coupons_date_end IS NULL )");
                if (tep_db_num_rows($check_code_query) != 1) {
                    //if no rows are returned, then they haven't entered a valid code
                    $message = ENTRY_DISCOUNT_COUPON_ERROR;
                    //display the error message
                    return '{
              "success": "false"
            }';
                } else {
                    if (tep_session_is_registered('customer_id') && (int) $customer_id > 0) {
                        //customer_exclusions
                        $check_user_query = tep_db_query($sql = 'SELECT dc2u.customers_id
                                                      FROM ' . TABLE_DISCOUNT_COUPONS_TO_CUSTOMERS . ' dc2u
                                                      WHERE customers_id=' . (int) $customer_id . '
                                                        AND coupons_id="' . tep_db_input($code) . '"');
                        if (tep_db_num_rows($check_user_query) > 0) {
                            $message = ENTRY_DISCOUNT_COUPON_ERROR;
                            //display the error message
                            //use this to debug exclusions:
                            //$this->message( 'Customer exclusion check failed' );
                            return '{
              "success": "false"
            }';
                        }
                    }
                    //shipping zone exclusions
                    $delivery = $order->delivery;
                    $check_user_query = tep_db_query($sql = 'SELECT dc2z.geo_zone_id
                                                    FROM ' . TABLE_DISCOUNT_COUPONS_TO_ZONES . ' dc2z
                                                    LEFT JOIN ' . TABLE_ZONES_TO_GEO_ZONES . ' z2g
                                                      USING( geo_zone_id )
                                                    WHERE ( z2g.zone_id=' . (int) $delivery['zone_id'] . ' or z2g.zone_id = 0 or z2g.zone_id IS NULL )
                                                      AND ( z2g.zone_country_id=' . (int) $delivery['country_id'] . ' or z2g.zone_country_id = 0 )
                                                      AND dc2z.coupons_id="' . tep_db_input($code) . '"');
                    if (tep_db_num_rows($check_user_query) > 0) {
                        $message = ENTRY_DISCOUNT_COUPON_ERROR;
                        //display the error message
                        //use this to debug exclusions:
                        //$this->message( 'Shipping Zones exclusion check failed' );
                        return '{
              "success": "false"
            }';
                    }
                    //end shipping zone exclusions
                    $row = tep_db_fetch_array($check_code_query);
                    //since there is one record, we have a valid code
                    $order->coupon = $row;
                    return '{
              "success": "true"
            }';
                }
            }
        }
        //EOF KGT
        return '{
              "success": "false", "message":"7. end"
            }';
    }
Example #7
0
 function restore_contents()
 {
     // BOF - MOD: CREDIT CLASS Gift Voucher Contribution
     //    global $customer_id;
     global $customer_id, $gv_id, $REMOTE_ADDR, $languages_id;
     // languages_id needed for PriceFormatter - QPBPP
     // EOF - MOD: CREDIT CLASS Gift Voucher Contribution
     if (!tep_session_is_registered('customer_id')) {
         return false;
     }
     // insert current cart contents in database
     if (is_array($this->contents)) {
         reset($this->contents);
         while (list($products_id, ) = each($this->contents)) {
             $qty = $this->contents[$products_id]['qty'];
             // BOF QPBPP for SPPC adjust quantity blocks and min_order_qty for this customer group
             // warnings about this are raised in PriceFormatter
             $pf = new PriceFormatter();
             $pf->loadProduct(tep_get_prid($products_id), $languages_id);
             $qty = $pf->adjustQty($qty);
             // EOF QPBPP for SPPC
             $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             if (!tep_db_num_rows($product_query)) {
                 tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
                 if (isset($this->contents[$products_id]['attributes'])) {
                     reset($this->contents[$products_id]['attributes']);
                     while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                         tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int) $customer_id . "', '" . tep_db_input($products_id) . "', '" . (int) $option . "', '" . (int) $value . "')");
                     }
                 }
             } else {
                 tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
             }
         }
         // BOF - MOD: CREDIT CLASS Gift Voucher Contribution
         if (tep_session_is_registered('gv_id')) {
             $gv_query = tep_db_query("insert into  " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_id . "', '" . (int) $customer_id . "', now(),'" . $REMOTE_ADDR . "')");
             $gv_update = tep_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_id . "'");
             tep_gv_account_update($customer_id, $gv_id);
             tep_session_unregister('gv_id');
         }
         // EOF - MOD: CREDIT CLASS Gift Voucher Contribution
     }
     // reset per-session cart contents, but not the database contents
     $this->reset(false);
     // LINE MODED: QPBPP for SPPC v4.2$
     // BOF QPBPP for SPPC
     global $sppc_customer_group_id;
     if (tep_session_is_registered('sppc_customer_group_id')) {
         $this->cg_id = $sppc_customer_group_id;
     } else {
         $this->cg_id = '0';
     }
     $products_query = tep_db_query("select p.products_status, cb.products_id, ptdc.discount_categories_id, customers_basket_quantity from " . TABLE_PRODUCTS . " p, " . TABLE_CUSTOMERS_BASKET . " cb left join (select products_id, discount_categories_id from " . TABLE_PRODUCTS_TO_DISCOUNT_CATEGORIES . " where customers_group_id = '" . $this->cg_id . "') as ptdc on cb.products_id = ptdc.products_id where customers_id = '" . (int) $customer_id . "' and cb.products_id = p.products_id");
     while ($products = tep_db_fetch_array($products_query)) {
         if ($products['products_status'] == 1) {
             // EOF Attribute Product Codes
             $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity'], 'discount_categories_id' => $products['discount_categories_id']);
             // EOF QPBPP for SPPC
             // attributes
             $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "'");
             while ($attributes = tep_db_fetch_array($attributes_query)) {
                 $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
             }
         } else {
             $this->remove($products['products_id']);
         }
     }
     $this->cleanup();
     // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
 }