function restore_contents()
 {
     if (!isset($_SESSION['customer_id'])) {
         return false;
     }
     // insert current cart contents in database
     if (is_array($this->contents)) {
         reset($this->contents);
         // Get database information
         $dbconn =& oosDBGetConn();
         $oostable =& oosDBGetTables();
         while (list($products_id, ) = each($this->contents)) {
             $qty = $this->contents[$products_id]['qty'];
             $towlid = $this->contents[$products_id]['towlid'];
             if ($_SESSION['customer_wishlist_link_id'] == $towlid) {
                 $towlid = '';
                 $customers_wishlisttable = $oostable['customers_wishlist'];
                 $dbconn->Execute("DELETE FROM {$customers_wishlisttable} WHERE customers_id= '" . intval($_SESSION['customer_id']) . "'  AND products_id = '" . oos_db_input($products_id) . "'");
                 $customers_wishlist_attributestable = $oostable['customers_wishlist_attributes'];
                 $dbconn->Execute("DELETE FROM {$customers_wishlist_attributestable} WHERE customers_id= '" . intval($_SESSION['customer_id']) . "'  AND products_id = '" . oos_db_input($products_id) . "'");
             }
             $customers_baskettable = $oostable['customers_basket'];
             $product_sql = "SELECT products_id\r\n                                FROM {$customers_baskettable}\r\n                                WHERE customers_id = '" . intval($_SESSION['customer_id']) . "'\r\n                                AND products_id = '" . intval($products_id) . "'";
             $product_result = $dbconn->Execute($product_sql);
             if (!$product_result->RecordCount()) {
                 $customers_baskettable = $oostable['customers_basket'];
                 $dbconn->Execute("INSERT INTO {$customers_baskettable}\r\n                                   (customers_id,\r\n                                    to_wishlist_id,\r\n                                    products_id,\r\n                                    customers_basket_quantity,\r\n                                    customers_basket_date_added) VALUES ('" . intval($_SESSION['customer_id']) . "',\r\n                                                                         '" . oos_db_input($towlid) . "',\r\n                                                                         '" . oos_db_input($products_id) . "',\r\n                                                                         '" . oos_db_input($qty) . "',\r\n                                                                         '" . oos_db_input(date("Y-m-d", time())) . "')");
                 if (isset($this->contents[$products_id]['attributes'])) {
                     reset($this->contents[$products_id]['attributes']);
                     while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                         $attr_value = $this->contents[$products_id]['attributes_values'][$option];
                         $customers_basket_attributestable = $oostable['customers_basket_attributes'];
                         $dbconn->Execute("INSERT INTO {$customers_basket_attributestable}\r\n                                            (customers_id,\r\n                                             products_id,\r\n                                             products_options_id,\r\n                                             products_options_value_id,\r\n                                             products_options_value_text) VALUES ('" . intval($_SESSION['customer_id']) . "',\r\n                                                                                  '" . oos_db_input($products_id) . "',\r\n                                                                                  '" . oos_db_input($option) . "',\r\n                                                                                  '" . oos_db_input($value) . "',\r\n                                                                                  '" . oos_db_input($attr_value) . "')");
                     }
                 }
             } else {
                 $customers_baskettable = $oostable['customers_basket'];
                 $dbconn->Execute("UPDATE {$customers_baskettable}\r\n                                      SET customers_basket_quantity = '" . intval($qty) . "'\r\n                                      WHERE customers_id = '" . intval($_SESSION['customer_id']) . "' AND\r\n                                            products_id = '" . oos_db_input($products_id) . "'");
             }
         }
         if (isset($_SESSION['gv_id'])) {
             MyOOS_CoreApi::requireOnce('functions/function_coupon.php');
             $remote = $_SESSION['session_ip_address'];
             $coupon_redeem_tracktable = $oostable['coupon_redeem_track'];
             $gv_result = $dbconn->Execute("INSERT INTO {$coupon_redeem_tracktable}\r\n                                              (coupon_id,\r\n                                               customer_id,\r\n                                               redeem_date,\r\n                                               redeem_ip) VALUES ('" . oos_db_input($_SESSION['gv_id']) . "',\r\n                                                                  '" . intval($_SESSION['customer_id']) . "',\r\n                                                                  '" . date("Y-m-d H:i:s", time()) . "',\r\n                                                                  '" . oos_db_input($remote) . "')");
             $couponstable = $oostable['coupons'];
             $gv_update = $dbconn->Execute("UPDATE {$couponstable}\r\n                                               SET coupon_active = 'N'\r\n                                               WHERE coupon_id = '" . oos_db_input($_SESSION['gv_id']) . "'");
             oos_gv_account_update($_SESSION['customer_id'], $_SESSION['gv_id']);
             unset($_SESSION['gv_id']);
         }
     }
     // reset per-session cart contents, but not the database contents
     $this->reset(false);
     $customers_baskettable = $oostable['customers_basket'];
     $sql = "SELECT products_id, to_wishlist_id, customers_basket_quantity\r\n                FROM {$customers_baskettable}\r\n                WHERE customers_id = '" . intval($_SESSION['customer_id']) . "'";
     $products_result = $dbconn->Execute($sql);
     while ($products = $products_result->fields) {
         $this->contents[$products['products_id']] = array('qty' => $products['customers_basket_quantity'], 'towlid' => $products['to_wishlist_id']);
         // attributes
         $customers_basket_attributestable = $oostable['customers_basket_attributes'];
         $sql = "SELECT products_options_id, products_options_value_id, products_options_value_text\r\n                    FROM {$customers_basket_attributestable}\r\n                    WHERE customers_id = '" . intval($_SESSION['customer_id']) . "'\r\n                    AND products_id = '" . $products['products_id'] . "'";
         $attributes_result = $dbconn->Execute($sql);
         while ($attributes = $attributes_result->fields) {
             $this->contents[$products['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
             if ($attributes['products_options_value_id'] == PRODUCTS_OPTIONS_VALUE_TEXT_ID) {
                 $this->contents[$products['products_id']]['attributes_values'][$attributes['products_options_id']] = $attributes['products_options_value_text'];
             }
             // Move that ADOdb pointer!
             $attributes_result->MoveNext();
         }
         // Move that ADOdb pointer!
         $products_result->MoveNext();
     }
     $this->cleanup();
 }
Exemplo n.º 2
0
            // check for require_onced session variables
            $_SESSION['gv_id'] = $coupon['coupon_id'];
            $bError = false;
        }
    }
} else {
    MyOOS_CoreApi::redirect(oos_href_link($aPages['main']));
}
if (!$bError && isset($_SESSION['customer_id'])) {
    // Update redeem status
    $remote_addr = $_SESSION['session_ip_address'];
    $coupon_email_tracktable = $oostable['coupon_email_track'];
    $gv_result = $dbconn->Execute("INSERT INTO {$coupon_email_tracktable}\n                            (coupon_id,\n                             customer_id,\n                             redeem_date,\n                             redeem_ip) VALUES ('" . $coupon['coupon_id'] . "',\n                                                '" . intval($_SESSION['customer_id']) . "',\n                                                '" . date("Y-m-d H:i:s", time()) . "',\n                                                '" . oos_db_input($remote_addr) . "')");
    $couponstable = $oostable['coupons'];
    $gv_update = $dbconn->Execute("UPDATE {$couponstable}\n                               SET coupon_active = 'N'\n                               WHERE coupon_id = '" . $coupon['coupon_id'] . "'");
    oos_gv_account_update($_SESSION['customer_id'], $_SESSION['gv_id']);
    unset($_SESSION['gv_id']);
}
// links breadcrumb
$oBreadcrumb->add($aLang['navbar_title']);
// if we get here then either the url gv_no was not set or it was invalid
// so output a message.
$sMessage = sprintf($aLang['text_valid_gv'], $oCurrencies->format($coupon['coupon_amount']));
if ($bError) {
    $sMessage = $aLang['text_invalid_gv'];
}
$aOption['template_main'] = $sTheme . '/modules/redeem.html';
$aOption['page_heading'] = $sTheme . '/heading/page_heading.html';
$aOption['breadcrumb'] = 'default/system/breadcrumb.html';
$nPageType = OOS_PAGE_TYPE_MAINPAGE;
require 'includes/oos_system.php';