Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Option Type Feature v1.6 (for osc 2.2 MS2)


Guest

Recommended Posts

Hi,

 

I have been using the contribution successfully for a while but now but when i add a new language to may existing catalogue i run into problems, i get a drop down instead of text field for the new language on the product attributes. any clues?

 

current language:

<input type="text" name ="id[txt_27]" size="75" maxlength="75" value="">

 

 

the new language:

<select name="id[27]"><option value="0" SELECTED>TEXT</option></select>

 

Thankful for any help...

 

//T.

 

 

Fixed the problem, I had to update the table:

 

PRODUCTS_OPTIONS for the new language added ... did not have the same product_option_type ... had to update it to 1 for the attributes for the new language to make it work

Link to comment
Share on other sites

  • Replies 799
  • Created
  • Last Reply

Top Posters In This Topic

I've got a little problem using the Option Type Module with the AJAX Attribute Manager. Can't add the TEXT field which is from the Option Type contribution. When trying to add a TEXT field to a product nothing happens? (the other standard attributes does work well)

 

My question are more people running in this problem? Is this common? Or isnt it implented yet?

Link to comment
Share on other sites

One other question...I want to have a drop down box (select box) that would contain the numbers 1 - 99. Is there a way to set up one select box that would be auto filled with the 99 numbers? I can't imagine having to create 99 select boxes in my admin.

 

Thanks

Link to comment
Share on other sites

Hey guys,

 

I'm having the same problem product attributes disappearing after the customer logs in to there account.

 

I fixed the loss upon update of the kart, but if a customer selects their desired options then logs in to purchase the option values disappear. Which is real bad because my pricing is in my options so they get charged 0.00 in many cases.

 

Anybody have a fix for this?

 

Running option type ver 3.0 OSC V 2.2

 

Brock

Link to comment
Share on other sites

Hey guys,

 

I'm having the same problem product attributes disappearing after the customer logs in to there account.

 

I fixed the loss upon update of the kart, but if a customer selects their desired options then logs in to purchase the option values disappear. Which is real bad because my pricing is in my options so they get charged 0.00 in many cases.

 

Anybody have a fix for this?

 

Running option type ver 3.0 OSC V 2.2

 

Brock

 

Having the same problem...Guests can add products to their cart..All of the options show - Excellent :lol: .

If they click the checkout button it prompts them to login. Once you've logged in and take a look at the cart, all of the options are stripped - Bogus :angry: .

 

If you are already logged in and add to cart. No problems. Everything works perfect.

 

I believe it has to do with cookies, sessions, or SSL...not sure though. Any help would be great.

 

Thanks

Link to comment
Share on other sites

If they click the checkout button it prompts them to login. Once you've logged in and take a look at the cart, all of the options are stripped - Bogus :angry: .

 

If you are already logged in and add to cart. No problems. Everything works perfect.

 

I believe it has to do with cookies, sessions, or SSL...not sure though.

Sound more like the function restore_contents() in catalog/includes/classes/shopping_cart.php is not working correctly. That is the function that stores the contents from the session to the database when you login.

Link to comment
Share on other sites

Sound more like the function restore_contents() in catalog/includes/classes/shopping_cart.php is not working correctly. That is the function that stores the contents from the session to the database when you login.

 

Hi all B)

 

I think I got it working thanks to above:

 

this is my working includes/classes/shopping_cart.php

 

<?php
/*
 $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class shoppingCart {
var $contents, $total, $weight, $cartID, $content_type;

function shoppingCart() {
  $this->reset();
}

function restore_contents() {
  global $customer_id;

  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) . "', '" . $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'])) {

			// OTF contrib begins
			//tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . $customer_id . "', '" . $products_id . "', '" . $option . "', '" . $value . "')");
			$attr_value = $this->contents[$products_id]['attributes_values'][$option];
			tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')");
		  }
		}
	  } else {
		tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	  }
	}
  }

// 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
	//CLR 020606 update query to pull attribute value_text. This is needed for text attributes.
	$attributes_query = tep_db_query("select products_options_id, products_options_value_id, products_options_value_text 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'];
	  //CLR 020606 if text attribute, then set additional information
	  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'];
	  }
	}
  }

  $this->cleanup();
}

function reset($reset_database = false) {
  global $customer_id;

  $this->contents = array();
  $this->total = 0;
  $this->weight = 0;
  $this->content_type = false;

  if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
  }

  unset($this->cartID);
  if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
}

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
  global $new_products_id_in_cart, $customer_id;

  $products_id = tep_get_uprid($products_id, $attributes);
  if ($notify == true) {
	$new_products_id_in_cart = $products_id;
	tep_session_register('new_products_id_in_cart');
  }

  if ($this->in_cart($products_id)) {
	$this->update_quantity($products_id, $qty, $attributes);
  } else {
	$this->contents[] = array($products_id);
	$this->contents[$products_id] = array('qty' => $qty);
// insert into database
	if (tep_session_is_registered('customer_id')) 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) . "', '" . $qty . "', '" . date('Ymd') . "')");

	if (is_array($attributes)) {
	  reset($attributes);
	  while (list($option, $value) = each($attributes)) {
		//CLR 020606 check if input was from text box.  If so, store additional attribute information
		//CLR 020708 check if text input is blank, if so do not add to attribute lists
		//CLR 030228 add htmlspecialchars processing.  This handles quotes and other special chars in the user input.
		$attr_value = NULL;
		$blank_value = FALSE;
		if (strstr($option, TEXT_PREFIX)) {
		  if (trim($value) == NULL)
		  {
			$blank_value = TRUE;
		  } else {
			$option = substr($option, strlen(TEXT_PREFIX));
			$attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);
			$value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;
			$this->contents[$products_id]['attributes_values'][$option] = $attr_value;
		  }
		}

		if (!$blank_value)
		{
		  $this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
		//CLR 020606 update db insert to include attribute value_text. This is needed for text attributes.
		//CLR 030228 add tep_db_input() processing
		  if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')");
		}
	  }
	}
  }
  $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();
}

function update_quantity($products_id, $quantity = '', $attributes = '') {
  global $customer_id;

  if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

  $this->contents[$products_id] = array('qty' => $quantity);
// update database
  if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

  if (is_array($attributes)) {
	reset($attributes);
	while (list($option, $value) = each($attributes)) {
	  //CLR 020606 check if input was from text box.  If so, store additional attribute information
	  //CLR 030108 check if text input is blank, if so do not update attribute lists
	  //CLR 030228 add htmlspecialchars processing.  This handles quotes and other special chars in the user input.
	  $attr_value = NULL;
	  $blank_value = FALSE;
	  if (strstr($option, TEXT_PREFIX)) {
		if (trim($value) == NULL)
		{
		  $blank_value = TRUE;
		} else {
		  $option = substr($option, strlen(TEXT_PREFIX));
		  $attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);
		  $value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;
		  $this->contents[$products_id]['attributes_values'][$option] = $attr_value;
		}
	  }

	  if (!$blank_value)
	  {
		$this->contents[$products_id]['attributes'][$option] = $value;
// update database
		//CLR 020606 update db insert to include attribute value_text. This is needed for text attributes.
		//CLR 030228 add tep_db_input() processing
		if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
	  }
	}
  }
}

function cleanup() {
  global $customer_id;

  reset($this->contents);
  while (list($key,) = each($this->contents)) {
	if ($this->contents[$key]['qty'] < 1) {
	  unset($this->contents[$key]);
// remove from database
	  if (tep_session_is_registered('customer_id')) {
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
	  }
	}
  }
}

function count_contents() {  // get total number of items in cart
  $total_items = 0;
  if (is_array($this->contents)) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  $total_items += $this->get_quantity($products_id);
	}
  }

  return $total_items;
}

function get_quantity($products_id) {
  if (isset($this->contents[$products_id])) {
	return $this->contents[$products_id]['qty'];
  } else {
	return 0;
  }
}

function in_cart($products_id) {
  if (isset($this->contents[$products_id])) {
	return true;
  } else {
	return false;
  }
}

function remove($products_id) {
  global $customer_id;

  //CLR 030228 add call tep_get_uprid to correctly format product ids containing quotes
  $products_id = tep_get_uprid($products_id, $attributes);

  unset($this->contents[$products_id]);
// remove from database
  if (tep_session_is_registered('customer_id')) {
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
  }

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
  $this->cartID = $this->generate_cart_id();
}

function remove_all() {
  $this->reset();
}

function get_product_id_list() {
  $product_id_list = '';
  if (is_array($this->contents)) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  $product_id_list .= ', ' . $products_id;
	}
  }

  return substr($product_id_list, 2);
}

function calculate() {
  global $currencies;

  $this->total = 0;
  $this->weight = 0;
  if (!is_array($this->contents)) return 0;

  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
	$qty = $this->contents[$products_id]['qty'];

// products price
	$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
	if ($product = tep_db_fetch_array($product_query)) {
	  $prid = $product['products_id'];
	  $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
	  $products_price = $product['products_price'];
	  $products_weight = $product['products_weight'];

	  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
	  if (tep_db_num_rows ($specials_query)) {
		$specials = tep_db_fetch_array($specials_query);
		$products_price = $specials['specials_new_products_price'];
	  }

	  $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
	  $this->weight += ($qty * $products_weight);
	}

// attributes price
	if (isset($this->contents[$products_id]['attributes'])) {
	  reset($this->contents[$products_id]['attributes']);
	  while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		$attribute_price = tep_db_fetch_array($attribute_price_query);
		if ($attribute_price['price_prefix'] == '+') {
		  $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
		} else {
		  $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
		}
	  }
	}
  }
}

function attributes_price($products_id) {
  $attributes_price = 0;

  if (isset($this->contents[$products_id]['attributes'])) {
	reset($this->contents[$products_id]['attributes']);
	while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
	  $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
	  $attribute_price = tep_db_fetch_array($attribute_price_query);
	  if ($attribute_price['price_prefix'] == '+') {
		$attributes_price += $attribute_price['options_values_price'];
	  } else {
		$attributes_price -= $attribute_price['options_values_price'];
	  }
	}
  }

  return $attributes_price;
}

function get_products() {
  global $languages_id;

  if (!is_array($this->contents)) return false;

  $products_array = array();
  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
	$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
	if ($products = tep_db_fetch_array($products_query)) {
	  $prid = $products['products_id'];
	  $products_price = $products['products_price'];

	  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
	  if (tep_db_num_rows($specials_query)) {
		$specials = tep_db_fetch_array($specials_query);
		$products_price = $specials['specials_new_products_price'];
	  }

	  $products_array[] = array('id' => $products_id,
								'name' => $products['products_name'],
								'model' => $products['products_model'],
								'image' => $products['products_image'],
								'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'final_price' => ($products_price + $this->attributes_price($products_id)),
								'tax_class_id' => $products['products_tax_class_id'],
								// OTF contrib begins
								//'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
								'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
								'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''));
								// OTF contrib ends
	}
  }

  return $products_array;
}

function show_total() {
  $this->calculate();

  return $this->total;
}

function show_weight() {
  $this->calculate();

  return $this->weight;
}

function generate_cart_id($length = 5) {
  return tep_create_random_value($length, 'digits');
}

function get_content_type() {
  $this->content_type = false;

  if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  if (isset($this->contents[$products_id]['attributes'])) {
		reset($this->contents[$products_id]['attributes']);
		while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
		  $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
		  $virtual_check = tep_db_fetch_array($virtual_check_query);

		  if ($virtual_check['total'] > 0) {
			switch ($this->content_type) {
			  case 'physical':
				$this->content_type = 'mixed';

				return $this->content_type;
				break;
			  default:
				$this->content_type = 'virtual';
				break;
			}
		  } else {
			switch ($this->content_type) {
			  case 'virtual':
				$this->content_type = 'mixed';

				return $this->content_type;
				break;
			  default:
				$this->content_type = 'physical';
				break;
			}
		  }
		}
	  } else {
		switch ($this->content_type) {
		  case 'virtual':
			$this->content_type = 'mixed';

			return $this->content_type;
			break;
		  default:
			$this->content_type = 'physical';
			break;
		}
	  }
	}
  } else {
	$this->content_type = 'physical';
  }

  return $this->content_type;
}

function unserialize($broken) {
  for(reset($broken);$kv=each($broken);) {
	$key=$kv['key'];
	if (gettype($this->$key)!="user function")
	$this->$key=$kv['value'];
  }
}

 }
?

 

A big thanks to Jan Zonjee for the name of the file we needed to look at.

 

Thanks

Simon

Link to comment
Share on other sites

Can you tell me exactly what changes you had to make to your shopping_cart.php file?

 

Comparing your shopping cart file and mine there are many differences.

 

Thanks for the help.

 

Brock

 

 

I agree, the file was much different from mine as well.....Checkout Beyond Compare 2...Awesome software

for seeing the differences.

 

I actually used the exact same code as the solution and when I got errors, I went in and replaced those lines

with my old code.

 

There were two changes under

 

// products price

 

&

 

// attributes price

 

// products price

$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

if ($product = tep_db_fetch_array($product_query)) {

$prid = $product['products_id'];

$products_tax = tep_get_tax_rate($product['products_tax_class_id']);

$products_price = $product['products_price'];

$products_weight = $product['products_weight'];

 

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

if (tep_db_num_rows ($specials_query)) {

$specials = tep_db_fetch_array($specials_query);

$products_price = $specials['specials_new_products_price'];

}

 

$this->total += tep_add_tax($products_price, $products_tax) * $qty;

$this->weight += ($qty * $products_weight);

}

 

// attributes price

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");

$attribute_price = tep_db_fetch_array($attribute_price_query);

if ($attribute_price['price_prefix'] == '+') {

$this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

} else {

$this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

}

}

}

}

}

 

I'm using OTF-3.0 so I think that's why there were so many differences.

 

 

 

Hope that helps...

Edited by laddman1
Link to comment
Share on other sites

I agree, the file was much different from mine as well.....Checkout Beyond Compare 2...Awesome software

for seeing the differences.

 

I actually used the exact same code as the solution and when I got errors, I went in and replaced those lines

with my old code.

 

There were two changes under

 

// products price

 

&

 

// attributes price

 

// products price

 

 

$this->total += tep_add_tax($products_price, $products_tax) * $qty;

 

 

// attributes price

 

$this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

} else {

$this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);

 

 

I'm using OTF-3.0 so I think that's why there were so many differences.

 

 

 

Hope that helps...

 

 

Hi

 

I am sorry but you must not be using the latest oscommerce-2.2rc2a which has had the price and tax update in how it workes this is a unmod file:

catalog/includes/classes/shopping_cart.php

 

/*
  $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class shoppingCart {
	var $contents, $total, $weight, $cartID, $content_type;

	function shoppingCart() {
	  $this->reset();
	}

	function restore_contents() {
	  global $customer_id;

	  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) . "'");
		  }
		}
	  }

// 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();
	}

	function reset($reset_database = false) {
	  global $customer_id;

	  $this->contents = array();
	  $this->total = 0;
	  $this->weight = 0;
	  $this->content_type = false;

	  if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
	  }

	  unset($this->cartID);
	  if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
	}

	function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
	  global $new_products_id_in_cart, $customer_id;

	  $products_id_string = tep_get_uprid($products_id, $attributes);
	  $products_id = tep_get_prid($products_id_string);

	  if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$qty > MAX_QTY_IN_CART)) {
		$qty = MAX_QTY_IN_CART;
	  }

	  $attributes_pass_check = true;

	  if (is_array($attributes)) {
		reset($attributes);
		while (list($option, $value) = each($attributes)) {
		  if (!is_numeric($option) || !is_numeric($value)) {
			$attributes_pass_check = false;
			break;
		  }
		}
	  }

	  if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {
		$check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
		$check_product = tep_db_fetch_array($check_product_query);

		if (($check_product !== false) && ($check_product['products_status'] == '1')) {
		  if ($notify == true) {
			$new_products_id_in_cart = $products_id;
			tep_session_register('new_products_id_in_cart');
		  }

		  if ($this->in_cart($products_id_string)) {
			$this->update_quantity($products_id_string, $qty, $attributes);
		  } else {
			$this->contents[$products_id_string] = array('qty' => (int)$qty);
// insert into database
			if (tep_session_is_registered('customer_id')) 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_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");

			if (is_array($attributes)) {
			  reset($attributes);
			  while (list($option, $value) = each($attributes)) {
				$this->contents[$products_id_string]['attributes'][$option] = $value;
// insert into database
				if (tep_session_is_registered('customer_id')) 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_string) . "', '" . (int)$option . "', '" . (int)$value . "')");
			  }
			}
		  }

		  $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();
		}
	  }
	}

	function update_quantity($products_id, $quantity = '', $attributes = '') {
	  global $customer_id;

	  $products_id_string = tep_get_uprid($products_id, $attributes);
	  $products_id = tep_get_prid($products_id_string);

	  if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$quantity > MAX_QTY_IN_CART)) {
		$quantity = MAX_QTY_IN_CART;
	  }

	  $attributes_pass_check = true;

	  if (is_array($attributes)) {
		reset($attributes);
		while (list($option, $value) = each($attributes)) {
		  if (!is_numeric($option) || !is_numeric($value)) {
			$attributes_pass_check = false;
			break;
		  }
		}
	  }

	  if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {
		$this->contents[$products_id_string] = array('qty' => (int)$quantity);
// update database
		if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");

		if (is_array($attributes)) {
		  reset($attributes);
		  while (list($option, $value) = each($attributes)) {
			$this->contents[$products_id_string]['attributes'][$option] = $value;
// update database
			if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'");
		  }
		}
	  }
	}

	function cleanup() {
	  global $customer_id;

	  reset($this->contents);
	  while (list($key,) = each($this->contents)) {
		if ($this->contents[$key]['qty'] < 1) {
		  unset($this->contents[$key]);
// remove from database
		  if (tep_session_is_registered('customer_id')) {
			tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
			tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
		  }
		}
	  }
	}

	function count_contents() {  // get total number of items in cart 
	  $total_items = 0;
	  if (is_array($this->contents)) {
		reset($this->contents);
		while (list($products_id, ) = each($this->contents)) {
		  $total_items += $this->get_quantity($products_id);
		}
	  }

	  return $total_items;
	}

	function get_quantity($products_id) {
	  if (isset($this->contents[$products_id])) {
		return $this->contents[$products_id]['qty'];
	  } else {
		return 0;
	  }
	}

	function in_cart($products_id) {
	  if (isset($this->contents[$products_id])) {
		return true;
	  } else {
		return false;
	  }
	}

	function remove($products_id) {
	  global $customer_id;

	  unset($this->contents[$products_id]);
// remove from database
	  if (tep_session_is_registered('customer_id')) {
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	  }

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
	  $this->cartID = $this->generate_cart_id();
	}

	function remove_all() {
	  $this->reset();
	}

	function get_product_id_list() {
	  $product_id_list = '';
	  if (is_array($this->contents)) {
		reset($this->contents);
		while (list($products_id, ) = each($this->contents)) {
		  $product_id_list .= ', ' . $products_id;
		}
	  }

	  return substr($product_id_list, 2);
	}

	function calculate() {
	  global $currencies;

	  $this->total = 0;
	  $this->weight = 0;
	  if (!is_array($this->contents)) return 0;

	  reset($this->contents);
	  while (list($products_id, ) = each($this->contents)) {
		$qty = $this->contents[$products_id]['qty'];

// products price
		$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
		if ($product = tep_db_fetch_array($product_query)) {
		  $prid = $product['products_id'];
		  $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
		  $products_price = $product['products_price'];
		  $products_weight = $product['products_weight'];

		  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
		  if (tep_db_num_rows ($specials_query)) {
			$specials = tep_db_fetch_array($specials_query);
			$products_price = $specials['specials_new_products_price'];
		  }

		  [u][b]$this->total += $currencies->calculate_price($products_price, $products_tax, $qty);[/b][/u]
		  $this->weight += ($qty * $products_weight);
		}

// attributes price
		if (isset($this->contents[$products_id]['attributes'])) {
		  reset($this->contents[$products_id]['attributes']);
		  while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
			$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
			$attribute_price = tep_db_fetch_array($attribute_price_query);
			if ($attribute_price['price_prefix'] == '+') {
			 [u][b] $this->total += $currencies->calculate_price($attribute_price['options_values_price'],[/b][b] $products_tax, $qty);[/b][/u]
			} else {
			  [u][b]$this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);[/b][/u]
			}
		  }
		}
	  }
	}

	function attributes_price($products_id) {
	  $attributes_price = 0;

	  if (isset($this->contents[$products_id]['attributes'])) {
		reset($this->contents[$products_id]['attributes']);
		while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		  $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		  $attribute_price = tep_db_fetch_array($attribute_price_query);
		  if ($attribute_price['price_prefix'] == '+') {
			$attributes_price += $attribute_price['options_values_price'];
		  } else {
			$attributes_price -= $attribute_price['options_values_price'];
		  }
		}
	  }

	  return $attributes_price;
	}

	function get_products() {
	  global $languages_id;

	  if (!is_array($this->contents)) return false;

	  $products_array = array();
	  reset($this->contents);
	  while (list($products_id, ) = each($this->contents)) {
		$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
		if ($products = tep_db_fetch_array($products_query)) {
		  $prid = $products['products_id'];
		  $products_price = $products['products_price'];

		  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
		  if (tep_db_num_rows($specials_query)) {
			$specials = tep_db_fetch_array($specials_query);
			$products_price = $specials['specials_new_products_price'];
		  }

		  $products_array[] = array('id' => $products_id,
									'name' => $products['products_name'],
									'model' => $products['products_model'],
									'image' => $products['products_image'],
									'price' => $products_price,
									'quantity' => $this->contents[$products_id]['qty'],
									'weight' => $products['products_weight'],
									'final_price' => ($products_price + $this->attributes_price($products_id)),
									'tax_class_id' => $products['products_tax_class_id'],
									'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
		}
	  }

	  return $products_array;
	}

	function show_total() {
	  $this->calculate();

	  return $this->total;
	}

	function show_weight() {
	  $this->calculate();

	  return $this->weight;
	}

	function generate_cart_id($length = 5) {
	  return tep_create_random_value($length, 'digits');
	}

	function get_content_type() {
	  $this->content_type = false;

	  if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
		reset($this->contents);
		while (list($products_id, ) = each($this->contents)) {
		  if (isset($this->contents[$products_id]['attributes'])) {
			reset($this->contents[$products_id]['attributes']);
			while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
			  $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
			  $virtual_check = tep_db_fetch_array($virtual_check_query);

			  if ($virtual_check['total'] > 0) {
				switch ($this->content_type) {
				  case 'physical':
					$this->content_type = 'mixed';

					return $this->content_type;
					break;
				  default:
					$this->content_type = 'virtual';
					break;
				}
			  } else {
				switch ($this->content_type) {
				  case 'virtual':
					$this->content_type = 'mixed';

					return $this->content_type;
					break;
				  default:
					$this->content_type = 'physical';
					break;
				}
			  }
			}
		  } else {
			switch ($this->content_type) {
			  case 'virtual':
				$this->content_type = 'mixed';

				return $this->content_type;
				break;
			  default:
				$this->content_type = 'physical';
				break;
			}
		  }
		}
	  } else {
		$this->content_type = 'physical';
	  }

	  return $this->content_type;
	}

	function unserialize($broken) {
	  for(reset($broken);$kv=each($broken);) {
		$key=$kv['key'];
		if (gettype($this->$key)!="user function")
		$this->$key=$kv['value'];
	  }
	}

  }
?>

 

so you must be useing an old osc so product_attributes_option_type_3.0 (updated for OsCommerce RC2a)

will / should not work anyway???????

Edited by West One Hosting
Link to comment
Share on other sites

hi

 

you think that "Checkout Beyond Compare 2" is Awesome software have a look at "Beyond Compare 3" now that is Awesome software Beyond Compare 3

 

use the "Optimized build"

Edited by West One Hosting
Link to comment
Share on other sites

Ok, I'm lost. :blink:

 

Here is my code. What do I need to change?

 

<?php

/*

$Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class shoppingCart {

var $contents, $total, $weight, $cartID, $content_type;

 

function shoppingCart() {

$this->reset();

}

 

function restore_contents() {

global $customer_id;

 

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'])) {

 

// OTF contrib begins

//tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . $customer_id . "', '" . $products_id . "', '" . $option . "', '" . $value . "')");

$attr_value = $this->contents[$products_id]['attributes_values'][$option];

$query_raw = "insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')";

tep_db_query($query_raw);

// OTF contrib ends

 

}

}

} 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) . "'");

}

}

}

 

// 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

 

// OTF contrib begins

//$attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . $customer_id . "' and products_id = '" . $products['products_id'] . "'");

$attributes_query_raw = "select products_options_id, " .

"products_options_value_id, products_options_value_text from " .

TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" .

(int)$customer_id . "' and products_id = '" .

tep_db_input($products['products_id']) . "'";

$attributes_query = tep_db_query($attributes_query_raw);

// OTF contrib ends

 

// OTF contrib begins

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'];

}

// OTF contrib ends }

}

 

$this->cleanup();

}

 

function reset($reset_database = false) {

global $customer_id;

 

$this->contents = array();

$this->total = 0;

$this->weight = 0;

$this->content_type = false;

 

if (tep_session_is_registered('customer_id') && ($reset_database == true)) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");

}

 

unset($this->cartID);

if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');

}

 

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {

global $new_products_id_in_cart, $customer_id;

 

// OTF contrib begins

//$products_id_string = tep_get_uprid($products_id, $attributes);

//$products_id = tep_get_prid($products_id_string);

 

if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$qty > MAX_QTY_IN_CART)) {

$qty = MAX_QTY_IN_CART;

}

 

//$attributes_pass_check = true;

//

//if (is_array($attributes)) {

// reset($attributes);

// while (list($option, $value) = each($attributes)) {

// if (!is_numeric($option) || !is_numeric($value)) {

// $attributes_pass_check = false;

// break;

// }

// }

//}

//

//if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {

$products_id = tep_get_uprid($products_id, $attributes);

// OTF contrib ends

 

 

$check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

$check_product = tep_db_fetch_array($check_product_query);

 

if (($check_product !== false) && ($check_product['products_status'] == '1')) {

if ($notify == true) {

$new_products_id_in_cart = $products_id;

tep_session_register('new_products_id_in_cart');

}

 

// OTF contrib begins

//if ($this->in_cart($products_id_string)) {

// $this->update_quantity($products_id_string, $qty, $attributes);

//} else {

// $this->contents[$products_id_string] = array('qty' => (int)$qty);

if ($this->in_cart($products_id)) {

$this->update_quantity($products_id, $qty, $attributes);

} else {

$this->contents[] = array($products_id);

$this->contents[$products_id] = array('qty' => (int)$qty);

// OTF contrib ends

 

// insert into database

// OTF contrib begins

//if (tep_session_is_registered('customer_id')) 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_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");

if (tep_session_is_registered('customer_id')) 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) . "', '" . $qty . "', '" . date('Ymd') . "')");

// OTF contrib ends

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

 

// OTF contrib begins

//$this->contents[$products_id_string]['attributes'][$option] = $value;

$attr_value = NULL;

$blank_value = FALSE;

if (strstr($option, TEXT_PREFIX)) {

if (trim($value) == NULL)

{

$blank_value = TRUE;

} else {

$option = substr($option, strlen(TEXT_PREFIX));

$attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);

$value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;

$this->contents[$products_id]['attributes_values'][$option] = $attr_value;

}

}

 

if (!$blank_value)

{

$this->contents[$products_id]['attributes'][$option] = $value;

// OTF contrib ends

 

 

 

// insert into database

// OTF contrib begins

//if (tep_session_is_registered('customer_id')) 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_string) . "', '" . (int)$option . "', '" . (int)$value . "')");

if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')");

}

// OTF contrib ends

}

}

}

 

$this->cleanup();

 

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

// OTF contrib begins

// $this->cartID = $this->generate_cart_id();

// }

// }

//}

$this->cartID = $this->generate_cart_id();

}

}

 

// OTF contrib ends

 

function update_quantity($products_id, $quantity = '', $attributes = '') {

global $customer_id;

 

// OTF contrib begins

//$products_id_string = tep_get_uprid($products_id, $attributes);

//$products_id = tep_get_prid($products_id_string);

if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

// OTF contrib ends

 

if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$quantity > MAX_QTY_IN_CART)) {

$quantity = MAX_QTY_IN_CART;

}

 

$attributes_pass_check = true;

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

if (!is_numeric($option) || !is_numeric($value)) {

$attributes_pass_check = false;

break;

}

}

}

 

// OTF contrib begins

//if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {

// $this->contents[$products_id_string] = array('qty' => (int)$quantity);

 

$this->contents[$products_id] = array('qty' => (int)$quantity);

// OTF contrib ends

 

 

// update database

// OTF contrib begins

//if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");

 

if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

// OTF contrib ends

 

 

if (is_array($attributes)) {

reset($attributes);

while (list($option, $value) = each($attributes)) {

 

// OTF contrib begins

//$this->contents[$products_id_string]['attributes'][$option] = $value;

$attr_value = NULL;

$blank_value = FALSE;

if (strstr($option, TEXT_PREFIX)) {

if (trim($value) == NULL)

{

$blank_value = TRUE;

} else {

$option = substr($option, strlen(TEXT_PREFIX));

$attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);

$value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;

$this->contents[$products_id]['attributes_values'][$option] = $attr_value;

}

}

 

if (!$blank_value)

{

$this->contents[$products_id]['attributes'][$option] = $value;

// OTF contrib ends

 

// update database

// OTF contrib begins

//if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'");

if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");

// OTF contrib ends

}

}

}

}

 

function cleanup() {

global $customer_id;

 

reset($this->contents);

while (list($key,) = each($this->contents)) {

if ($this->contents[$key]['qty'] < 1) {

unset($this->contents[$key]);

// remove from database

if (tep_session_is_registered('customer_id')) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");

}

}

}

}

 

function count_contents() { // get total number of items in cart

$total_items = 0;

if (is_array($this->contents)) {

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$total_items += $this->get_quantity($products_id);

}

}

 

return $total_items;

}

 

function get_quantity($products_id) {

if (isset($this->contents[$products_id])) {

return $this->contents[$products_id]['qty'];

} else {

return 0;

}

}

 

function in_cart($products_id) {

if (isset($this->contents[$products_id])) {

return true;

} else {

return false;

}

}

 

function remove($products_id) {

global $customer_id;

 

// OTF contrib begins

$products_id = tep_get_uprid($products_id, $attributes);

// OTF contrib ends

 

unset($this->contents[$products_id]);

// remove from database

if (tep_session_is_registered('customer_id')) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

}

 

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure

$this->cartID = $this->generate_cart_id();

}

 

function remove_all() {

$this->reset();

}

 

function get_product_id_list() {

$product_id_list = '';

if (is_array($this->contents)) {

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$product_id_list .= ', ' . $products_id;

}

}

 

return substr($product_id_list, 2);

}

 

function calculate() {

global $currencies;

 

$this->total = 0;

$this->weight = 0;

if (!is_array($this->contents)) return 0;

 

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$qty = $this->contents[$products_id]['qty'];

 

// products price

$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

if ($product = tep_db_fetch_array($product_query)) {

$prid = $product['products_id'];

$products_tax = tep_get_tax_rate($product['products_tax_class_id']);

$products_price = $product['products_price'];

$products_weight = $product['products_weight'];

 

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

if (tep_db_num_rows ($specials_query)) {

$specials = tep_db_fetch_array($specials_query);

$products_price = $specials['specials_new_products_price'];

}

 

$this->total += $currencies->calculate_price($products_price, $products_tax, $qty);

$this->weight += ($qty * $products_weight);

}

 

// attributes price

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");

$attribute_price = tep_db_fetch_array($attribute_price_query);

if ($attribute_price['price_prefix'] == '+') {

$this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);

} else {

$this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);

}

}

}

}

}

 

function attributes_price($products_id) {

$attributes_price = 0;

 

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {

$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");

$attribute_price = tep_db_fetch_array($attribute_price_query);

if ($attribute_price['price_prefix'] == '+') {

$attributes_price += $attribute_price['options_values_price'];

} else {

$attributes_price -= $attribute_price['options_values_price'];

}

}

}

 

return $attributes_price;

}

 

function get_products() {

global $languages_id;

 

if (!is_array($this->contents)) return false;

 

$products_array = array();

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

if ($products = tep_db_fetch_array($products_query)) {

$prid = $products['products_id'];

$products_price = $products['products_price'];

 

$specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");

if (tep_db_num_rows($specials_query)) {

$specials = tep_db_fetch_array($specials_query);

$products_price = $specials['specials_new_products_price'];

}

 

$products_array[] = array('id' => $products_id,

'name' => $products['products_name'],

'model' => $products['products_model'],

'image' => $products['products_image'],

'price' => $products_price,

'quantity' => $this->contents[$products_id]['qty'],

'weight' => $products['products_weight'],

'length' => $products['products_length'],

'width' => $products['products_width'],

'height' => $products['products_height'],

'ready_to_ship' => $products['products_ready_to_ship'],

 

'final_price' => ($products_price + $this->attributes_price($products_id)),

'tax_class_id' => $products['products_tax_class_id'],

// OTF contrib begins

//'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));

'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),

'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''));

// OTF contrib ends

}

}

 

return $products_array;

}

 

function show_total() {

$this->calculate();

 

return $this->total;

}

 

function show_weight() {

$this->calculate();

 

return $this->weight;

}

 

function generate_cart_id($length = 5) {

return tep_create_random_value($length, 'digits');

}

 

function get_content_type() {

$this->content_type = false;

 

if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {

reset($this->contents);

while (list($products_id, ) = each($this->contents)) {

if (isset($this->contents[$products_id]['attributes'])) {

reset($this->contents[$products_id]['attributes']);

while (list(, $value) = each($this->contents[$products_id]['attributes'])) {

$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");

$virtual_check = tep_db_fetch_array($virtual_check_query);

 

if ($virtual_check['total'] > 0) {

switch ($this->content_type) {

case 'physical':

$this->content_type = 'mixed';

 

return $this->content_type;

break;

default:

$this->content_type = 'virtual';

break;

}

} else {

switch ($this->content_type) {

case 'virtual':

$this->content_type = 'mixed';

 

return $this->content_type;

break;

default:

$this->content_type = 'physical';

break;

}

}

}

} else {

switch ($this->content_type) {

case 'virtual':

$this->content_type = 'mixed';

 

return $this->content_type;

break;

default:

$this->content_type = 'physical';

break;

}

}

}

} else {

$this->content_type = 'physical';

}

 

return $this->content_type;

}

 

function unserialize($broken) {

for(reset($broken);$kv=each($broken);) {

$key=$kv['key'];

if (gettype($this->$key)!="user function")

$this->$key=$kv['value'];

}

}

 

}

?>

Link to comment
Share on other sites

Ok, I'm lost. :blink:

 

Here is my code. What do I need to change?

 

Hi

 

try this:

 

<?php
/*
 $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class shoppingCart {
var $contents, $total, $weight, $cartID, $content_type;

function shoppingCart() {
  $this->reset();
}

function restore_contents() {
  global $customer_id;

  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) . "', '" . $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'])) {

			// OTF contrib begins
			//tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . $customer_id . "', '" . $products_id . "', '" . $option . "', '" . $value . "')");
			$attr_value = $this->contents[$products_id]['attributes_values'][$option];
			tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')");
		  }
		}
	  } else {
		tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	  }
	}
  }

// 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
	//CLR 020606 update query to pull attribute value_text. This is needed for text attributes.
	$attributes_query = tep_db_query("select products_options_id, products_options_value_id, products_options_value_text 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'];
	  //CLR 020606 if text attribute, then set additional information
	  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'];
	  }
	}
  }

  $this->cleanup();
}

function reset($reset_database = false) {
  global $customer_id;

  $this->contents = array();
  $this->total = 0;
  $this->weight = 0;
  $this->content_type = false;

  if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
  }

  unset($this->cartID);
  if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
}

function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
  global $new_products_id_in_cart, $customer_id;

  $products_id = tep_get_uprid($products_id, $attributes);
  if ($notify == true) {
	$new_products_id_in_cart = $products_id;
	tep_session_register('new_products_id_in_cart');
  }

  if ($this->in_cart($products_id)) {
	$this->update_quantity($products_id, $qty, $attributes);
  } else {
	$this->contents[] = array($products_id);
	$this->contents[$products_id] = array('qty' => $qty);
// insert into database
	if (tep_session_is_registered('customer_id')) 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) . "', '" . $qty . "', '" . date('Ymd') . "')");

	if (is_array($attributes)) {
	  reset($attributes);
	  while (list($option, $value) = each($attributes)) {
		//CLR 020606 check if input was from text box.  If so, store additional attribute information
		//CLR 020708 check if text input is blank, if so do not add to attribute lists
		//CLR 030228 add htmlspecialchars processing.  This handles quotes and other special chars in the user input.
		$attr_value = NULL;
		$blank_value = FALSE;
		if (strstr($option, TEXT_PREFIX)) {
		  if (trim($value) == NULL)
		  {
			$blank_value = TRUE;
		  } else {
			$option = substr($option, strlen(TEXT_PREFIX));
			$attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);
			$value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;
			$this->contents[$products_id]['attributes_values'][$option] = $attr_value;
		  }
		}

		if (!$blank_value)
		{
		  $this->contents[$products_id]['attributes'][$option] = $value;
// insert into database
		//CLR 020606 update db insert to include attribute value_text. This is needed for text attributes.
		//CLR 030228 add tep_db_input() processing
		  if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')");
		}
	  }
	}
  }
  $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();
}

function update_quantity($products_id, $quantity = '', $attributes = '') {
  global $customer_id;

  if (empty($quantity)) return true; // nothing needs to be updated if theres no quantity, so we return true..

  $this->contents[$products_id] = array('qty' => $quantity);
// update database
  if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");

  if (is_array($attributes)) {
	reset($attributes);
	while (list($option, $value) = each($attributes)) {
	  //CLR 020606 check if input was from text box.  If so, store additional attribute information
	  //CLR 030108 check if text input is blank, if so do not update attribute lists
	  //CLR 030228 add htmlspecialchars processing.  This handles quotes and other special chars in the user input.
	  $attr_value = NULL;
	  $blank_value = FALSE;
	  if (strstr($option, TEXT_PREFIX)) {
		if (trim($value) == NULL)
		{
		  $blank_value = TRUE;
		} else {
		  $option = substr($option, strlen(TEXT_PREFIX));
		  $attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES);
		  $value = PRODUCTS_OPTIONS_VALUE_TEXT_ID;
		  $this->contents[$products_id]['attributes_values'][$option] = $attr_value;
		}
	  }

	  if (!$blank_value)
	  {
		$this->contents[$products_id]['attributes'][$option] = $value;
// update database
		//CLR 020606 update db insert to include attribute value_text. This is needed for text attributes.
		//CLR 030228 add tep_db_input() processing
		if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'");
	  }
	}
  }
}

function cleanup() {
  global $customer_id;

  reset($this->contents);
  while (list($key,) = each($this->contents)) {
	if ($this->contents[$key]['qty'] < 1) {
	  unset($this->contents[$key]);
// remove from database
	  if (tep_session_is_registered('customer_id')) {
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
		tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
	  }
	}
  }
}

function count_contents() {  // get total number of items in cart
  $total_items = 0;
  if (is_array($this->contents)) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  $total_items += $this->get_quantity($products_id);
	}
  }

  return $total_items;
}

function get_quantity($products_id) {
  if (isset($this->contents[$products_id])) {
	return $this->contents[$products_id]['qty'];
  } else {
	return 0;
  }
}

function in_cart($products_id) {
  if (isset($this->contents[$products_id])) {
	return true;
  } else {
	return false;
  }
}

function remove($products_id) {
  global $customer_id;

  //CLR 030228 add call tep_get_uprid to correctly format product ids containing quotes
  $products_id = tep_get_uprid($products_id, $attributes);

  unset($this->contents[$products_id]);
// remove from database
  if (tep_session_is_registered('customer_id')) {
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
  }

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
  $this->cartID = $this->generate_cart_id();
}

function remove_all() {
  $this->reset();
}

function get_product_id_list() {
  $product_id_list = '';
  if (is_array($this->contents)) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  $product_id_list .= ', ' . $products_id;
	}
  }

  return substr($product_id_list, 2);
}

function calculate() {
  global $currencies;

  $this->total = 0;
  $this->weight = 0;
  if (!is_array($this->contents)) return 0;

  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
	$qty = $this->contents[$products_id]['qty'];

// products price
	$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
	if ($product = tep_db_fetch_array($product_query)) {
	  $prid = $product['products_id'];
	  $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
	  $products_price = $product['products_price'];
	  $products_weight = $product['products_weight'];

	  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
	  if (tep_db_num_rows ($specials_query)) {
		$specials = tep_db_fetch_array($specials_query);
		$products_price = $specials['specials_new_products_price'];
	  }

	  $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
	  $this->weight += ($qty * $products_weight);
	}

// attributes price
	if (isset($this->contents[$products_id]['attributes'])) {
	  reset($this->contents[$products_id]['attributes']);
	  while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
		$attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
		$attribute_price = tep_db_fetch_array($attribute_price_query);
		if ($attribute_price['price_prefix'] == '+') {
		  $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
		} else {
		  $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
		}
	  }
	}
  }
}

function attributes_price($products_id) {
  $attributes_price = 0;

  if (isset($this->contents[$products_id]['attributes'])) {
	reset($this->contents[$products_id]['attributes']);
	while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
	  $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
	  $attribute_price = tep_db_fetch_array($attribute_price_query);
	  if ($attribute_price['price_prefix'] == '+') {
		$attributes_price += $attribute_price['options_values_price'];
	  } else {
		$attributes_price -= $attribute_price['options_values_price'];
	  }
	}
  }

  return $attributes_price;
}

function get_products() {
  global $languages_id;

  if (!is_array($this->contents)) return false;

  $products_array = array();
  reset($this->contents);
  while (list($products_id, ) = each($this->contents)) {
	$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_length, p.products_width, p.products_height, p.products_ready_to_ship, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
	if ($products = tep_db_fetch_array($products_query)) {
	  $prid = $products['products_id'];
	  $products_price = $products['products_price'];

	  $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
	  if (tep_db_num_rows($specials_query)) {
		$specials = tep_db_fetch_array($specials_query);
		$products_price = $specials['specials_new_products_price'];
	  }

	  $products_array[] = array('id' => $products_id,
								'name' => $products['products_name'],
								'model' => $products['products_model'],
								'image' => $products['products_image'],
								'price' => $products_price,
								'quantity' => $this->contents[$products_id]['qty'],
								'weight' => $products['products_weight'],
								'length' => $products['products_length'],
								'width' => $products['products_width'],
								'height' => $products['products_height'],
								'ready_to_ship' => $products['products_ready_to_ship'],
								'final_price' => ($products_price + $this->attributes_price($products_id)),
								'tax_class_id' => $products['products_tax_class_id'],
								// OTF contrib begins
								//'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
								'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
								'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''));
								// OTF contrib ends
	}
  }

  return $products_array;
}

function show_total() {
  $this->calculate();

  return $this->total;
}

function show_weight() {
  $this->calculate();

  return $this->weight;
}

function generate_cart_id($length = 5) {
  return tep_create_random_value($length, 'digits');
}

function get_content_type() {
  $this->content_type = false;

  if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
	reset($this->contents);
	while (list($products_id, ) = each($this->contents)) {
	  if (isset($this->contents[$products_id]['attributes'])) {
		reset($this->contents[$products_id]['attributes']);
		while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
		  $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
		  $virtual_check = tep_db_fetch_array($virtual_check_query);

		  if ($virtual_check['total'] > 0) {
			switch ($this->content_type) {
			  case 'physical':
				$this->content_type = 'mixed';

				return $this->content_type;
				break;
			  default:
				$this->content_type = 'virtual';
				break;
			}
		  } else {
			switch ($this->content_type) {
			  case 'virtual':
				$this->content_type = 'mixed';

				return $this->content_type;
				break;
			  default:
				$this->content_type = 'physical';
				break;
			}
		  }
		}
	  } else {
		switch ($this->content_type) {
		  case 'virtual':
			$this->content_type = 'mixed';

			return $this->content_type;
			break;
		  default:
			$this->content_type = 'physical';
			break;
		}
	  }
	}
  } else {
	$this->content_type = 'physical';
  }

  return $this->content_type;
}

function unserialize($broken) {
  for(reset($broken);$kv=each($broken);) {
	$key=$kv['key'];
	if (gettype($this->$key)!="user function")
	$this->$key=$kv['value'];
  }
}

}
?>

Link to comment
Share on other sites

HELP!

 

I've installed this wonderful contribution to add a text box to the product info page, I also have the Quantity Product Info mod as well as I want to have a list of products with a quantity box.

 

My problem is that I can either have the quantity added to the cart correctly with no text box info or the text box info added but with the quantity set to 1 but the total price ok, this depends on the following line in catalogue/product_info.php:

 

<td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_mult')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">

 

in this format it adds the text box info but not the right quantity, if I change the action=add_multi to action=add_product it add the correct quantity but not the text box info.

 

You can have a look at http://www.deanforestfayre.co.uk/shop you will need to login to the store using test as the username and test as the password

 

Thanks

Link to comment
Share on other sites

Okay, here is where I think the problem is in application_top.php, the two choices are of mult or product and here are the two bits of code

 

add_mult

	  case 'add_mult' : if (is_array($HTTP_POST_VARS['a'])){
			  reset($HTTP_POST_VARS['quantity']);
		reset($HTTP_POST_VARS['a']);

		$x=0;
		if (is_array($HTTP_POST_VARS['a'])){
		 foreach(($HTTP_POST_VARS['a']) as $key => $value){
		   $c = array((int)$HTTP_POST_VARS['b'] => (int)$value);		

		   if (is_array($HTTP_POST_VARS['quantity'])){
			  $qty = (int)$HTTP_POST_VARS['quantity'][$x];


			  $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], ($c)))+($qty),($c));
			  $x++;

			}
		 } 
		}
		 } else {
		 if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
							$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
						  }
		}
		tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

					 break;

 

and here is the add_product code

 

	  // customer adds a product from the products page
  case 'add_product' :	if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
							$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;

 

Would my problem be solved by a combination of the two and if so how would it be coded?

 

Thanks in advance for any help.

Link to comment
Share on other sites

Hello,

 

I have been trying for a week now to get "attribute sets plus" to work with this contribution,

 

The thing is i have got it all working appart from a small issue with the checkboxes,

 

If i add a product option (even by default)

 

eg,

product options

access -- set it as a checkbox,

 

option values

access -- rack1

access -- rack2

access -- rack3

 

This will only show the first one added to the product, for it to work i have to add them all to "product options",

Is there a any way to make it work as above,

 

Any help or support would be much appreciated

Link to comment
Share on other sites

Working on getting this up and production ready for me.

 

I noticed that when you click on an item with a textarea that was already in your cart the product_info.php page did not repopulate the textarea field with the cart data as it did with text fields. This is due to textareas not supporting "value=". It might be kind of silly that any of the fields are sticky anyway, as when they are changed the result is not a change to that item's attributes but rather the addition of a new item to the cart. But I think that consistency is better.

 

I would really love it if we could figure out how customers could edit the products attributes of items already in the cart.

So here is a fix to the textarea not being sticky:

 

product_info.php

Find:
value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . '"></textarea>

Replace with:
id="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" >' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . '
</textarea>' . '

 

I also noticed that long entries by a customer into a textarea field breaks the virtual flow of text on the checkout_confirmation.php page. The fix is to simply delete all occurences of: "<nobr>" and "</nobr>" in checkout_confirmation.php.

Edited by gotham

Kendall

Brooklyn, New York USA

Link to comment
Share on other sites

I have SPPC installed and when I use a text area option, it shows the retail price for that text area But when I am logged in as a wholesaler, the price that shows is still the retail price.

 

It functions properly, it adds the correct wholesale attribute price, it just doesn't show the correct group price.

 

Anyone know how to fix this?

Link to comment
Share on other sites

  • 1 month later...

Hi

 

I have installed Option Type Feature 1.7.2 on my oscommerce MS2.2, i tested it and it worked, but when I added a lot more product options to my products and tried to checkout my shipping options has disepeared, and all of my payment options to are gone to except for the Moneyorder, what can have happened ?

 

Checkout worked first as it should when I tested in the beginning but not anymore.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...