Jump to content
Sign in to follow this  
azer

Ajax Buy Now

Recommended Posts

To Medreces,

 

I just realized that what you provided is not what I was asking.

My problem is the AJAX Buy Now mod not working when a product quantity field is added the product_info.php.

Product listing is fine, I don't use the ajax or quantity mod there.

Edited by pixclinic

Share this post


Link to post
Share on other sites
2 pixclinic

It is much easier!

See 2dn version from 23 Nov 2005

 

???

 

what you are refering to is a mod in the product LISTING file. I don't need that: I need a MOD in the product INFO file that doesn't affect the AJAX BUY NOW.

 

Did I miss something? :-)

Share this post


Link to post
Share on other sites
Additional Bit for Product Info dreaminggates 23 Nov 2005

 

Please excuse me, as this is my -very- first bit of PHP tweaking, but I discovered a way to use this same code to put a quantity box on the Product Info page as well.

 

Just open:

 

/catalog/product_info.php

(or the root dir of wherever you installed osc)

 

 

 

and where it says:

 

<td class="main" align="right"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>

 

 

 

simply insert a snippet of code from this contribution so it looks like:

 

<td class="main" align="right"><?php echo '<b>Qty:</b> <input type="text" name="quantity" value="1" maxlength="5" size="5">' . tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>

 

 

 

Important: You must have this contribution already installed for this to work! The attached zip does NOT include the original contribution, only my bit.

 

Please test this after backing up your system, and forgive me for bugs. I have tested it thoroughly on my installation and it works well, but again... PHP is very new to me.

 

Thank you and take care.

~Kyr

 

:D

Share this post


Link to post
Share on other sites
:D

 

sorry but this mod dosn't : the "wheel" turns, the green checkmark shows up, but the shopping cart is not filled :-(

aI added the code above and modified the application_top php

Share this post


Link to post
Share on other sites

On my test script all right.

Write, what you did?

Or give me ftp-access for testing your site (log/pass in PM)

Share this post


Link to post
Share on other sites
On my test script all right.

Write, what you did?

Or give me ftp-access for testing your site (log/pass in PM)

 

what I did:

in product-info.php: installed the input field as indicated above

in application_top.php: replaced the +1 by +$quantity

 

 

the site:

www.thefrenchybee.com

 

the product_info.php code:

http://www.thefrenchybee.com/__product_info.txt

 

the application top code:

http://www.thefrenchybee.com/__application_top.txt

 

the ajax java script:

http://www.thefrenchybee.com/ajax.js

 

PLEASE NOTE THESE FILES are the ones WITHOUT the suggested mod

 

let me know if you need more files. I can;t provide FTP, the site is in production

 

Thanks

Share this post


Link to post
Share on other sites
To Medreces,

 

I just realized that what you provided is not what I was asking.

My problem is the AJAX Buy Now mod not working when a product quantity field is added the product_info.php.

Product listing is fine, I don't use the ajax or quantity mod there.

 

where are you adding ajax?

 

In the cart there should be "add to cart" buttons (and if you made the mods, that should be able to pass a quantity).

 

ajax buy now should ONLY affect the "buy now" buttons, which show up in product_listing and product_listing_col from includes/modules calls.

 

product_info.php should NOT be affected by these unless you are displaying "buy now" buttons there, and I would recomend that if you are, you change them to "add to cart" buttons that pass in the quantity as well.

 

This method of installing ajax keeps the site very clean.


The king of kluge...

? Do you really know what is and isn't working in your store? ≡ ?

Share this post


Link to post
Share on other sites
where are you adding ajax?

 

In the cart there should be "add to cart" buttons (and if you made the mods, that should be able to pass a quantity).

 

ajax buy now should ONLY affect the "buy now" buttons, which show up in product_listing and product_listing_col from includes/modules calls.

 

product_info.php should NOT be affected by these unless you are displaying "buy now" buttons there, and I would recomend that if you are, you change them to "add to cart" buttons that pass in the quantity as well.

 

This method of installing ajax keeps the site very clean.

 

I just realized that I might not be in the right forum, haha!

 

I'm talking about the PRODUCT INFO PAGE, with an ajax "add to cart" button. How to make it work with a quantity field there?

 

for example:http://www.thefrenchybee.com/pre-de-provence-7-x-25g-olive-oil-guest-soaps-in-gift-box-honey-pollen-lavender-p-486.html

Share this post


Link to post
Share on other sites

2 pixclinic:

 

in product_info.php uncomment line 222:

				 <!-- <td class="main" align="right" width="50"> x <input type="text" name="quantity" value="1" maxlenght="2" size="2"></td> -->

 

in application_top.php find line 373:

								$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);

 

and replace it by:

								$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+($HTTP_POST_VARS['quantity']>0?$HTTP_POST_VARS['quantity']:1), $HTTP_POST_VARS['id']);

 

This should work.

 

2 Met00:

 

This contribut v2.0 already works with the forms in which "action=add_product" and consequently with "add to cart" buttons.

Example: www.vashop.ru

 

regards

Share this post


Link to post
Share on other sites

Well done :-) Thank you so much for this. I really appreciate your help (that was not easy!)

 

Greetings to Russia ;-)

Share this post


Link to post
Share on other sites
2 Met00:

 

This contribut v2.0 already works with the forms in which "action=add_product" and consequently with "add to cart" buttons.

Example: www.vashop.ru

 

regards

 

I'm not saying that it shoudn't I just question the wisdom. I like bringing people to the cart, my partner prefers not to. The only thing "saved" is a page refresh if you are not going to the cart. Since a page refresh will refresh a number of other components on the page (specials, also purchased <modified version that picks up all the also purchased and does a random display>, cross-sell <modified, as per the also purchased>, etc.) which would be lost by using ajax, I don't see the upside. But that's just me. :-)


The king of kluge...

? Do you really know what is and isn't working in your store? ≡ ?

Share this post


Link to post
Share on other sites

Hi Medreces,

 

Your contribution is great, but I cannot make it work with the Ultimate SEO URL on my website.

Is it possible that you can show me how to change it to running with the ultimate SEO URL?

 

tony :(

Share this post


Link to post
Share on other sites
Hi Medreces,

 

Your contribution is great, but I cannot make it work with the Ultimate SEO URL on my website.

Is it possible that you can show me how to change it to running with the ultimate SEO URL?

 

tony :(

Hi Tony?

 

All must work.

Show me your web-site.

Share this post


Link to post
Share on other sites

Medreces,

 

thank you for your reply. my website is http://www.monstech.com

here are part of the code that i don't know how to change it. if you need to view whole file, please let me know how can i send it to you.

 

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') {
require(DIR_WS_BOXES . 'shopping_cart.php');
 }
// EOF: SHOPPING_CART
.
.
.

 

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);
			}
	return $seo_urls->href_link($page, $parameters, $connection, $add_session_id);
 }
} 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;
}

return $link;
 }
}
.
.
.

 

Thx

Tony :blush:

Share this post


Link to post
Share on other sites

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

Edited by Medreces

Share this post


Link to post
Share on other sites

Hi Medreces,

 

Thank you for your help! it is working now.

btw, I refered to your previous posted code to change the "return $link;" section.

I also added your code at the following parts.

hope you can spend some more time to help me verify it, in case, i did something wrong.

 

in /includes/functions/html_output.php

// Output a form
 function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
$form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';

if (tep_not_null($parameters)) $form .= ' ' . $parameters;

[color=#CC0000] // AJAX Addto shopping_cart - Begin[/color]
if( preg_match("/add_product/i", $action) ){
  $form .= ' onSubmit="doAddProduct(this); return false;"';
}
[color=#CC0000]  // AJAX Addto shopping_cart - End[/color]
$form .= '>';
return $form;
 }

 

////
// Output a form input field
 function tep_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
$field = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {
  $field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';
} elseif (tep_not_null($value)) {
  $field .= ' value="' . tep_output_string($value) . '"';
}

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

[color=#CC0000]  // AJAX Addto shopping_cart - Begin[/color]
if( preg_match("/add_product/i", $action) ){
  $form .= ' onSubmit="doAddProduct(this); return false;"';
}
[color=#FF0000]  // AJAX Addto shopping_cart - End[/color]
$field .= '>';
return $field;
 }

 

// Output a form textarea field
 function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {
$field = '<textarea name="' . tep_output_string($name) . '" wrap="' . tep_output_string($wrap) . '" cols="' . tep_output_string($width) . '" rows="' . tep_output_string($height) . '"';

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

[color=#CC0000]  // AJAX Addto shopping_cart - Begin[/color]
if( preg_match("/add_product/i", $action) ){
  $form .= ' onSubmit="doAddProduct(this); return false;"';
}
[color=#CC0000]  // AJAX Addto shopping_cart - End[/color]
$field .= '>';

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {
  $field .= tep_output_string_protected(stripslashes($GLOBALS[$name]));
} elseif (tep_not_null($text)) {
  $field .= tep_output_string_protected($text);
}

$field .= '</textarea>';

return $field;
 }

 

////
// Output a form hidden field
 function tep_draw_hidden_field($name, $value = '', $parameters = '') {
$field = '<input type="hidden" name="' . tep_output_string($name) . '"';

if (tep_not_null($value)) {
  $field .= ' value="' . tep_output_string($value) . '"';
} elseif (isset($GLOBALS[$name])) {
  $field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';
}

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

[color=#CC0000]  // AJAX Addto shopping_cart - Begin[/color]
if( preg_match("/add_product/i", $action) ){
  $form .= ' onSubmit="doAddProduct(this); return false;"';
}
[color=#CC0000]  // AJAX Addto shopping_cart - End[/color]
$field .= '>';
return $field;
 }

 

////
// Output a form pull down menu
 function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
$field = '<select name="' . tep_output_string($name) . '"';

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

[color=#CC0000]  // AJAX Addto shopping_cart - Begin[/color]
if( preg_match("/add_product/i", $action) ){
  $form .= ' onSubmit="doAddProduct(this); return false;"';
}
[color=#CC0000]  // AJAX Addto shopping_cart - End[/color]
$field .= '>';

if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);

for ($i=0, $n=sizeof($values); $i<$n; $i++) {
  $field .= '<option value="' . tep_output_string($values[$i]['id']) . '"';
  if ($default == $values[$i]['id']) {
	$field .= ' SELECTED';
  }

  $field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>';
}
$field .= '</select>';

if ($required == true) $field .= TEXT_FIELD_REQUIRED;

return $field;
 }

 

Tony:)

Share this post


Link to post
Share on other sites

Sorry, i tried to higlight your code on the file but not working.

please ignored the " ................" when you read it.

:'(

Share this post


Link to post
Share on other sites

2 Tony:

Changes which you have done in the following functions tep_draw_input_field, tep_draw_textarea_field, tep_draw_hidden_field, tep_draw_pull_down_menu absolutely unusefull but they are not harmful.

Please follow the istallation instructions (readme.txt)

Share this post


Link to post
Share on other sites

Medreces,

 

Thank you so much! I really appreciate your help.

Maybe you should mentioned that your code also working with the Ultimate SEO URL.

Because there are many people using the Ultimate SEO URL with OSC.

anyway, Thanks again....LOL

 

TONY :thumbsup:

Share this post


Link to post
Share on other sites

HI there! Thx Medreces for this so interesting contribution. I'm here to ask for hel cause i'm trying to integrate this mod with my site (www.drako.it) which use a lot of other mod, like "B2B" and "Product Listening in Column" and a lot of self made mod but without any luck...

 

I've read other members post and i've tryed some of the modifies proposed, but seems no one did the trick...

 

The problem is that with the contrib installed i see the "rotating arrow" but i never see the "green flag". If i do a manual refresh the Shopping Cart is right, with the added products, but the ajax mod is not working properly.

 

Any hints please?


my contribution: Alex's Contributions

Share this post


Link to post
Share on other sites

Hi, Drako!

 

The work of the mode is consists of 3 steps:

1. the preparation of l datas in brouser and sending of the request on server

2.datas are processing on the server by the standard style of osCOMMERCE and the answer is sending to brouser

3. after getting the answer from server shows it

I think that in your case the 3rd step is not working.

Please have a look how do you put the server's answer on the page.

 

Luck!

Share this post


Link to post
Share on other sites
Hi, Drako!

 

The work of the mode is consists of 3 steps:

1. the preparation of l datas in brouser and sending of the request on server

2.datas are processing on the server by the standard style of osCOMMERCE and the answer is sending to brouser

3. after getting the answer from server shows it

I think that in your case the 3rd step is not working.

Please have a look how do you put the server's answer on the page.

 

Luck!

 

 

Thank a lot for the hints! I'm going to work on it immediatly! Do you know exatly wich files are included in the 3 point?

 

That's too much of a good contribution not using it, a lot of reload saved!

Edited by Drako

my contribution: Alex's Contributions

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  

×