Jump to content
Sign in to follow this  
Chandra

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

Recommended Posts

I think somewhere in these 17 pages of support someone asked the question, and someone provided a potential answer.

Okay, I've looked at the database of orders, and the text values are simply "TEXT", so they are not be written to the database for some reason.

 

Odd thing is that the order email, the customer's email, and the shopping cart all have the text the customer entered.

 

Any ideas where I can look? Which file actually writes the data to the database..

 

I compared modifications to my files against the files provided, and there was one line that I missed,even after comparing 2x previously.

 

Everything is working fine now. It was coding in file in shopping_cart.php

Share this post


Link to post
Share on other sites

I'm having problems with this module. I have it installed and it was working great, except when I update the quantity in the shopping cart, it reset to the original price before the attributes not allowing the visitor to update accurately. Maybe there's a way to eliminate the quantiy and just have the visitor purchase one product limit and be able to edit the attributes instead of quantity.

 

If someone has some insight on this, please let me know. The product sample is here:

 

http://pecu.com/liveclass/product_info.php...&products_id=28

 

Thanks,

 

Ben Wade


World Portal Technologies

Share this post


Link to post
Share on other sites

I have gone through all 17 pages of this post. I have tried everything suggested, and re-compared the files suggested, to no avail!

 

I have a product with two textareas. On the shopping_cart.php page, I can see my item in the cart, with the CORRECT text values for the textarea options. I then go to the shipping page, then payment, then confirmation, and voila, it now only says "TEXT" for the textarea values.

 

Can someone point me in the right direction for this fix? Thanks!


Tara Lang

Share this post


Link to post
Share on other sites
You'll have to add an extra field in product_options to indicate if the option is required or not. In product_info.php you can then add a javascript to test if the required field is filled in or not. It's quite some work. Or you can hardcode in your shop the test using the option_id in your database (no need to add an extra database column).

 

Didier.

Has anyone figured out how to REQUIRE FIELDS yet? I'm working on it, but haven't been able to figure it out. :blink:

Edited by cdickson

cdickson

Share this post


Link to post
Share on other sites
I have gone through all 17 pages of this post. I have tried everything suggested, and re-compared the files suggested, to no avail!

 

I have a product with two textareas. On the shopping_cart.php page, I can see my item in the cart, with the CORRECT text values for the textarea options. I then go to the shipping page, then payment, then confirmation, and voila, it now only says "TEXT" for the textarea values.

 

Can someone point me in the right direction for this fix? Thanks!

 

I found the one tiny line that wasn't right, so I got it fixed! :thumbsup:


Tara Lang

Share this post


Link to post
Share on other sites

Did you find an answer for this? I am desperately seeking an answer.

 

Has anyone worked out how to make text fields mandetory, is there a simple peice of code that forces people to fill in fields before they can add to basket?

 

Thanks for your help guys:)

 

mes


cdickson

Share this post


Link to post
Share on other sites
I found the one tiny line that wasn't right, so I got it fixed! :thumbsup:

 

 

What file and line was it Tara?

Share this post


Link to post
Share on other sites
What file and line was it Tara?

 

Looks like I found it in includes/classes/order.php:

 

Original (well, on a seriously modified site)

 

'value' => $attributes['products_options_values_name'],

 

From order.php from install files:

'value' => $attr_value,

Share this post


Link to post
Share on other sites

I did the following while QA'ing the Option Type install:

 

1. buy a product and set several of its attributes.

2. go to the shopping cart.

3. return to the product to make an attribute edit.

 

When I returned, all the attributes were all missing / lost. I noticed that they were successfully being passed in the URL string, but not collected on the product's page.

 

The URL String looks like:

product_info.php?products_id=39{3}27{txt_4}This%20is%20line%2001.This%20is%20line%2002.

 

I figured the issue is on the product_info.php, but .... I think my mind has quit for the night!

 

Any ideas? :)

Share this post


Link to post
Share on other sites
Looks like I found it in includes/classes/order.php:

 

Original (well, on a seriously modified site)

 

'value' => $attributes['products_options_values_name'],

 

From order.php from install files:

'value' => $attr_value,

 

 

Hi, sorry, I was away sick for a few days. Yes, that was the exact line causing all the problems :)


Tara Lang

Share this post


Link to post
Share on other sites

Ok, here is my new problem :)

 

I had the problem with PayPal returning the TEXT instead of the actual text, so I found the fix for that, although my version of Paypal IPN was a bit different, so I had to improvise.

 

However, now Paypal is only returning some of the text. It cuts it off after so many characters. Is there a way to fix this??


Tara Lang

Share this post


Link to post
Share on other sites

My mistake, it's ALL payment methods. The option values are cutting off at 32 characters. Anyone know how to fix this?


Tara Lang

Share this post


Link to post
Share on other sites

hi all,

 

i've asked this elsewhere but no replies.

 

if i have a product with a TEXT attribute, and a customer buys two, only the attributes from the last one are stored in the cart.

 

if i remove the TEXT attribute, it works as expected, with two separate items in the cart , each with their own attributes.

 

is this a fault of the contribution or have i done something wrong somewhere?

 

thanks

john

Share this post


Link to post
Share on other sites

So I am building a store, and had this contrib installed and working nicely. but i screwed up something else big time and had to start over from scratch. in the meantime, I picked up the new updated release osCommerce 2.2 Milestone 2 Update 051113.

 

as i'm merging i notice something is not quite right with includes/classes/shopping_cart.php. neither with functions/general.php -- but have been updated to fix a bug having to do with adding non-existing products to the cart. These fixes are all mixed up in changes required for this contrib.

 

doh! i'm not quite a programmer. i tried giving it a look, but i'm quite confused. anyone willing to take a stab???

 

FILE 1: INCLUDES/CLASSES/SHOPPING_CART.PHP

 

MS2 ORIG lines 78-127:

	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)) {
		$this->contents[$products_id]['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) . "', '" . (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;

  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)) {
	  $this->contents[$products_id]['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) . "' and products_options_id = '" . (int)$option . "'");
	}
  }
}

 

MS2 051113 BUG FIX lines 78-139:

	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 (is_numeric($products_id) && is_numeric($qty)) {
	$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' => $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 (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity)) {
	$this->contents[$products_id_string] = array('qty' => $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 . "'");
	  }
	}
  }
}

 

OPTION TYPE FEATURE VERSION lines 85-178

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

 

FILE 2: INCLUDES/FUNCTIONS/GENERAL.PHP

 

MS2 ORIG lines 912-929

  function tep_get_uprid($prid, $params) {
$uprid = $prid;
if ( (is_array($params)) && (!strstr($prid, '{')) ) {
  while (list($option, $value) = each($params)) {
	$uprid = $uprid . '{' . $option . '}' . $value;
  }
}

return $uprid;
 }

////
// Return a product ID from a product ID with attributes
 function tep_get_prid($uprid) {
$pieces = explode('{', $uprid);

return $pieces[0];
 }

 

MS2 051113 BUG FIX lines 916-982

  function tep_get_uprid($prid, $params) {
if (is_numeric($prid)) {
  $uprid = $prid;

  if (is_array($params) && (sizeof($params) > 0)) {
	$attributes_check = true;
	$attributes_ids = '';

	reset($params);
	while (list($option, $value) = each($params)) {
	  if (is_numeric($option) && is_numeric($value)) {
		$attributes_ids .= '{' . (int)$option . '}' . (int)$value;
	  } else {
		$attributes_check = false;
		break;
	  }
	}

	if ($attributes_check == true) {
	  $uprid .= $attributes_ids;
	}
  }
} else {
  $uprid = tep_get_prid($prid);

  if (is_numeric($uprid)) {
	if (strpos($prid, '{') !== false) {
	  $attributes_check = true;
	  $attributes_ids = '';

// strpos()+1 to remove up to and including the first { which would create an empty array element in explode()
	  $attributes = explode('{', substr($prid, strpos($prid, '{')+1));

	  for ($i=0, $n=sizeof($attributes); $i<$n; $i++) {
		$pair = explode('}', $attributes[$i]);

		if (is_numeric($pair[0]) && is_numeric($pair[1])) {
		  $attributes_ids .= '{' . (int)$pair[0] . '}' . (int)$pair[1];
		} else {
		  $attributes_check = false;
		  break;
		}
	  }

	  if ($attributes_check == true) {
		$uprid .= $attributes_ids;
	  }
	}
  } else {
	return false;
  }
}

return $uprid;
 }

////
// Return a product ID from a product ID with attributes
 function tep_get_prid($uprid) {
$pieces = explode('{', $uprid);

if (is_numeric($pieces[0])) {
  return $pieces[0];
} else {
  return false;
}
 }

 

 

OPTION TYPE FEATURE VERSION lines 912-938

  function tep_get_uprid($prid, $params) {
$uprid = $prid;
if ( (is_array($params)) && (!strstr($prid, '{')) ) {
  while (list($option, $value) = each($params)) {
	//CLR 030714 Add processing around $value. This is needed for text attributes.
	$uprid = $uprid . '{' . $option . '}' . htmlspecialchars(stripslashes(trim($value)), ENT_QUOTES);
  }
//CLR 030228 Add else stmt to process product ids passed in by other routines.
} else {
  $uprid = htmlspecialchars(stripslashes($uprid), ENT_QUOTES);
}






return $uprid;
 }

////
// Return a product ID from a product ID with attributes
 function tep_get_prid($uprid) {
$pieces = explode('{', $uprid);

return $pieces[0];
 }

Share this post


Link to post
Share on other sites
hi all,

 

i've asked this elsewhere but no replies.

 

if i have a product with a TEXT attribute, and a customer buys two, only the attributes from the last one are stored in the cart.

 

if i remove the TEXT attribute, it works as expected, with two separate items in the cart , each with their own attributes.

 

is this a fault of the contribution or have i done something wrong somewhere?

 

thanks

john

 

I added this contribution and mine works fine using TEXT attributes in the scenario you describe.

 

Check your code modifications. I found WinMerge to be a great help in finding small coding errors. It's open source software and you can download it at http://sourceforge.net/projects/winmerge.


cdickson

Share this post


Link to post
Share on other sites
I added this contribution and mine works fine using TEXT attributes in the scenario you describe.

 

Check your code modifications. I found WinMerge to be a great help in finding small coding errors. It's open source software and you can download it at http://sourceforge.net/projects/winmerge.

 

thank you cdickson!

 

at last i have a reply, at least now i know it works for someone else I can look to see where i have gone wrong.

 

thank you so much!

 

john

Share this post


Link to post
Share on other sites
Okay, new problem now. When I view orders in admin/orders.php, I only see some of my product attribute information. However, all of the information comes over in my email order confirmation, and when I check the table orders_products_attributes, all the information is there.

 

I do not think the problem is with orders.php because orders placed last month are still showing all their attribute information. Since all of the attribute information is going to the database and through the email, I'm confused as to where the problem is happening.

 

Any suggestions??

 

dani,

 

did you ever figure that out? i'm having the same problem, it seems to be only happening to textarea boxes. all the information is appearing in the shopping cart and on the email confirmation BUT in the admin section when you click on orders>edit, invoice or packing slip it is only displaying 32 characters of the information that was entered in the textarea. all the information is in the database but the admin section is only allowing 32 characters to be displayed and i can't find where to set it to allow more characters.

 

in the read me file for this contribution is has this recommendation to limit entered text to 30 characters:

1. the length of the entered text. It can mess up the layout of your email html invoices, packing slips and order confirmations. I decided to cut off the user's text after 30 characters so that his text is printed on one line. Here is an example of how to do it :

if (strlen($order->products[$i]['attributes'][$j]['value']) > 30)

{

$value_cut = substr($order->products[$i]['attributes'][$j]['value'], 0, 30) . ' [...]';

} else {

$value_cut = $order->products[$i]['attributes'][$j]['value'];

}

$products_ordered_attributes .= '<br>??›<small><i> ' . $attributes_values['products_options_name'] . ': ' . tep_decode_specialchars($value_cut) . '</i></small>';

You can use the same principle (not the same code as the arrays are different between catalog and admin !!) everywhere where the option value is displayed : account_history.php, shopping_cart.php, checkout_process.php, /admin/invoice.php, /admin/packingslip.php, /admin/orders.php, pdf_datasheet_functions.php (if installed), /admin/edit_orders.php (if installed).

BUT i'm not using that code, so i have no idea why the entered text is being limited to 32 characters.

 

can anyone help with this? it is EXTREMELY important that this gets fixed because the store is using paypal ipn for payments and not every customer returns to the site after they make a payment, if the customer doesn't return to the store then a confirmation email is not generated. if a confirmation email is not generated then we have to rely on the info on the orders page in the admin but unfortunately all the info is not being displayed.

Edited by fribhey

Share this post


Link to post
Share on other sites

I second that call for someone to update this contrib to the new release of osc. I was in the process of updating it and came across that part. I could probably hack my way through, but i'd probably end up just screwing up my store so I'm just going to hope someone else can figure it out.

 

Let us know when you've got it!

Edited by Gidgidonihah

Share this post


Link to post
Share on other sites

Can someone tell me where to get rid of the extra form area for the attributes comment? Or is it supposed to look like this?

otf.jpg

As you see I have the same input box on each side of the select menu. I have searched all over for duplicate code and can not find anything to remove it.

Also, there should be a length box in the middle, I have that, I just didnt when I took this pic.


Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!

Share this post


Link to post
Share on other sites

Never Mind, I found the solution, I had to find two instances of

<?php echo $inputs; ?>

and comment them out. 1 was for the area in the front end and the other for use inside the edit attribute.

If anyone needs to know the exact lines then leave a post.


Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!

Share this post


Link to post
Share on other sites

This is a great mod, but I needed a way to require input for certain features that are added by this contribution. Others in this forum were trying to do the same thing, but there were no answers posted here.

 

With some help, I found a way to do this. There is one new file to add, and there are three existing files that need to be modified.

 

Remember: BACKUP first, and proceed at your own risk. I have this feature functioning properly on a client web site, but I offer no guarantees.

 

Instructions - Create a .txt file

=========================================
INSTRUCTIONS FOR REQUIRING AND VALIDATING DESIGNATED FIELDS FOR THE
CONTRIBUTION Option Type Feature v1.71
=========================================

This was written to require two specific fields - Name & Birthdate - that I added with the Option Type Feature v1.71.  You will need to do your own modifications to suit your specific fields.



New file:
catalog/formValidate.js

Modified files:
catalog/product_info.php
catalog/includes/application_top.php
catalog/includes/languages/english.php

=========================================
1.  BACKUP - BACKUP - BACKUP
=========================================

=========================================
2.  Upload formValidate.js to your catalog/ (or equivalent) directory.
=========================================

=========================================
3.  Open cataolg/product_info.php
=========================================

**FIND APPROX LINE 89:
if (tep_not_null($product_info['products_model'])) {
  $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
} else {
  $products_name = $product_info['products_name'];
}

**ADD IMMEDIATELY AFTER THE ABOVE:
//SG Begin attribute validation
if ($messageStack->size('product_info') > 0) {
?>
	<tr>
			<td><?php echo $messageStack->output('product_info'); ?></td>
	</tr>
	<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
<?php  }
//SG End attribute validation


**FIND APPROX LINE 155:
$products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");
		$products_attribs_array = tep_db_fetch_array($products_attribs_query);

**ADD IMMEDIATELY AFTER THE ABOVE:
//SG Begin attribute validation
		$tmp_html = '<input type="text" id="' . TEXT_PREFIX . $products_options_name['products_options_id'] . '" name="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] .'">  <span id="inf_' . TEXT_PREFIX . $products_options_name['products_options_id'] . '"> </span>' . $products_options_name['products_options_comment'];
		//SG End attribute validation


=========================================
4.  Open catalog/includes/application_top.php
=========================================

**FIND APPROX LINE 324:
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
if ($session_started == false) {
  tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
}

**ADD IMMEDIATELY AFTER THE ABOVE:
  //SG Begin attribute validation
 if (DISPLAY_CART == 'true') {
 $goto =  FILENAME_SHOPPING_CART;
 $parameters = array('action', 'cPath', 'products_id', 'pid','mustselect');
  } else {
 $goto = basename($PHP_SELF);
 if ($HTTP_GET_VARS['action'] == 'buy_now') {
   $parameters = array('action', 'pid', 'products_id','mustselect');
 } else {
   $parameters = array('action', 'pid','mustselect');
 }
  }
 //SG End attribute validation

**FIND APPROX LINE 369:
// 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'])) {

**ADD IMMEDIATELY AFTER THE ABOVE:
//SG Begin attribute validation
						   if (is_array($HTTP_POST_VARS['id']) ) {
//								 $messageStack->reset();								  
							 while (list($option, $value) = each($HTTP_POST_VARS['id'])) {
							 switch ($option) {
							 	case 'txt_1': //Name
									$trimmedText = trim($value);
									if (strlen($trimmedText) < ENTRY_NAME_MIN_LENGTH) {
								   	tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'] . '&mustselect=product_name'));
													break;
												}
								   break;
								case 'txt_2': //Birthdate
									$strDate = $value;
								   $isValid = false;

								   if (ereg('^([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})$', $strDate)) {
									  $dateArr = split('[/]', $value);
									  $m=$dateArr[0]; $d=$dateArr[1]; $y=$dateArr[2];
									  $isValid = checkdate($m, $d, $y);
								   }

								   if (!$isValid) {
													tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'] . '&mustselect=product_birth'));
													break;
												}
								   break;
							   }   
							 }
						   } elseif (tep_has_product_attributes($HTTP_POST_VARS['products_id'])) {
							   tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_POST_VARS['products_id']));
							   break;
						   } 
						   //SG End attribute validation

**FIND APPROX LINE 544:
// initialize the message stack for output messages
 require(DIR_WS_CLASSES . 'message_stack.php');
 $messageStack = new messageStack;

**ADD IMMEDIATELY AFTER THE ABOVE:
//SG Begin attribute validation
if (isset($HTTP_GET_VARS['mustselect'])){
  $error = true;
  switch ($HTTP_GET_VARS['mustselect']) {
 case 'product_name' :
  $messageStack->add('product_info',ENTRY_NAME_ERROR);
  break;
 case 'product_birth' :
  $messageStack->add('product_info',ENTRY_BIRTHDATE_ERROR);
  break;
  }
}
//SG End attribute validation


=========================================
5.  Open catalog/includes/languages/english.php
=========================================

**ADD AT END OF PAGE JUST BEFORE ?>:

//SG Require products_options for ski passes
define ('ENTRY_NAME_ERROR', 'Full Name is Required to Purchase a Season Pass');
define ('ENTRY_NAME_MIN_LENGTH', '5');
define ('ENTRY_BIRTHDATE_ERROR', 'Birthdate is Required to Purchase a Season Pass. Please enter in format mm/dd/yyyy.');
define ('ENTRY_BIRTHDATE_MIN_LENGTH', '10');

 

 

 

New File - save as catalog/formValidate.js

// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
//
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// Update Aug 2004: have tested that IE 5.0 and IE 5.5 both support DOM model
// sufficiently well, so innerHTML option removed (redundant).
//
// Update Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
//
// Update Oct 2005: minor tidy-up: unused parameter removed
// ----------------------------------------------------------------------

var nbsp = 160;	// non-breaking space char
var node_text = 3; // DOM text node-type
var emptyString = /^\s*$/
var glb_vfld;	  // retain vfld for timer thread

// -----------------------------------------
//				  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
 return str.replace(/^\s+|\s+$/g, '')
};


// -----------------------------------------
//				  setfocus
// Delayed focus setting to get around IE bug
// -----------------------------------------

function setFocusDelayed()
{
 glb_vfld.focus()
}

function setfocus(vfld)
{
 // save vfld in global variable so value retained when routine exits
 glb_vfld = vfld;
 setTimeout( 'setFocusDelayed()', 100 );
}


// -----------------------------------------
//				  msg
// Display warn/error message in HTML element
// commonCheck routine must have previously been called
// -----------------------------------------

function msg(fld,	 // id of element to display message in
		 msgtype, // class to give element ("warn" or "error")
		 message) // string to display
{
 // setting an empty string can give problems if later set to a 
 // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
 // simply use a space, but IE demands something more, like a non-breaking space.)
 var dispmessage;
 if (emptyString.test(message)) 
dispmessage = String.fromCharCode(nbsp);	
 else  
dispmessage = message;

 var elem = document.getElementById(fld);
 elem.firstChild.nodeValue = dispmessage;  

 elem.className = msgtype;   // set the CSS class to adjust appearance of message
};

// -----------------------------------------
//			commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//		 false (validation failed) or 
//		 proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck	(vfld,   // element to be validated
					 ifld,   // id of element to receive info/error msg
					 reqd)   // true if required
{
 if (!document.getElementById) 
return true;  // not available on this browser - leave validation to the server
 var elem = document.getElementById(ifld);
 if (!elem.firstChild)
return true;  // not available on this browser 
 if (elem.firstChild.nodeType != node_text)
return true;  // ifld is wrong type of node  

 if (emptyString.test(vfld.value)) {
if (reqd) {
  msg (ifld, "error", "ERROR: ");  
  setfocus(vfld);
  return false;
}
else {
  msg (ifld, "warn", "");   // OK
  return true;  
}
 }
 return proceed;
}

// -----------------------------------------
//			validatePresent
// Validate if something has been entered
// Returns true if so 
// -----------------------------------------

function validatePresent(vfld,   // element to be validated
					 ifld )  // id of element to receive info/error msg
{
 var stat = commonCheck (vfld, ifld, true);
 if (stat != proceed) return stat;

 msg (ifld, "warn", "");  
 return true;
};

function validateDate( vfld, ifld ) {
 var stat = commonCheck (vfld, ifld, true);
 if (stat != proceed) return stat;

 var strValue = trim(vfld.value);
 var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/

 //check to see if in correct format
 if(!objRegExp.test(strValue)) {
 msg (ifld, "error", "ERROR: ");
setfocus(vfld);
return false; //doesn't match pattern, bad date
 }
 else{
var strSeparator = strValue.substring(2,3) //find date separator
var arrayDate = strValue.split(strSeparator); //split date into month, day, year
//create a lookup for months not equal to Feb.
var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
					'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
var intDay = parseInt(arrayDate[1]);

//check if month value and day value agree
if(arrayLookup[arrayDate[0]] != null) {
  if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
	return true; //found in lookup table, good date
}

//check for February (bugfix 20050322)
var intMonth = parseInt(arrayDate[0]);
if (intMonth == 2) { 
   var intYear = parseInt(arrayDate[2]);
   if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
	  return true; //Feb. had valid number of days
   }
 }
 msg (ifld, "error", "ERROR: ");
 setfocus(vfld);
 return false; //any other values, bad date
}



function validateOnSubmit() {
var elem;
var errs=0;
// execute all element validations in reverse order, so focus gets
// set to the first one in error.
if (!validateDate	(document.forms.cart_quantity.txt_2,   'inf_txt_2')) errs += 1; 
if (!validatePresent  (document.forms.cart_quantity.txt_1, 'inf_txt_1')) errs += 1; 

if (errs>1)  alert('Some fields have not been completed correctly');
if (errs==1) alert('There is a field which has not been completed correctly');

return (errs==0);
};

 

Good luck!


cdickson

Share this post


Link to post
Share on other sites

Text shows up in shopping cart and on checkout page, then it doesn't go through to email or order history and in the database gets overwritten by TEXT instead of the message customer wrote. I looked through this support thread and compared my files over and over to OTF 1.6 files. I don't see anything missing. I also tried what was suggested below (I see that it worked for many people) but no luck. :blink:

 

Any ideas would be greatly appreciated!

Thanks!

 

Looks like I found it in includes/classes/order.php:

 

Original (well, on a seriously modified site)

 

'value' => $attributes['products_options_values_name'],

 

From order.php from install files:

'value' => $attr_value,

Share this post


Link to post
Share on other sites

I had a little bit of trouble with the code when I first installed this as well. I downloaded WinMerge - a terrific, free program that compares code in documents - and I found quite a few little things that I missed the first time around. After correcting my code, the mod works great! You can download WinMerge at http://winmerge.org/.

 

Text shows up in shopping cart and on checkout page, then it doesn't go through to email or order history and in the database gets overwritten by TEXT instead of the message customer wrote. I looked through this support thread and compared my files over and over to OTF 1.6 files. I don't see anything missing. I also tried what was suggested below (I see that it worked for many people) but no luck. :blink:

 

Any ideas would be greatly appreciated!

Thanks!


cdickson

Share this post


Link to post
Share on other sites
I had a little bit of trouble with the code when I first installed this as well. I downloaded WinMerge - a terrific, free program that compares code in documents - and I found quite a few little things that I missed the first time around. After correcting my code, the mod works great! You can download WinMerge at http://winmerge.org/.

 

it was one little line and winmerge made all the difference! Thank you!! :D

Share this post


Link to post
Share on other sites

Hi all,

 

I really don't succeed to obtain the option name to appear for text and texarea options in the shopping cart, confirmation email, order history...

 

I've verified, and verified again...

 

I used WINMERGE to compare files...

 

I Tried to use directly the files :

includes/classes/order.php

includes/classes/shopping_cart.php

includes/functions/general.php

checkout_process.php

product_info.php

shopping_cart.php

 

from the contrib...

 

I've verified my configure.php :

 

I've well :

define('PRODUCTS_OPTIONS_VALUE_TEXT_ID', 0); //Must match id for user defined "Text" value in db table TABLE_PRODUCTS_OPTIONS_VALUES

 

I've verified my database :

TEXT is well set to 0...

 

I had done an error I saw : Used the bad product option value (a select one) with my products... But I test to modify my choice (creating a value to the the option type text) and order the product with option modified and don't work too...

 

 

PLEASE, it's 2:33 in the morning, I'm searching why it don't works since 14 HOURS without success, and it was monthes I search before too...

 

If someone has another idea... I would be graceful...

 

 

THANK YOU VERY MUCH.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×