function restore_contents() { global $customer_id, $gv_id, $REMOTE_ADDR; if (!smn_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']; // store id is getting lost when a shopper add items, THEN logs in $ID = $this->get_store_id($products_id); //$ID = $this->contents[$products_id]['store_id'];^M $product_query = smn_db_query("select * from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_db_input($products_id) . "'"); if (!smn_db_num_rows($product_query)) { smn_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added, store_id) values ('" . (int) $customer_id . "', '" . smn_db_input($products_id) . "', '" . smn_db_input($qty) . "', '" . date('Ymd') . "', '" . smn_db_input($ID) . "')"); if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { smn_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, store_id) values ('" . (int) $customer_id . "', '" . smn_db_input($products_id) . "', '" . (int) $option . "', '" . (int) $value . "', '" . smn_db_input($ID) . "')"); } } } else { smn_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . smn_db_input($qty) . "' where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_db_input($products_id) . "'"); } } if (smn_session_is_registered('gv_id')) { $gv_query = smn_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 = smn_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_id . "'"); smn_gv_account_update($customer_id, $gv_id); smn_session_unregister('gv_id'); } } // reset per-session cart contents, but not the database contents $this->reset(false); $products_query = smn_db_query("select products_id, store_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int) $customer_id . "'"); while ($products = smn_db_fetch_array($products_query)) { $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity'], 'store_id' => $products['store_id']); // attributes $attributes_query = smn_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int) $customer_id . "' and products_id = '" . smn_db_input($products['products_id']) . "'"); while ($attributes = smn_db_fetch_array($attributes_query)) { $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id']; } } $this->cleanup(); }
// check if coupon exist if (smn_db_num_rows($gv_query) > 0) { $coupon = smn_db_fetch_array($gv_query); // check if coupon_id exist and coupon not redeemed if ($coupon['coupon_id'] > 0 && $coupon['redeemed'] == 'false') { smn_session_unregister('floating_gv_code'); $gv_query = smn_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 = smn_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'"); smn_gv_account_update($customer_id, $coupon['coupon_id']); } } } //********** /******************************************************* **** create_account.php *********************************** *******************************************************/ if (smn_session_is_registered('floating_gv_code')) { $gv_query = smn_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 (smn_db_num_rows($gv_query) > 0) { $coupon = smn_db_fetch_array($gv_query); // check if coupon_id exist and coupon not redeemed if ($coupon['coupon_id'] > 0 && $coupon['redeemed'] == 'false') { smn_session_unregister('floating_gv_code'); $gv_query = smn_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 = smn_db_query("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'"); smn_gv_account_update($customer_id, $coupon['coupon_id']); } } } $breadcrumb->add(NAVBAR_TITLE);