Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Replace "Buy Now" link on products_listing.php with jquery button?


Landho

Recommended Posts

Posted

Is this possible?

 

I was able to change the link to a .gif, using this snip below...

 

$prod_list_contents .= '<a href="' . tep_href_link(basename(($PHP_SELF)), tep_get_all_get_params(array('action','sort','products_id')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW, 'style="padding-bottom: 5px;"') . '</a>';

 

But I would really like it to be the Add to Cart button like what is on the product_info.php page... and based off of the jquery theme choosen...

 

I have tried several variants of this snippet from product_info.php without success...

 

tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary');

 

 

I have done a clean install of 2.3.3, painstakenly imported the old MC2 store mysql stuff, I have also replaced the product_listing.php table with CSS - all is going great, just getting the product_listing page to show nicely right now and I can't get the darn button to appear without it being an image.

 

Thanks,

Rich

Posted

The stock button should still work:

 

tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']))

 

You may need to wrap that in something your CSS can manipulate. I don't know what changes you've made there so I can't be more specific.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Posted

Thanks... I will bang around with that... I think I have tried that before - is there some magical setting elsewhere that would change the link from a "link" to a button that I am missing?

 

I haven't done anything too crazy as far as changes yet - I roughly followed this guide http://www.oscommerce-template-easy.com/oscommerce-2-3-3/product-listing-page-change-to-css-div-layers-customization.html to move product listing to CSS, have not finished yet as I've been hung up on getting the darn button to work with jquery instead of an image.

Posted

There are two types of button in osCommerce. The Buy Now button on the Product Info page is a form submit button, while the Buy Now buttons on the Categories page (product_listing.php) are links. The buttons are drawn by jQuery UI so they all follow the theme.

 

If the code I posted isn't working, it's likely that something is interfering with the CSS. Use Firebug or a similar inspection tool to check the CSS that your button is using.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Posted

The code you provide above still results in just a link, and not an image... I am missing a piece of the magic which should be occuring elsewhere and have only been messing with 2.3.3 for a few hours - so I haven't traced back where the link becomes a button yet. Spoiled after 6+ years of the good old MC2 code I was more familiar with... or unfamiliar with because I haven't had to change much until recently when forced to upgrade to get some PayPal and some other features added.

 

Here is what I have messed up so far, mostly, to the product_listing.php lol... I am trying to keep this "fresh" 2.3.3 site as "stock" as possible - but getting it to look like the old MC version is proving impossible, so hacks abound.

 

   while ($listing = tep_db_fetch_array($listing_query)) {
  $rows++;
  $prod_list_contents .= '<div class="outerDiv">';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
	   case 'PRODUCT_LIST_IMAGE':
	  $prod_list_contents .= '<div class="outerLeftDiv">'.	 
												    '<div class="innerLeftDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    }
   $prod_list_contents .=	   '</div>' .
												    '<div class="innerRightDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    }
 $prod_list_contents .=	   '</div>' .
												 '</div><!-- end outerLeftDiv -->' .
												 '<div class="outerRightDiv">' .
		  '<div class="InnerLeftDiv">';
		  if (tep_not_null($listing['specials_new_products_price'])) {
		  $prod_list_contents .= '	    ' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
	    } else {
		  $prod_list_contents .= '	    ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '';
	    }
   $prod_list_contents .=	  '</div>' .
		  '<div class="InnerRightDiv">';
		  $prod_list_contents .= '<a href="' . tep_href_link(basename(($PHP_SELF)), tep_get_all_get_params(array('action','sort','products_id')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW, 'style="padding-bottom: 5px;"') . '</a>';
   $prod_list_contents .=	  '</div>' .
			 '</div><!-- end outerRightDiv -->';
    break;

    }
   }
  $prod_list_contents .= '</div>';
   }

Posted

It is picking up ".tbdLink a" instead of ".tbdLink button", this is what I have been hung up on... getting closer though.

 

I really appreciate the help

Posted

Your code still has the old image link so I can't tell anything from that.

 

tep_draw_button() should just work, and usually will unless something is interfering.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Posted

Sorry - that was what I was banging on before your help... here is where I've added your code -

 

$prod_list_contents .= '  <div class="ui-widget-content ui-corner-bottom productListTable">' .
					   '';
   while ($listing = tep_db_fetch_array($listing_query)) {
  $rows++;
  $prod_list_contents .= '<div class="outerDiv">';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
	   case 'PRODUCT_LIST_IMAGE':
	  $prod_list_contents .= '<div class="outerLeftDiv">'.	 
												    '<div class="innerLeftDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    }
   $prod_list_contents .=	   '</div>' .
												    '<div class="innerRightDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    }
 $prod_list_contents .=	   '</div>' .
												 '</div><!-- end outerLeftDiv -->' .
												 '<div class="outerRightDiv">' .
		  '<div class="InnerLeftDiv">';
		  if (tep_not_null($listing['specials_new_products_price'])) {
		  $prod_list_contents .= '	    ' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
	    } else {
		  $prod_list_contents .= '	    ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '';
	    }
   $prod_list_contents .=	  '</div>' .
		  '<div class="InnerRightDiv">' .
		  '<div class="contentContainer"><div class="buttonSet"><span class="buttonActionProductInfoCart">';
   $prod_list_contents .=	  tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])) .
		  '</span></div></div>';
   $prod_list_contents .=	  '</div>' .
			 '</div><!-- end outerRightDiv -->';
    break;

    }
   }
  $prod_list_contents .= '</div>';
   }
   $prod_list_contents .= '' .
					   '  </div>' .
					   '</div>';
   echo $prod_list_contents;

 

I also tried this with no luck... without the '<div class="contentContainer"><div class="buttonSet"><span class="buttonActionProductInfoCart">';

 

		  '';
   $prod_list_contents .=	  tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])) .
		  '';

Posted

You have an extra </span> after the button. I don't know if all of the div's match up, but an error there can also mess up the display. View the page source in Firefox and look for tags in red -- those are the ones it thinks are incorrect.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Posted

I banged and banged on this for a bit today... still haven't figured it out... I even reverted to the "stock" product_listing.php page and tried your code snip and still the link appears as a hyperlink and not the jquery themed button. grr....

 

 

 

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
*/
 $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');
?>
 <div class="contentText">
<?php
 if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
   <div>
  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
  <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></span>
   </div>
   <br />
<?php
 }
 $prod_list_contents = '<div class="ui-widget infoBoxContainer">' .
				    '  <div class="ui-widget-header ui-corner-top infoBoxHeading">'; /** . **/
				   /** '    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingHeader">' .
				    '	  <tr>';
 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
   $lc_align = '';
   switch ($column_list[$col]) {
  case 'PRODUCT_LIST_MODEL':
    $lc_text = TABLE_HEADING_MODEL;
    $lc_align = '';
    break;
  case 'PRODUCT_LIST_NAME':
    $lc_text = TABLE_HEADING_PRODUCTS;
    $lc_align = '';
    break;
  case 'PRODUCT_LIST_MANUFACTURER':
    $lc_text = TABLE_HEADING_MANUFACTURER;
    $lc_align = '';
    break;
  case 'PRODUCT_LIST_PRICE':
    $lc_text = TABLE_HEADING_PRICE;
    $lc_align = 'right';
    break;
  case 'PRODUCT_LIST_QUANTITY':
    $lc_text = TABLE_HEADING_QUANTITY;
    $lc_align = 'right';
    break;
  case 'PRODUCT_LIST_WEIGHT':
    $lc_text = TABLE_HEADING_WEIGHT;
    $lc_align = 'right';
    break;
  case 'PRODUCT_LIST_IMAGE':
    $lc_text = TABLE_HEADING_IMAGE;
    $lc_align = 'center';
    break;
  case 'PRODUCT_LIST_BUY_NOW':
    $lc_text = TABLE_HEADING_BUY_NOW;
    $lc_align = 'center';
    break;
   }
   if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
  $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
   }

   $prod_list_contents .= '	    <td' . (tep_not_null($lc_align) ? ' align="' . $lc_align . '"' : '') . '>' . $lc_text . '</td>';
 }
**/
  /** '	  </tr>' . **/
					 /** '    </table>' . **/
 $prod_list_contents .= '  </div>';
 if ($listing_split->number_of_rows > 0) {
   $rows = 0;
   $listing_query = tep_db_query($listing_split->sql_query);
   $prod_list_contents .= '  <div class="ui-widget-content ui-corner-bottom productListTable">' .
					   '';
   while ($listing = tep_db_fetch_array($listing_query)) {
  $rows++;
  $prod_list_contents .= '<div class="outerDiv">';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
	   case 'PRODUCT_LIST_IMAGE':
	  $prod_list_contents .= '<div class="outerLeftDiv">'.	 
												    '<div class="innerLeftDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
	    }
   $prod_list_contents .=	   '</div>' .
												    '<div class="innerRightDiv">';
		  if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    } else {
		  $prod_list_contents .= '	    <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
	    }
 $prod_list_contents .=	   '</div>' .
												 '</div><!-- end outerLeftDiv -->' .
												 '<div class="outerRightDiv">' .
		  '<div class="InnerLeftDiv">';
		  if (tep_not_null($listing['specials_new_products_price'])) {
		  $prod_list_contents .= '	    ' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
	    } else {
		  $prod_list_contents .= '	    ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '';
	    }
   $prod_list_contents .=	  '</div>' .
		  '<div class="InnerRightDiv">' .
		  '<div class="contentContainer"><div class="buttonSet"><span class="buttonActionProductInfoCart">';
   $prod_list_contents .=	  tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])) .
		  '</span></div></div>';
   $prod_list_contents .=	  '</div>' .
			 '</div><!-- end outerRightDiv -->';
    break;

    }
   }
  $prod_list_contents .= '</div>';
   }
   $prod_list_contents .= '' .
					   '  </div>' .
					   '</div>';
   echo $prod_list_contents;
 } else {
?>
   <p><?php echo TEXT_NO_PRODUCTS; ?></p>
<?php
 }
 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
   <br />
   <div>
  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
  <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></span>
   </div>
<?php
 }
?>
 </div>

Archived

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

×
×
  • Create New...