[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> wishlist.php (source)

   1  <?php
   2  /*

   3    $Id: wishlist.php,v 3.0  2005/08/24 Dennis Blake

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Released under the GNU General Public License

   8  */
   9  
  10    class wishlist {
  11      var $wishID;
  12  
  13  
  14  	function wishlist() {
  15            $this->reset();
  16      }
  17  
  18  	function restore_wishlist() {
  19      global $customer_id;
  20  
  21          if (!tep_session_is_registered('customer_id')) return false;
  22  
  23      // merge current wishlist items in database

  24          if (is_array($this->wishID)) {
  25              reset($this->wishID);
  26  
  27              while (list($wishlist_id, ) = each($this->wishID)) {
  28                  $wishlist_query = tep_db_query("select products_id from " . TABLE_WISHLIST . " where customers_id = '" . $customer_id . "' and products_id = '" . $wishlist_id . "'");
  29                  if (!tep_db_num_rows($wishlist_query)) {
  30                         tep_db_query("insert into " . TABLE_WISHLIST . " (customers_id, products_id) values ('" . $customer_id . "', '" . $wishlist_id . "')");
  31                      if (isset($this->wishID[$wishlist_id]['attributes'])) {
  32                            reset($this->wishID[$wishlist_id]['attributes']);
  33                          while (list($option, $value) = each($this->wishID[$wishlist_id]['attributes'])) {
  34                                  tep_db_query("insert into " . TABLE_WISHLIST_ATTRIBUTES . " (customers_id, products_id, products_options_id , products_options_value_id) values ('" . $customer_id . "', '" . $wishlist_id . "', '" . $option . "', '" . $value . "' )");
  35                          }
  36                      }
  37                  }
  38              }
  39          }
  40  
  41          // reset session contents

  42          unset($this->wishID);
  43  
  44          $wishlist_session = tep_db_query("select products_id from " . TABLE_WISHLIST . " where customers_id = '" . $customer_id . "'");
  45          while($wishlist = tep_db_fetch_array($wishlist_session)) {
  46              $this->wishID[$wishlist['products_id']] = array($wishlist['products_id']);
  47          // attributes

  48                 $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_WISHLIST_ATTRIBUTES . " where customers_id = '" . $customer_id . "' and products_id = '" . $wishlist['products_id'] . "'");
  49                 while ($attributes = tep_db_fetch_array($attributes_query)) {
  50                   $this->wishID[$wishlist['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
  51                 }
  52          }
  53      }
  54  
  55  	function add_wishlist($wishlist_id, $attributes_id) {
  56        global $customer_id;
  57  
  58  
  59          if(!$this->in_wishlist($wishlist_id)) {
  60  
  61              $wishlist_id = tep_get_uprid($wishlist_id, $attributes_id);
  62              // Insert into session

  63              $this->wishID[$wishlist_id] = array($wishlist_id);
  64  
  65              if (tep_session_is_registered('customer_id')) {
  66              // Insert into database

  67                     tep_db_query("insert into " . TABLE_WISHLIST . " (customers_id, products_id) values ('" . $customer_id . "', '" . $wishlist_id . "')");
  68              }
  69  
  70                 // Read array of options and values for attributes in id[]

  71              if (is_array($attributes_id)) {
  72                  reset($attributes_id);
  73                  while (list($option, $value) = each($attributes_id)) {
  74                      $this->wishID[$wishlist_id]['attributes'][$option] = $value;
  75                         // Add to customers_wishlist_attributes table

  76                      if (tep_session_is_registered('customer_id')) {
  77                          tep_db_query("insert into " . TABLE_WISHLIST_ATTRIBUTES . " (customers_id, products_id, products_options_id , products_options_value_id) values ('" . $customer_id . "', '" . $wishlist_id . "', '" . $option . "', '" . $value . "' )");
  78                      }
  79                  }
  80                  tep_session_unregister('attributes_id');
  81                }
  82          }
  83      }
  84  
  85  	function remove($wishlist_id) {
  86      global $customer_id;
  87  
  88          // Remove from session

  89          unset($this->wishID[$wishlist_id]);
  90  
  91          //remove from database

  92          if (tep_session_is_registered('customer_id')) {
  93              tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . $wishlist_id . "' and customers_id = '" . $customer_id . "'");
  94              tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . $wishlist_id . "' and customers_id = '" . $customer_id . "'");
  95          }
  96      }
  97  
  98  
  99  	function clear() {
 100      global $customer_id;
 101  
 102          // Remove all from database

 103            if (tep_session_is_registered('customer_id')) {
 104                 $wishlist_products_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . $customer_id . "'");
 105                while($wishlist_products = tep_db_fetch_array($wishlist_products_query)) {
 106                  tep_db_query("delete from " . TABLE_WISHLIST . " where products_id = '" . $wishlist_products[products_id] . "' and customers_id = '" . $customer_id . "'");
 107                  tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where products_id = '" . $wishlist_products[products_id] . "' and customers_id = '" . $customer_id . "'");
 108                }
 109          }
 110      }
 111  
 112  	function reset($reset_database = false) {
 113        global $customer_id;
 114  
 115          // Remove all from database

 116          if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
 117              tep_db_query("delete from " . TABLE_WISHLIST . " where customers_id = '" . $customer_id . "'");
 118              tep_db_query("delete from " . TABLE_WISHLIST_ATTRIBUTES . " where customers_id = '" . $customer_id . "'");
 119            }
 120  
 121          // reset session contents

 122          unset($this->wishID);        
 123      }
 124  
 125  	function in_wishlist($wishlist_id) {
 126      global $customer_id;
 127  
 128          if (isset($this->wishID[$wishlist_id])) {
 129              return true;
 130            } else {
 131              return false;
 132            }
 133      }
 134  
 135  
 136  	function get_att($wishlist_id) {
 137          $pieces = explode('{', $wishlist_id);
 138  
 139          return $pieces[0];
 140      }
 141  
 142      function count_wishlist() {  // get total number of items in wishlist 
 143        $total_items = 0;
 144        if (is_array($this->wishID)) {
 145          reset($this->wishID);
 146          while (list($wishlist_id, ) = each($this->wishID)) {
 147            $total_items++;
 148          }
 149        }
 150  
 151        return $total_items;
 152      }
 153  
 154    }
 155  
 156  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7