Post by troyveluz » Wed Jul 23, 2008 8:45 am

Step 1
Edit catalog/template/default/content/Product.tpl
Look for the line : :
Insert this below that line:

Code: Select all

<script language="JavaScript" type="text/javascript">
 <!--
 function chgVal(myVal,hiddenTxt) { 
  mycntl=document.getElementById(hiddenTxt); 
  mycntl.value=mycntl.value+myVal;
 //alert (mycntl.value); 
} 
//--> </script>
Look for this code:

Code: Select all

      <?php foreach ($options as $option) {  ?>
 		<tr>
		<td><?php echo $option['name']; ?>:</td>
		<td><select name="option[<?php echo $option['option_id']; ?>]">						<?php foreach ($option['value'] as $option_value) { ?>
				<option value="<?php echo $option_value['product_to_option_id']; ?>"><?php echo $option_value['name']; ?>
				<?php if ($option_value['price']) { ?> 
				<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
				<?php } ?>
				</option>
				<?php } ?>
			  </select></td>
      		</tr>
<?php } ?>
Replace that code with:

Code: Select all

//===tv start
<?php foreach ($options as $option) {
if ( strpos($option['name'],'[input:') === false ) { ?>
		 <tr>
			<td><?php echo $option['name']; ?>:</td>
			<td><select name="option[<?php echo $option['option_id']; ?>]">
				<?php foreach ($option['value'] as $option_value) { ?>
				<option value="<?php echo $option_value['product_to_option_id']; ?>"><?php echo $option_value['name']; ?>
				<?php if ($option_value['price']) { ?> 
				<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
				<?php } ?>
				</option>
				<?php } ?>
			  </select></td>
      		</tr>
		<?php	
		} else { 
		    ?>
			<tr><td>
		   	<?php $tv_input=str_replace('[input:','', $option['name']);
				$tv_input=str_replace(']','', $tv_input);
		   		$tv_input=str_replace('[',' :</td><td> <input ', $tv_input);
								$tv_input.=' :</td><td> <input ';
				foreach ($option['value'] as $option_value) {
					$tv_params=str_replace('[',' ',$option_value['name']);
					$tv_params=str_replace(':','="',$tv_params);
					$tv_params=str_replace(']','" ',$tv_params);
					$tv_input.=$tv_params;
				}
				// 
				$tv_input.='name="temp['.$option['option_id'].']" onBlur="chgVal(this.value,\'option'.$option['option_id'].'\')" >';
				$tv_input.='<input type="hidden" name="option['.$option['option_id'].']" id="option'.$option['option_id'].'"';
				$tv_input.=' value="'.$option_value['product_to_option_id'].'~"> </td></tr>';
				echo $tv_input;
		 } //=== end if		
       } //===  end options ?>
//===tv end
Step 2
Edit the file library/cart/cart.php
Look for this line of code:

Code: Select all

$option = $this->database->getRow("select o.name as name, ov.name as `value`, p2o.price, p2o.prefix from product_to_option p2o left join `option` o on p2o.option_id = o.option_id left join option_value ov on p2o.option_value_id = ov.option_value_id where p2o.product_to_option_id = '" . $tv_ptoid . "' and product_id = '" . (int)$product_id . "' and o.language_id = '" . (int)$this->language->getId() . "' and ov.language_id = '" . (int)$this->language->getId() . "'");
Insert this above that line of code:

Code: Select all

//===tv				    
                    $tv_ptoid=strval($product_to_option_id);
 	      $tv_pos=strpos($tv_ptoid,'~');
                    if ($tv_pos === false) {
                    } else {	
                        $tv_optVal=substr($tv_ptoid,$tv_pos+1);
                         $product_to_option_id=substr($tv_ptoid,0,$tv_pos);
                    }
              //===tv end	
And insert this below that line of code:

Code: Select all

//===tv
	if ($tv_pos !== false ){
                    $option['name']=str_replace('input:','',$option['name'])
                    $option['name']=str_replace(']','',$option['name']);
                    $option['value']=$tv_optVal;
               }
	$option['name'].=': ';
 //===tv end
Step 3
To create a textbox for your product:
1) Create an option with the format [input:optionName]
example: [input:Monogram Initials]
2) Create option values with the format [attribute:attributeValue].
*It is mandatory that you create an option value with the name [type:text].
You can add other textbox attributes, for example,
a. [size:20]
b. [maxlenght:30]
3) Add the option value(s) to your product.

That's it.
Regards,
Troy

==========================================================================
Veluzar Studios
Web Design and Development


New member

Posts

Joined
Thu Jul 17, 2008 1:45 am
Location - Frisco, TX USA

Post by anmp3r » Wed Jul 23, 2008 9:10 am

any chance of a screenshot to show us??

cheers mate!  ;D

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by troyveluz » Wed Jul 23, 2008 10:16 am

You can find the demo at my  test opencart site.
Here is the url to product 1 with a textbox and other options:
http://www.veluzarwebdesign.com/octplt/ ... oduct_id=1
Here is the url to product 2 with two texboxes:
http://www.veluzarwebdesign.com/octplt/ ... oduct_id=2
Regards,
Troy

==========================================================================
Veluzar Studios
Web Design and Development


New member

Posts

Joined
Thu Jul 17, 2008 1:45 am
Location - Frisco, TX USA

Post by alice » Mon Aug 11, 2008 3:38 pm

I am not quite sure if this is what I am looking for or not but I would like
to have a textbox where my clients can type in.

Place: Each product page. In the available option section. (I want: not just only a drop down but also a text box)

Is this possible with this code? And if so, I didn't get it where you said

""Create an option with the format [input:optionName]""

Do this in Admin?

Thank you,

Newbie

Posts

Joined
Thu Jun 19, 2008 5:29 pm

Post by kgrace » Wed Dec 31, 2008 2:06 pm

Troy:

I was looking for this functionality and your post is great.  Thanks.  For other non-php folks, I didn't get it work exactly as posted - showed a blank page at first. I realized after looking carefully that a line was missing a semicolon. The last code section in step 2 showed the following:

Code: Select all

//===tv
	if ($tv_pos !== false ){
                    $option['name']=str_replace('input:','',$option['name'])
                    $option['name']=str_replace(']','',$option['name']);
                    $option['value']=$tv_optVal;
               }
	$option['name'].=': ';
 //===tv end
It should have been:

Code: Select all

//===tv
	if ($tv_pos !== false ){
                    $option['name']=str_replace('input:','',$option['name']);    <-----the missing semicolon
                    $option['name']=str_replace(']','',$option['name']);
                    $option['value']=$tv_optVal;
               }
	$option['name'].=': ';
 //===tv end
Only other thing I noticed was there were php comments outside of php tags in the product.tpl code section

Code: Select all

//===tv 

...

//===tv end

To make it all clean you'll want to either wrap these in php tags or just delete them.


Troy - you're the man.  Thanks for this valuable post. 

Regards,
Kevin G.

User avatar
Newbie

Posts

Joined
Wed Dec 31, 2008 1:57 pm

Post by kgrace » Mon Jan 12, 2009 3:18 am

I started to ask is there a way to make options required - then I realized they are required once assigned by default.  So -

Anyone know an easy way to make sure these text fields actually have data.  I assume you'd have to use something driven on the "onClick" or "onFocus" add to cart button event using javascript..

maybe someone might have a better idea??  Maybe checking the option value in the php code before to see if it's null??  how hard would that be? any other ideas?

My problem - have text field options using the information in this topic - but like to make some of them required fields before you can add the product to cart.

Many thanks,
Kevin

User avatar
Newbie

Posts

Joined
Wed Dec 31, 2008 1:57 pm

Post by cparkner01 » Sun Feb 08, 2009 4:11 am

I have tried to get this to work and keep throwing errors, it seems it is conflicting with another product option (the upload file product option), would anyone be willing to custom code a feature like this for some paypal cash?  PM me if interested and let me know your price.

Newbie

Posts

Joined
Sat Feb 07, 2009 4:57 am
Who is online

Users browsing this forum: No registered users and 3 guests