Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add to Cart Link from html page


azrith

Recommended Posts

Hi,

 

I am fairly new to OS Commerce. I have an html page setup and I want to create "add to cart" links for products so that they will be added to the OS Commerce cart. Any help to some documentation or some sample code would be great. The HTML page is located in the root and the OSC is located in /shopping/

 

Thanks.

 

Bob

Link to comment
Share on other sites

Ive found this code in an old forum:

<form name="buy_now" id="buy_now" action="<?php print FILENAME_PRODUCT_INFO . '?action=add_product'; ?>" method="post">

<input type="hidden" name="id[1]" id="id[1]" value="1"> <!-- if you want an option to be added this would be the option id and it's value -->

<input type="hidden" name="products_id" id="products_id" value="<?php print $product_info['products_id']; ?>"> <!-- this is the product id... it can be static or it could be a variable -->

</form>

 

I tried it but it isn't working. Anyone know how to fix it?

 

 

Thanks.

Link to comment
Share on other sites

ALL RIGHT!!! FINALLY AFTER HOURS I FIGURED THIS OUT.

A special thanks goes to . . . ME

This is a quick fix to create an Add to Cart button on an html page you may have. This will add the item directly to the cart.

1) Paste this code in the top of your page (above <html>)

<?php require('includes/application_top.php');?>

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

 

2) Paste this below </html>

</form>

 

3) Now paste this where you want your button: (NOTE - 28 was the product ID wanted replace this with your product id)

<?php echo tep_draw_hidden_field('products_id', 28) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></a></b></font></p>

4) Now you are going to have to place this item in your root of the shop folder. Mine was /shopping/. Since you are doing this all links will needed to be changed depending upon how you have your directoy system set up.

5) rename the html file to .php

6) Try it!

 

Im sure there is probably a better way to do this but . . .Ive spent enough time on this and it works so . . .

 

TT

Bob

Link to comment
Share on other sites

  • 2 weeks later...

This sounds up my street, but I can't get it to work, though I've possibly missed something!

 

Here's my interpretation of the above instructions.

 

Can anyone who has got their page working, advise where I've gone wrong with a correction please?

 

 

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

<html>

<head>
</head>
<body>

<form name="buy_now" id="buy_now" action="<?php print FILENAME_PRODUCT_INFO . '?action=add_product'; ?>" method="post">
<input type="hidden" name="id[1]" id="id[1]" value="1"> 

<input type="hidden" name="products_id" id="products_id" value="<?php print $product_info['products_id']; ?>"> 

</body>
</html>
</form>

____________________________________________________________________

____________________________________________________________________

Link to comment
Share on other sites

hi

how do you find out what the product id is for the item?

cheerz

I found mine by going to the store, find the product, get to the page where this item is the only one on the page. Then look at the end of your URL, you will see it.

 

Good luck!

 

BK

Link to comment
Share on other sites

<form name="buy_now" id="buy_now" action="<?php print FILENAME_PRODUCT_INFO . '?action=add_product'; ?>" method="post">

<input type="hidden" name="id[1]" id="id[1]" value="1">

 

<input type="hidden" name="products_id" id="products_id" value="<?php print $product_info['products_id']; ?>">

 

</form>

[/code]

Steve,

 

The OSCommerce code is very complicated to me, so I usually change similar code to make mine work.

 

Instead of what you wrote (made more sense when you actually wrote the code at the post distination), here is what I have in between the <form> tag.

 

<?php echo tep_draw_hidden_field('products_id', $my_pid) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

 

This displays button and adds item to cart.

 

Hope this helps...

Link to comment
Share on other sites

Hi bijink,

 

Thanks for your help.

 

I've now got the button to show and it takes me to an empty cart! So what do I need to do, to add a product (description and price)?

 

My present page looks like...

 

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

<html>
<head>
</head>
<body>

<form name="buy_now" id="buy_now" action="<?php print FILENAME_PRODUCT_INFO . '?action=add_product'; ?>" method="post">
<input type="hidden" name="id[1]" id="id[1]" value="1">
<input type="hidden" name="products_id" id="products_id" value="<?php print $product_info['products_id']; ?>">

<?php echo tep_draw_hidden_field('products_id', $my_pid) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

</body>
</html>
</form>

Thanks

 

Steve

____________________________________________________________________

____________________________________________________________________

Link to comment
Share on other sites

For these codes,

 

<form name="buy_now" id="buy_now" action="<?php print FILENAME_PRODUCT_INFO . '?action=add_product'; ?>" method="post">

<input type="hidden" name="id[1]" id="id[1]" value="1">

<input type="hidden" name="products_id" id="products_id" value="<?php print $product_info['products_id']; ?>">

 

Change to,

<form>

 

---- ----

 

tep_draw_hidden_field(), tep_image_submit are some mysterious functions that make things work. We don't need to write out <input> tags at all.

 

Make sure $my_pid in <?php echo tep_draw_hidden_field('products_id', $feature_pid) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> has the correct product id number.

 

May your cart no longer be empty!

 

BK

Link to comment
Share on other sites

</body>

</html>

</form>

 

 

I think it should be written this way :

 

</form>

</body>

</html>

 

As far as I know, normally the forms should be inside the body of the document. But in any case, all the information should be inside the html. When you write "</html>", you are closing the document, so I guess that writing after "</form>" is useless because it won't be readen, so the form won't be closed.

 

I didn't try it but I guess it might be that. Give it a try ;)

Link to comment
Share on other sites

  • 1 month later...

I had a question that builds off of this topic. I want to add an "Add to Cart" button to my custom product page, but instead of just assuming that a quantity of one should be added, i would like to have a text field that allows the customer to enter how many they would like to purchase. I know this can be done because on the MyCart page it shows all your items with a box next to them to update quantities, I would just prefer to have this option on the product's page as well. However, I can't seem to figure out how to get this option to work. Any ideas would be greatly appreciated. Thanks!

 

~Zach

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...