Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Ajax Buy Now


azer

Recommended Posts

I'm using STS 4.5 and I got it working by changing

if (strstr($scriptbasename, "popup")|| strstr($scriptbasename, "info_shopping_cart"))

in sts_default to

if (strstr($scriptbasename, "popup")|| strstr($scriptbasename, "info_shopping_cart") || strstr($scriptbasename, "ajax"))  

 

I enabled infoboxes and created infobox_shopping_cart.php.html and wrapped like so:

 

     <tr>
      <td style="padding: 0">
      <script language="JavaScript" src="includes/ajax_sc.js"></script>
        <div id="divShoppingCard"><table border="0" width="100%" cellspacing="0" cellpadding="2">$content</table></div>
      </td>
    </tr>

 

Hope this helps Someone

 

This is working just for STS or could work for a normal OSC too? I'm getting crazy let this od work with GZip enabled...

my contribution: Alex's Contributions

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Hi there

 

First of all - thanks for this great contrib!

 

Good work. :thumbsup:

 

 

It workd great for me so far but in IE7/IE6 after pressing the buy now button on the product list the shopping cart still shows up??

 

In Firefox and Opera all works just perfect.

 

In your DEMO Shop

http://www.netso.ru/index.php?cPath=1_68 it is also broken in IE7 (if added from the product_listing)

First it seems ok but half a second after the image flies over to the border the shopping cart pops up.

 

 

Any hints?

 

 

Thnx in advance :)

Edited by ronnie
Link to comment
Share on other sites

ronnie mc donnie:

 

Would you share your website URL and which release did you install? Did you have to make any alterations other than to follow the install instructions from the contribution download?

 

Hi there

 

First of all - thanks for this great contrib!

 

Good work. :thumbsup:

 

 

It workd great for me so far but in IE7/IE6 after pressing the buy now button on the product list the shopping cart still shows up??

 

In Firefox and Opera all works just perfect.

 

In your DEMO Shop

http://www.netso.ru/index.php?cPath=1_68 it is also broken in IE7 (if added from the product_listing)

First it seems ok but half a second after the image flies over to the border the shopping cart pops up.

 

 

Any hints?

 

 

Thnx in advance :)

Link to comment
Share on other sites

  • 4 months later...

Posted a new ajax_sc.js javascript file that will fix the location of the

loading image in various browsers.

 

if you haven't modified ajax_sc.js, simply replace this file; otherwise

you already know a bit about programming so use a file diff.

 

tested on ie5,ie6,ie7 and mozilla; but should work on most others

 

to see in action:

ajax buy now example

Link to comment
Share on other sites

How about the flying product image? That's the really cool part. The world will beat a path to your door if you could figure out how to get the flying image to work correctly.

 

 

Posted a new ajax_sc.js javascript file that will fix the location of the

loading image in various browsers.

 

if you haven't modified ajax_sc.js, simply replace this file; otherwise

you already know a bit about programming so use a file diff.

 

tested on ie5,ie6,ie7 and mozilla; but should work on most others

 

to see in action:

ajax buy now example

Link to comment
Share on other sites

How about the flying product image? That's the really cool part. The world will beat a path to your door if you could figure out how to get the flying image to work correctly.

 

like others on this forum, it's part personal taste and part lesson hard learned. I always aim for simple & functional for customers and can accomplish this without using flying image.

 

The ajax loading/added to cart message combined with common colors between the message and shopping cart box works well with our customers; ie. lets them buy more with less effort by eliminating full page reloads and having to view shopping cart after every add.

 

Good luck to all working on the fly to cart feature... given all the compatibility caveats with javascript, I'd make sure the fly-to-cart adds enough real value to cover the risk and extra code size.

Link to comment
Share on other sites

I wish this board allowed longer for editing a posting.

 

Correction: The buy now button at the product_info page does add the product to the cart but there is no indication that it has done so and you must reload the page to see the addition in the shopping cart. I must be missing something.

 

Do I need to add some code to product_info.php? I cannot add an item to the cart from the product_info pages.
Link to comment
Share on other sites

I wish this board allowed longer for editing a posting.

 

Correction: The buy now button at the product_info page does add the product to the cart but there is no indication that it has done so and you must reload the page to see the addition in the shopping cart. I must be missing something.

 

nothing special on product_info, if this is working on other pages but not here... then check the key functions individually on broken page and compare to something that is working.

 

in an Ajax program, you have the following:

 

1) set up response handler from server;

this is done in ajax_shopping_cart.php... make sure you are calling this cart on every page where you use the function; in readme.txt, this is show in edits for column_right.php. The response handler is setup here and also the div tag id where the updated info is to be displayed. oh, btw watch the name on the div tag... it is "divShoppingCard" not cart? may be a typo that slipped in.

 

if you don't have this right... you'll send the request to server, but you're page won't know to update? sounds similar to your case. I'd compare my column_right.php and shopping_cart.php calls as a start.

 

2) call to server to do something; if you've made code changes to html_output and general.php, you should be ok here.

 

3) handle server response at browser... you setup this in #1; once server has added to cart, it sends back response that is targeted at your new div tag set up earlier.

Link to comment
Share on other sites

Many thanks! This gives somehing to work on. Appreciate the tips and help.

 

nothing special on product_info, if this is working on other pages but not here... then check the key functions individually on broken page and compare to something that is working.

 

in an Ajax program, you have the following:

 

1) set up response handler from server;

this is done in ajax_shopping_cart.php... make sure you are calling this cart on every page where you use the function; in readme.txt, this is show in edits for column_right.php. The response handler is setup here and also the div tag id where the updated info is to be displayed. oh, btw watch the name on the div tag... it is "divShoppingCard" not cart? may be a typo that slipped in.

 

if you don't have this right... you'll send the request to server, but you're page won't know to update? sounds similar to your case. I'd compare my column_right.php and shopping_cart.php calls as a start.

 

2) call to server to do something; if you've made code changes to html_output and general.php, you should be ok here.

 

3) handle server response at browser... you setup this in #1; once server has added to cart, it sends back response that is targeted at your new div tag set up earlier.

Link to comment
Share on other sites

Hello again:

 

Now I remember the problem I had and exactly why it wouldn't work for me in the product_info page. The following is the the post I made back in March 1996 and the answer I received from Medreces a few days later: "Unfortunately this version does not work with sending POST-data. It will be in following release." So it seems I am at the same impasse.

 

Begin previous posting:

My catalog/includes/modules/product_listing.php:

 

$lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing['products_id']) . '"><input type="hidden" name="products_id" value="' . $listing['products_id'] . '"><input type="text" name="quantity" value="1" maxlength="5" size="5">
  ' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';

 

Please help me to add:

 

// AJAX Addto shopping_cart - Begin
  $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . 'loading.gif', '', '', '', 'align="absmiddle" id="loading_' . $listing['products_id'] . '" style="visibility: hidden;"') . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
  // AJAX Addto shopping_cart - End

END of Previous posting

Link to comment
Share on other sites

...

 

$lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing['products_id']) . '"><input type="hidden" name="products_id" value="' . $listing['products_id'] . '"><input type="text" name="quantity" value="1" maxlength="5" size="5">
  ' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';

 

Please help me to add:

 

// AJAX Addto shopping_cart - Begin
  $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . 'loading.gif', '', '', '', 'align="absmiddle" id="loading_' . $listing['products_id'] . '" style="visibility: hidden;"') . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
  // AJAX Addto shopping_cart - End

END of Previous posting

 

Joe, looks like you already have the answer... but why are you using post data on product_listing.php and get data on your other pages where you said this works? Even though post data doesn't show up in the header line, its just as easy to read your post variables as get variables from a hackers view; so make sure you don't ever rely on post for security.

 

if you decide you can't live without post data, then you'll have to build yourself a new ajax_sc.js to send post data and a new ajax_shopping_cart.php to receive the post data and complete the http request. fortunately the server doesn't care if it is post or get for any application including Ajax apps.

 

I'd recommend getting your product_listing working with get statements if possible... and before you start rebuilding ajax apps I'd recommend Head Rush Ajax from Oreilly books, it's simple to understand (good for me) and makes reworking Ajax apps a breeze.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Hello,

 

I've got a stumper of a question for this contribution.

 

I'm using QTPro on my site. Some of my products have extra options, others do not.

 

Go to this page - choose a color - click "add to cart"

 

http://loiterink.com/alcoholics-synonymous-p-438/

 

go to this page - and click "add to cart"

 

http://loiterink.com/the-birds-p-382/

 

The "add to cart" feature works great on the 2nd page that has the birds.

 

But, because you are required to select other product options on pages that host either hoodies, or t-shirts , this contribution does not work.

 

Can anyone here point me in the right direction to fix this?

 

I need all of my pages to behave exactly the same.

 

Let me know what you need from me. I'll gladly supply you with whatever you need...

 

( ps: do not bother to look at this site in IE6 - i'm not supporting it)

Link to comment
Share on other sites

  • 4 weeks later...

Hi all,

i have installed the contrib and its working ok, but i have another infobox (other than the shopping cart infobox) that show the total products in cart...

how can i make this infobox to also refresh when clicking in the buy now or add to cart buttons?

thanks in advance...

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

I have added this addon to our shop, but have a strange problem. When clicking on add to cart, sometimes the function works perfectly, and some othertimes, it just does not. What happens is that after clicking on add to cart, it shows the loading image, but does not further show the OK image or show the updated cart. In fact the item is added to the cart, but that can be seen first if the page is refreshed.

 

Can anyone help please?

 

Thanks in advance.

Link to comment
Share on other sites

  • 2 months later...
1. in /includes/column_right.php

<?php
.
.
.
if (COLUMN_RIGHT_IS_ON=='true') {
// BOF: SHOPPING_CART
 if (BOX_SHOPPING_CART_IS_ON=='true' and BOX_SHOPPING_CART_COLUMN=='right') {
?>
 <tr>
   <td style="padding: 0">
   <script language="JavaScript" src="includes/ajax_sc.js"></script>
	 <div id="divShoppingCard"><table border="0" width="100%" cellspacing="0" cellpadding="2"><?php  require(DIR_WS_BOXES . 'shopping_cart.php'); ?>
	 </table></div>
   </td>
 </tr>
<?php
 }
// EOF: SHOPPING_CART
.
.
.

 

2. in /includes/functions/html_output.php

<?php
.
.
.
// Ultimate SEO URLs v2.1
// The HTML href link wrapper function
if (SEO_ENABLED == 'true') { //run chemo's code
 function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
	global $seo_urls;
			if ( !is_object($seo_urls) ){
					if ( !class_exists('SEO_URL') ){
							include_once(DIR_WS_CLASSES . 'seo.class.php');
					}
					global $languages_id;
					$seo_urls = new SEO_URL($languages_id);
			}
// AJAX Addto shopping_cart - Begin
			$link_ajax = '';
			if( tep_not_null($parameters) && preg_match("/buy_now/i", $parameters) && $page != 'ajax_shopping_cart.php'){
			  $link_ajax = '" onclick="doBuyNowGet(\'' . tep_href_link( 'ajax_shopping_cart.php', $parameters, $connection, $add_session_id, $search_engine_safe) . '\'); return false;';
			}

	return $seo_urls->href_link($page, $parameters, $connection, $add_session_id) . $link_ajax;
// AJAX Addto shopping_cart - End
 }
} else { //run original code
// The HTML href link wrapper function
 function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
global $request_type, $session_started, $SID;

if (!tep_not_null($page)) {
  die('<br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
}

if ($connection == 'NONSSL') {
  $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
} elseif ($connection == 'SSL') {
  if (ENABLE_SSL == true) {
	$link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
  } else {
	$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
  }
} else {
  die('<br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
}

if (tep_not_null($parameters)) {
  $link .= $page . '?' . tep_output_string($parameters);
  $separator = '&';
} else {
  $link .= $page;
  $separator = '?';
}

while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);

// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
  if (tep_not_null($SID)) {
	$_sid = $SID;
  } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
	if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
	  $_sid = tep_session_name() . '=' . tep_session_id();
	}
  }
}

if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
  while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);

  $link = str_replace('?', '/', $link);
  $link = str_replace('&', '/', $link);
  $link = str_replace('=', '/', $link);

  $separator = '?';
}

if (isset($_sid)) {
  $link .= $separator . $_sid;
}

// AJAX Addto shopping_cart - Begin
		   $link_ajax = '';
		   if( tep_not_null($parameters) && preg_match("/buy_now/i", $parameters) && $page != 'ajax_shopping_cart.php'){
			 $link_ajax = '" onclick="doBuyNowGet(\'' . tep_href_link( 'ajax_shopping_cart.php', $parameters, $connection, $add_session_id, $search_engine_safe) . '\'); return false;';
		   }

		   return $link . $link_ajax;
// AJAX Addto shopping_cart - End
 }
}
.
.
.

 

Hi,

 

First i want to thanks for this great contribution, i was install in my store and it was working great, but now i have some problem.

 

I install " Ultimate_Seo_Urls_v2.6_(18 Aug 2008)" and now this contribution don't work, but if i disable ultimate seo , this contribution work again.

 

Anyone have some crue for my problem? Thanks for any help....

 

I Am sorry for my bad Inggris.

 

Best Regards,

 

IEA

Link to comment
Share on other sites

  • 2 months later...

Hello,

I am comming up with the same problem than the post before. I have Ultimate SEO2 installed and I really like the ajax buy now contribution.

 

Since I have seen many oscommerce site wich seem to work with both contributions I thought that there must be a solution out there.

 

How can I get both contributions to work together? I have spend hours looking for a solution.

 

Please help me. :rolleyes:

Or could someone please give me an alternative solution?

 

Thank you very much

Regards

Link to comment
Share on other sites

  • 4 weeks later...

QUESTION!!!!!!

 

I got this to work except for the flying effect, but this contribution is worth little if products can't be removed.

Since there is no second page how do we remove products, for example someone adds a product by mistake or changes his mind and wants to remove the

product from the cart. The contribution is a pice of art but can't do anything with it because it does not have a remove product option.

Edited by pallmall78
Link to comment
Share on other sites

  • 2 weeks later...

Hi there,

 

This is a wonderful contribution and I would love to get it to work on my highly modified site. I was wondering if this contribution works with the following mod on OSC v2.2 Rc2: Separate Price Per Customer and QT Pro

 

I added the contribution, but nothing is happening on my product info page...it continues to go to the shopping cart. I browsed through this entire thread and found no answer. I even have the Gzip compression set to false.

 

If anyone can take a look at my site that would be great. Let me know what I can give you so it would be easier for you to find the error.

 

http://cpboutique.com

 

Thank you!

Nora

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