Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Cannot get a button to work


DataMouse

Recommended Posts

Hi all

 

I hope that everyone's well.

 

I've got a store that I've been customising and have hit a snag.

It's a really simple issue, but my brain's fried.

 

My home page has four products showing which are built from an array.

The array includes the product image, text, title etc - plus a "details" and "add to cart" button.

 

I have the "details" button working perfect; it directs to the product in product_info

 

However, I cannot get the add to cart to do anything.

 

can anyone point out what I'm doing wrong, please?

 

Thanks

 

 

 

 

 

<tr>
		<td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main" height="<?php echo SMALL_IMAGE_HEIGHT + 4; ?>" ><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
		<td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . tep_date_long($products_new['products_date_added']) . '<br>' . TEXT_MANUFACTURER . ' ' . $products_new['manufacturers_name'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
		<td align="right" valign="middle" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>'; ?></td>
	  </tr>
	  <tr>

Link to comment
Share on other sites

Is this an MS2 site? if so is RG on/off, have u done RG fixes, if so which?

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Hey Sam. Thanks for dropping by (again) :D

It's an MS2 site with no fixes at all.

It's on PHP5 - so I've had to change some of the query stuff to prevent the 1054 errors.

 

Aside from that, it's virtually untouched in the front end.

It's a reworked template.

 

You can have a gander at www.absolutelyecigs.com/test.php (index has a redirect on it at present)

Link to comment
Share on other sites

There may be issues with application_top as its ms2, but I see others strait away.

 

The code u give anint the code on that page, there your using forms for each product, but every form has the same name, error 1

 

2 it looks like your using tep_image rather than tep_image_submit

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

You're right.

The code actually comes from products_new.php (in the root).

 

If I change

 

tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART)

 

to

 

tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART)

 

Will that get me back on track?

Link to comment
Share on other sites

BTW

The rest of the store works great (including add to cart buttons on other pages).

It's just this one buttonon this one page that's playing funny beggars...

Link to comment
Share on other sites

yes but also make sure every form has a different name, or you have trouble

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

I've posted completely the wrong code :rolleyes:

 

The main page pulls the info from a module called new_products - my mistake (late here)

 

They're not 4 forms. It's an infobox built using an array, which is split into four outputs (2 rows, 2 columns).

The proper full code is here:

 

<?php 
 if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 } else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 }

 $row = 0;
 $col = 0;
 $info_box_contents = array();
 while ($new_products = tep_db_fetch_array($new_products_query)) {
$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
$description_query = tep_db_query($sql);
$description = mysql_fetch_array($description_query, MYSQL_ASSOC);		
$description['products_description'] = substr($description['products_description'], 0, 65);
$desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
$description['products_description'][$desc_len-2] = '.';
$description['products_description'][$desc_len-3] = '.';

if  ( ($col == 1 && $row == 0) || ($col == 1 && $row == 2) ){
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'width="1" height="100%" valign="middle" style="border-left:1px solid #5E6367"',
									   'text' => '<table height="" width="100%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td><div style="width:1px;"></div></td>
 </tr>
</table>');
}
elseif (($col == 0 && $row == 1) || ($col == 2 && $row == 1)) {
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'height="1"',
									   'text' => '<table width="95%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td style="font-size:1px;background:url(images/points.gif) repeat-x;"> </td>
 </tr>
</table>');
}
elseif ($col == 1 && $row == 1) {
$info_box_contents[$row][$col] = array('align' => '',
									   'params' => '',
									   'text' => ' ');
}
else {	
$info_box_contents[$row][$col] = array('align' => 'left',
									   'params' => 'class="main" width="340"  valign="top" align="left"',
									   'text' => '<table width="340" cellpadding=0 cellspacing=0 border=0 style="margin:8px 1px 10px 0px;">
									   				<tr>
															<td rowspan="4"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="absmiddle"') . '</a></td>
															<td height="35" style="padding-right:10px;"><div style="border-bottom:1px solid #333333" class="productName">'.$new_products['products_name'].'</div></td>
													</tr>
													<tr>

														<td height="60" align="left" valign="top">'.$description['products_description'].'</td>
													</tr>
													<tr>
														<td height="32" ><span style="color:#FF7F00; font-size:20px; "> ' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span></td>
													</tr>
													<tr>		
															<td class="main" valign=top align="right" style="padding-right:10px; >'. tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'
																<table width="100%"  border="0" cellspacing="0" cellpadding="0" style="border-top:1px solid #333333; ">
																  <tr>	
																	<td style="padding-top:1px; padding-right:1px;" ><a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'">'.tep_image_button('button_details.gif', IMAGE_BUTTON_DETAILS).'</a></td><td style="padding-top:1px;">'.tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_BY_NOW).'</td>
																  </tr>
																</table></form>
															</td>
														</tr>
													</table>'); }


$col ++;
if ($col > 2) {
  $col = 0;
  $row ++;
}

 }
 new contentBox($info_box_contents, 0);

?>
</div>

Link to comment
Share on other sites

The details button works fine:

<a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'">'.tep_image_button('button_details.gif', IMAGE_BUTTON_DETAILS).'</a>

 

The add to cart button code doesn't:

td style="padding-top:1px;">'.tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_BY_NOW).'</td>

 

I'm sure it'ssomething simple with this line.

Maybe the hidden field aspect...

Link to comment
Share on other sites

There are multiple forms, as the way u wrote it each product is in its own form!, always called cart_quantity, look at the generated source!!

 

simplest fix, change

 

tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'

to

 

tep_draw_form('cart_quantity' . $col .  $row , tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Right. I see it now.

 

How come the product button works? Because it's given a "a href" location on-the-fly?

Can this be done with an add-to-cart button too?

 

The change hasn't fixed :(

 

Cheers for this Sam. You're a star.

Link to comment
Share on other sites

Yes it can,

 

have u changed to the tep_image_submit?

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Yes - I believe so:

<td style="padding-top:1px; padding-right:1px;" ><a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'">'.tep_image_button('button_details.gif', IMAGE_BUTTON_DETAILS).'</a></td><td style="padding-top:1px;">'.tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_BY_NOW).'</td>

Link to comment
Share on other sites

Ok I think your hidden is messing it, remove

tep_draw_hidden_field('products_id', $new_products['products_id']) .

from where it is & put it just after the form, like:

 

tep_draw_form('cart_quantity' . $col .  $row , tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'

 

becomes

 

tep_draw_form('cart_quantity' . $col .  $row , tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).
tep_draw_hidden_field('products_id', $new_products['products_id']) . '

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

No joy :(

 

The code now looks like this:

 

<?php 
 if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 } else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 }

 $row = 0;
 $col = 0;
 $info_box_contents = array();
 while ($new_products = tep_db_fetch_array($new_products_query)) {
$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
$description_query = tep_db_query($sql);
$description = mysql_fetch_array($description_query, MYSQL_ASSOC);		
$description['products_description'] = substr($description['products_description'], 0, 65);
$desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
$description['products_description'][$desc_len-2] = '.';
$description['products_description'][$desc_len-3] = '.';

if  ( ($col == 1 && $row == 0) || ($col == 1 && $row == 2) ){
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'width="1" height="100%" valign="middle" style="border-left:1px solid #5E6367"',
									   'text' => '<table height="" width="100%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td><div style="width:1px;"></div></td>
 </tr>
</table>');
}
elseif (($col == 0 && $row == 1) || ($col == 2 && $row == 1)) {
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'height="1"',
									   'text' => '<table width="95%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td style="font-size:1px;background:url(images/points.gif) repeat-x;"> </td>
 </tr>
</table>');
}
elseif ($col == 1 && $row == 1) {
$info_box_contents[$row][$col] = array('align' => '',
									   'params' => '',
									   'text' => ' ');
}
else {	
$info_box_contents[$row][$col] = array('align' => 'left',
									   'params' => 'class="main" width="340"  valign="top" align="left"',
									   'text' => '<table width="340" cellpadding=0 cellspacing=0 border=0 style="margin:8px 1px 10px 0px;">
									   				<tr>
															<td rowspan="4"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="absmiddle"') . '</a></td>
															<td height="35" style="padding-right:10px;"><div style="border-bottom:1px solid #333333" class="productName">'.$new_products['products_name'].'</div></td>
													</tr>
													<tr>

														<td height="60" align="left" valign="top">'.$description['products_description'].'</td>
													</tr>
													<tr>
														<td height="32" ><span style="color:#FF7F00; font-size:20px; "> ' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span></td>
													</tr>
													<tr>		
															<td class="main" valign=top align="right" style="padding-right:10px; >'. tep_draw_form('cart_quantity' . $col .  $row , tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).
tep_draw_hidden_field('products_id', $new_products['products_id']) . '
																<table width="100%"  border="0" cellspacing="0" cellpadding="0" style="border-top:1px solid #333333; ">
																  <tr>	
																	<td style="padding-top:1px; padding-right:1px;" ><a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'">'.tep_image_button('button_details.gif', IMAGE_BUTTON_DETAILS).'</a></td><td style="padding-top:1px;">'.tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_BY_NOW).'</td>
																  </tr>
																</table></form>
															</td>
														</tr>
													</table>'); }


$col ++;
if ($col > 2) {
  $col = 0;
  $row ++;
}

 }
 new contentBox($info_box_contents, 0);

?>

Link to comment
Share on other sites

Should have spotted before, your crossing bounaries!!

 

move the

 

<table width="100%"  border="0" cellspacing="0" cellpadding="0" style="border-top:1px solid #333333; ">

 

 

to just before the tep_draw_form

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Sam

 

Cheers for your help - I really appreciate it.

I've gotta go and get some sleep,as 'm dropping on my feet here.

 

I'll check back in the morning.

 

Thanks again

Link to comment
Share on other sites

Sam

 

I figured it out and have postedit here in case anyone else wants to see:

 

<?php 
 if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 } else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
 }

 $row = 0;
 $col = 0;
 $info_box_contents = array();
 while ($new_products = tep_db_fetch_array($new_products_query)) {
$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$new_products['products_id'].' && language_id='.(int)$languages_id;
$description_query = tep_db_query($sql);
$description = mysql_fetch_array($description_query, MYSQL_ASSOC);		
$description['products_description'] = substr($description['products_description'], 0, 65);
$desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
$description['products_description'][$desc_len-2] = '.';
$description['products_description'][$desc_len-3] = '.';

if  ( ($col == 1 && $row == 0) || ($col == 1 && $row == 2) ){
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'width="1" height="100%" valign="middle" style="border-left:1px solid #5E6367"',
									   'text' => '<table height="" width="100%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td><div style="width:1px;"></div></td>
 </tr>
</table>');
}
elseif (($col == 0 && $row == 1) || ($col == 2 && $row == 1)) {
$info_box_contents[$row][$col] = array('align' => 'center',
									   'params' => 'height="1"',
									   'text' => '<table width="95%" border="0" cellspacing="0" cellpadding="0" >
 <tr>
<td style="font-size:1px;background:url(images/points.gif) repeat-x;"> </td>
 </tr>
</table>');
}
elseif ($col == 1 && $row == 1) {
$info_box_contents[$row][$col] = array('align' => '',
									   'params' => '',
									   'text' => ' ');
}
else {	
$info_box_contents[$row][$col] = array('align' => 'left',
									   'params' => 'class="main" width="340"  valign="top" align="left"',
									   'text' => '<table width="340" cellpadding=0 cellspacing=0 border=0 style="margin:8px 1px 10px 0px;">
									   				<tr>
															<td rowspan="4"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="absmiddle"') . '</a></td>
															<td height="35" style="padding-right:10px;"><div style="border-bottom:1px solid #333333" class="productName">'.$new_products['products_name'].'</div></td>
													</tr>
													<tr>

														<td height="60" align="left" valign="top">'.$description['products_description'].'</td>
													</tr>
													<tr>
														<td height="32" ><span style="color:#FF7F00; font-size:20px; "> ' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span></td>
													</tr>
													<tr>		
															<td class="main" valign=top align="right" style="padding-right:10px; >'. tep_draw_form('cart_quantity' . $col .  $row , tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).
tep_draw_hidden_field('products_id', $new_products['products_id']) . '
																<table width="100%"  border="0" cellspacing="0" cellpadding="0" style="border-top:1px solid #333333; ">
																  <tr>	
																	<td style="padding-top:1px; padding-right:1px;" ><a href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']).'">'.tep_image_button('button_details.gif', IMAGE_BUTTON_DETAILS).'</a></td><td style="padding-top:1px;">'.tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).tep_draw_hidden_field('products_id', $new_products['products_id']) . tep_image_submit('add_to_cart.gif', IMAGE_BUTTON_IN_CART).'</td>


																  </tr>
																</table></form>
															</td>
														</tr>
													</table>'); }


$col ++;
if ($col > 2) {
  $col = 0;
  $row ++;
}

 }
 new contentBox($info_box_contents, 0);

?>

 

Thanks again :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...