_exists()) // sets id if exists { $this->_set(); $this->num_items = 0; $this->items_amount = 0; } else { $this->set_items($Designers, $Items, $Sizes, $Template, $Promotion); } } function _exists() { // returns true if cart is set if(isset($_COOKIE[$this->cookie_name])) { $this->_get(); return(TRUE); } else { return(FALSE); } } function _get() { $this->id = $_COOKIE[$this->cookie_name]; } function _set() { $this->_insert(); setcookie($this->cookie_name, $this->id, time()+60*60*24*90, '/'); // 90 days } function _insert() { $ins = "INSERT INTO ".Config::$db_tables['carts']." VALUES(NULL, NOW(), '".Tracker::$cookie_id."')"; return($this->id = Database::ado_execute_query($ins, 'Cart::insert_cart')); } function _delete() { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['cart_items']." WHERE cart_id='".$this->id."'", "Cart::delete cart items"); $del = "DELETE FROM ".Config::$db_tables['carts']." WHERE id='$this->id' LIMIT 1"; return(Database::ado_execute_query($del, 'Cart::_delete')); } function update_item_quantity($cart_item_id, $qty) { $upd = "UPDATE ".Config::$db_tables['cart_items']." SET item_qty='$qty' WHERE id='$cart_item_id' LIMIT 1"; return(Database::ado_execute_query($upd, 'Cart::update_item_quantity')); } function insert_item($item_id, $item_color_id, $size_id, $quantity=1) { // if item already there just update qty if nec if($cart_item_record = $this->item_search($item_id, $item_color_id, $size_id)) { return($this->update_item_quantity($cart_item_record['id'], $quantity)); } else { $ins_fields = array( 'id' => 'NULL', 'cart_id' => $this->id, 'item_id' => $item_id, 'item_qty' => $quantity, 'item_color_id' => $item_color_id, 'size_id' => $size_id, 'enter_dt' => 'NOW()' ); return(Database::_insert(Config::$db_tables['cart_items'], $ins_fields, 'Cart::insert_item')); } } function item_search($item_id, $item_color_id, $size_id) { // returns cart_item_id or FALSE return(Database::ado_get_row("SELECT id FROM ".Config::$db_tables['cart_items']." WHERE cart_id=".$this->id." AND item_id='$item_id' AND item_color_id='$item_color_id' AND size_id='$size_id'", "Cart:: item_search")); } function is_item_in($item_id) { // just checks for item in general, not specific color/size combo - see item_search $sel = "SELECT * FROM ".Config::$db_tables['cart_items']." WHERE cart_id=".$this->id." AND item_id='$item_id'"; return(Database::ado_get_row($sel, 'Cart::is_item_in')); } function remove_cookie() { setcookie($$this->cookie_name, $this->id, time()-60000, '/'); // 90 days } function remove_item($cart_item_id) { $del = "DELETE FROM ".Config::$db_tables['cart_items']." WHERE id='$cart_item_id' LIMIT 1"; return(Database::ado_execute_query($del, 'Cart::remove_item')); } function _empty() { $del = "DELETE FROM ".Config::$db_tables['cart_items']." WHERE cart_id='".$this->id."'"; return(Database::ado_execute_query($del, 'Cart::_empty')); } function get_items_RS($echo = FALSE) { if(!isset($this->items_RS)) { if($echo){echo 'setting items RS';} $this->set_items_RS(); } else { if($echo){echo 'NOT setting items RS';} } return($this->items_RS); } function set_items_RS() { $sel = "SELECT * FROM ".Config::$db_tables['cart_items']." WHERE cart_id='".$this->id."' ORDER BY id DESC"; //echo $sel; $this->items_RS = Database::ado_execute_query($sel, "Cart::set_items_RS"); } function set_items($Designers, $Items, $Sizes, $Template, $Promotion) { $this->html = '
'; $items_html = ''; // either gets populated with item rows and total info or bag is empty message and featured designer $preorders = array(); // stores preorder dates $backorders = array(); // stores backorder dates // note - not necessarily all items in cart are still avail on web. loop thru cart items, adding avail ones to this array and deleting unavail ones $i = 0; while($row = $this->get_items_RS()->FetchRow()) // :: for some reason does not work { ++$i; $Item = new Item($row['item_id']); $Item->set_data(); if(!$Item->is_live_web($Items)) { $this->remove_item($row['id']); } else { $item_designer = $Designers->get_name($Item->data['designer_id'], 'Cart::set_html'); $spcr_cell = ''; if($i == 1) { $items_html .= ' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '; } else { $items_html .= ' '; } $Item->set_cross_sells(); if( (!isset($this->cross_sell_html) || $this->cross_sell_html == '') && count($Item->cross_sells) > 0) { // a cross sell row for the last item added to the cart (or prior items if the last item has no cross sells) $this->set_cross_sell_html($Items, $Sizes, $Designers, $Item); } ///////////////////////////////////////////////// // item cell (pic) $Item->set_images($Items); $Item->set_web_images($Items); { $item_cell = ''.$Item->img_html($Items, 'thumb').''; } // description cell $Item->set_web_colors_and_sizes($Sizes); $asterisks = ''; // check if it is a preorder or a backorder if($Item->is_preorder($row['item_color_id'], $row['size_id'])) { $preorders[] = Utilities::informal_date($Item->data['available_date']); foreach($preorders as $preorder) { $asterisks .= "*"; } foreach($backorders as $backorder) { $asterisks .= "*"; } } elseif($row['item_color_id'] != '' && $row['item_color_id'] != '0' && $back = $Item->backorder_date($row['item_color_id'])) { $backorders[] = $back; foreach($preorders as $preorder) { $asterisks .= "*"; } foreach($backorders as $backorder) { $asterisks .= "*"; } } $item_name = ($Item->data['short_name'] != '') ? $Item->data['short_name'] : substr($Item->data['name'], 0 , 21); $link_title = (count($Item->web_colors) > 1) ? 'add this in more colors' : 'view item'; $description_cell = ''.$asterisks.'' . ''.Utilities::quotes_to_html($item_designer).' '.Utilities::quotes_to_html($item_name).''; $color_cell = ($row['item_color_id'] != '' && $row['item_color_id'] != '0') ? $Item->colors[$row['item_color_id']]['name'] : ' '; $size_cell = ($row['size_id'] != '' && $row['size_id'] != '0') ? $Item->sizes[$row['size_id']] : ' '; ///////////////////////////////////////////////// $price = $Item->get_web_price($Promotion); $price_cell = ''; if($Item->get_on_sale('web') || $Item->get_on_promotion_web($Promotion)) { $price_cell .= '$'.number_format($Item->data['price_web'], 2).' '; } $price_cell .= '$'.number_format($price, 2); $Item->set_web_qty_max($row['item_color_id'], $row['size_id']); $quantity_cell = $Item->web_quantity_select($row['item_qty'], 'qty['.$row['id'].']', 'location.href=\''.$_SERVER['PHP_SELF'].'?qty['.$row['id'].']=\'+this.value', '');// document.forms[\'cart\'].submit(); 2nd param is field name - need cart_item_id to know which to change $this->num_items += $row['item_qty']; $item_amount = $row['item_qty'] * $price; $this->items_amount += $item_amount; $amount_cell = '$'.number_format($item_amount, 2); $remove_cell = '  remove'; $items_html .= ' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '.$spcr_cell.' '; } } // while $this->get_items_RS()->MoveFirst(); // reset for next loop if nec if($this->num_items > 0) { //echo 'p id: '.$Promotion->get_id().'
p err'.$Promotion->get_error_msg(); $promo_code = ''; $code_value = ''; // default field value $promo_fields = '       '; if($Promotion->is_error()) { $promo_code .= ''.$Promotion->get_error_msg().':'.$promo_fields; $code_value = $Promotion->get_code(); } elseif(!$Promotion->get_id()) { // prompt for code - none has been applied $promo_code .= 'If you have a PROMOTION CODE, enter it here:'.$promo_fields; } else { // promo applied $promo_text = 'Thank you for participating in the '.strtoupper($Promotion->get_code()).' promotion!'; } $items_html .= ' '; if(isset($promo_text)) { $items_html .= ' '; } $items_html .= ' '; if(isset($promo_code)) { $items_html .= ' '; } $items_html .= '
SHOPPING BAG
Need help?
ITEMDESCRIPTIONCOLORSIZEPRICEQTYAMOUNT 
'.$item_cell.''.$description_cell.''.$color_cell.''.$size_cell.''.$price_cell.''.$quantity_cell.''.$amount_cell.''.$remove_cell.'
  ______  
Items Total: $'.number_format($this->items_amount, 2).'  
'.$promo_text.'  
*The total shown here excludes taxes (CT residents only) and shipping costs, which are calculated based on your shipping destination. The complete cost of your order will be displayed on the Payment page.
'.$promo_code.'  
'; if(count($preorders) > 0 || count($backorders) > 0) { $Template->set_preorder_policy_text(); $Template->set_backorder_policy_text(); $preorder_text = ''; $asterisks = ''; // there will be a bug with the asterisks if both backorders and preorders are made in the same order - they will increment properly in the cart but may not match up here foreach($preorders as $preorder_date) { $asterisks .= "*"; $preorder_text .= $asterisks . ' This item is a preorder and is scheduled to ship on or before '.$preorder_date.'
'; } $backorder_text = ''; $asterisks = ''; foreach($backorders as $backorder_date) { $asterisks .= "*"; $backorder_text .= $asterisks . ' This item is backordered until '.$backorder_date.'
'; } $items_html .= ' '; if($preorder_text != '') { $items_html .= ' '; } if($backorder_text != '') { $items_html .= ' '; } $items_html .= ' '; if(count($preorders) > 0) { $items_html .= ' '; } if(count($backorders) > 0) { $items_html .= ' '; } //Utilities::notify(Config::$tech_email, "backordered item in cart", "cart id: ".$this->id."\n\n$backorder_text"); } $items_html .= '
   
'.$preorder_text.'
'.$backorder_text.'
Preorders Policy
'.$Template->preorder_policy_text.'
Backorders Policy
'.$Template->backorder_policy_text.'
'; } else { $FeaturedDesigners = new FeaturedDesigners(); $items_html = '
There are currently no items in your Shopping Bag.



Note: You must have cookies enabled in your web browser
in order to add items to your bag.
'.$FeaturedDesigners->get_random($Designers, $Items, $Sizes).'
'; } $this->html .= $items_html; } function set_cross_sell_html($Items, $Sizes, $Designers, $crItem) { $CrossSellItems = new CrossSellItems($Items, $crItem->cross_sells, $this); $this->cross_sell_html = $CrossSellItems->html; // a table if avail web items exist or else blank } } ?>