Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Changing add_to_cart form action


Mr. Ables

Recommended Posts

Hello,

I am working with osc v2.3.1, and have encountered a bit of an issue while trying to implement some changes to product_info.php. I am using OSC as an info site, i.e. there are no customer accounts and no shopping cart. Instead, the idea is to use it as a consignment shop: we host the items on our website and allow customers to contact the seller directly.

 

I have not had any issues with removing the Add to Cart/Account functions and links, however, I am in the process of creating a ReCAPTCHA button, Contact Seller, on the product_info.php page and discovered that nearly the entire page is already a <form> for the original Add to Cart buttons, which leads to the shopping cart page. I need to change the action on this form so that it no longer leads to the Shopping Cart page, but instead, upon correct input of the ReCAPTCHA code, displays the (otherwise) hidden Seller's contact information.

 

I certainly do not expect someone to code this all in it's entirety for me, however is it possible to change/remove the original add_to_cart form without causing any major problems? If so, how can this be done?

 

Thank you in advance for the help.

Link to comment
Share on other sites

Perhaps I can simplify my question:

 

How are forms handled in OSC 2.3.1? In product_info.php, the form is drawn with the following line:

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?>

 

I need to change the form action or remove of this form entirely to add another, as I cannot nest another form inside. If I needed to create a form, below the product description, that did something entirely different, what can I change? Would this cause any problems? Since I have removed of all of the buttons, does that mean I can terminate the form sooner? Where does it define what "cart_quantity" or "add_product" are?

 

I am obviously not, by any means, a PHP expert so help with any of these questions or just a direction to go would be extremely helpful.

Link to comment
Share on other sites

Why not just change the action of the existing form? Then it's a simple matter of adding another action in application_top.php to process your captcha and return the data.

 

Regards

Jim

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

Link to comment
Share on other sites

Jim,

Thank you very much for the help. I wasn't aware that the form was processed with application_top.php (as I said, I only have working knowledge of PHP, but this is a wonderful way to learn), so that should lead me in the correct direction. In application_top, would I then be able to display information (i.e. a specific Seller's contact info) based on the $products_id?

 

Would something simple like this work?:

switch ($product_info['products_id']) {
  case 29:
  case 30:
  case 31:
  echo ("Seller info");
 break;
 default:
}

OR



if ($product_info['products_id'] == 29) echo ("Seller info");

 

Thank you again for the help. I appreciate any recommendations.

Link to comment
Share on other sites

How is the seller tied to the product ID? Your database architecture is critical to figuring this part out. Do you have a table with seller info, and another table that relates the seller table to the Product ID? That's how I would design it, but I don't know what you've done. If you did it my way, the the code in application_top.php would use the newt tables to look up the seller info and pass it back to be displayed. Or possibly pass it to a new PHP file, such as a popup.

 

If you're good with Javascript, you could us a Javascript popup to display the data over the product page. So many possibilities here....

 

Regards

Jim

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

Link to comment
Share on other sites

Jim,

A JavaScript popup would be a nice way to do this, and I am much more experienced with JavaScript. The seller is not currently tied to the product ID in any way, as I did not know the best way to go about this. A database would likely be the most elegant and effective way to make this work, as I would otherwise have to manually enter the sellers info into the script manually every time a new product was added.

 

So the best way to go about this would be: ReCAPTCHA would be processed with application_top. If ReCAPTCHA was correct, application_top would look up the seller info via these tables, one that contains the sellers info and one that ties products_id to sellers_id. Then application_top would pass info that to a new page, which would display, in a popup the sellers info based on the original products_id. Correct? My only, probably stupid, question is (despite what I'm sure will be the daunting task of figuring out the syntax), how would I tie in the JavaScript Popup to this button? I know I can redirect via the action, but can I use a popup there instead?

 

Now it's just figuring out the syntax, I suppose ;) Thanks again for the ideas, Jim

Link to comment
Share on other sites

I was just throwing ideas out there. Now, how to make it work ... Could you retrieve the seller information with the original page load but not make it visible until the captcha is processed? Use Javascript to do all of the processing so you don't need to reload. Or would the data show up in the page source? Maybe this would require an AJAX-style call to get the data?

 

It would be easier to just pass the form back to the server, retrieve the data, and display a popup that way. Not as pretty, but simple to code.

 

Regards

Jim

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

Link to comment
Share on other sites

If I use JavaScript alone to pull the data it would definitely require AJAX. If I pulled the seller info at the top of product_info I believe it would be visible via the source, but because of the complexity of this code and the fact that my boss is hounding me daily to finish this project (because HE already sold many slots on this site) I'm thinking that as long as no one can tell that their information is accessible and it looks as though CAPTCHA blocks bots then who cares if it really works :P.

 

The only way I can think to do it would require a reload or a popup, otherwise the code would be visible in the source. If I made the pop_up process the form and pull the info from the database, would I need to use application_top at all?

Link to comment
Share on other sites

You don't have to use application_top, but that's where all of the action logic currently resides. Ripping that out is extra work for no real gain. Making major changes to osCommerce requires an understanding of the entire system. There's code in there to manage a lot of different processes from different sources. Removing it might impact something else that you still want to use. I would leave it alone and just add to it.

 

If you're doing everything in the popup, doesn't that add an extra step? Click once to get the popup, then again to submit the form. I would stay with a single form. Every click that you add to the process will cost you sales.

 

Regards

Jim

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

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...