Post by internet54 » Sun Oct 25, 2009 10:05 am

Hey,

I have my standard listing of the products on the manufactures page. All the products display correctly and I want to have an add to cart button under each one. This is the code I came up with and it works.

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product">
<input type="hidden" name="quantity" size="3" value="1" />
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span>Add to Cart</span></a>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />
</form>
My issue is that when I click add to cart on any of the items it only adds the 1st item on the category/manufacture page view. I have 12 products on the page and for each product I have the product_id value correct. When adding to the cart I don't have the ability to pick a different item to add because it seems that the form is submitting the first product_id it comes across.

Is there another piece of code I can add to fix this issue?

Thanks O0

New member

Posts

Joined
Sat Oct 10, 2009 3:53 am

Post by Qphoria » Sun Oct 25, 2009 8:52 pm

an id must be unique. You your <form id="product" so its finding the first instance of product.

1. Change id="product"
to id="product_<?php echo $j;?>"

2. change onclick="$('#product').submit();"
to onclick="$('#product_<?php echo $j;?>').submit();"

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by internet54 » Tue Oct 27, 2009 11:24 am

Thank you, worked great.

Now I'm off to work on the dropdowns on the manufactures and category pages.
O0

New member

Posts

Joined
Sat Oct 10, 2009 3:53 am

Post by benmckechnie » Wed Nov 25, 2009 6:04 pm

I'm trying to do just this - add an 'add to cart' button on the category page (i presume it is the same procedure as for the manufacturer page?). Can you tell me where i'd add this code?
I've only just found Opencart, but i guess the file would be 'catalog/controller/product/category.php' but where in that file? I've tried a couple of places but keep breaking it!!

Newbie

Posts

Joined
Wed Nov 25, 2009 5:57 pm

Post by Qphoria » Wed Nov 25, 2009 8:01 pm

benmckechnie wrote:but i guess the file would be 'catalog/controller/product/category.php'
That is the "code" file
you need the "view" file:
catalog/view/theme/YOURTHEME/template/product/category.tpl

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by benmckechnie » Thu Nov 26, 2009 2:09 am

Thanks, I've played a bit and got the button on the category listing, but when i click it to add a product to the cart it just loops back to the homepage. Any ideas on what i need to change - i'm guessing its something to do woth the 'onclick'?

Newbie

Posts

Joined
Wed Nov 25, 2009 5:57 pm

Post by internet54 » Sat Nov 28, 2009 3:55 am

Code: Select all

              <input type="hidden" name="quantity" size="3" value="1" />
              <a onclick="$('#product_<?php echo $j; ?>').submit();" id="add_to_cart" class="button"><span>Add to Cart</span></a></div>
            <input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />

New member

Posts

Joined
Sat Oct 10, 2009 3:53 am

Post by mohan » Thu Dec 24, 2009 7:44 am

can any one provide me how to add the add to cart button in the index or in the home page.i tired to insert a add to cart button in the home but im not getting the clear output. so can any one suggest me the answer by providing me the code.
it will be a great pleasure for me, if anyone helps me out.
my email address is : katti.lock@gmail.com
thanks in advance.
mohan

Newbie

Posts

Joined
Tue Dec 15, 2009 5:30 pm

Post by mohan » Tue Dec 29, 2009 12:08 pm

Can any one tell me, how to add a cart button in the home page and it should get added in the shopping cart list when i click on that cart button.
my mail id is katti.lock@gmail.com. Please if any one knows means please tel me the answer.

Newbie

Posts

Joined
Tue Dec 15, 2009 5:30 pm

Post by pravinbhat » Tue Dec 29, 2009 9:03 pm

Hi mohan here s de solution 4 ur question

Code: Select all

<?php echo $header; 
$indexed=0;
static $indexs;
?>
<?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content">
  <div class="top">
    <h1><?php echo $heading_title; ?></h1>
  </div>
  <div class="middle">
    <div><?php echo $welcome; ?></div>
    <div class="heading"><?php echo $text_latest; ?></div>
    <table class="list">
	
	
	
      <?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
      <tr>
        <?php for ($j = $i; $j < ($i + 4); $j++) { ?>
        <td style="width: 25%;"><?php if (isset($products[$j])) { ?>
          <a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a><br />
          <a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a><br />
          <span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br />
          <?php if ($display_price) { ?>
          <?php if (!$products[$j]['special']) { ?>
          <span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
          <?php } else { ?>
          <span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
          <?php } ?>
          <?php }?> 
<form action="index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">
                            </div>
							<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;">Qty:<input type="text" name="quantity" size="3" value="1" />
                <a href="index.php" onclick="$('#product_<?php echo $j;?>').submit();" id="add_to_cart" class="button"><span>Add to Cart</span></a></div>
				<input type="hidden" name="product_id" value='<?php
			  $conn=mysql_connect("localhost","root","");
mysql_select_db("cart");
$result=mysql_query("select product_id as pid from product order by product_id desc limit 8");
global $indexed;
while($res=mysql_fetch_array($result))
{
$pid[$indexed++]=$res['pid'];
} 
echo $pid[$indexs];
?>' />



<input type="hidden" name="redirect" value="index.php?route=product/product&product_id='<?php  
$conn=mysql_pconnect("localhost","root","");
mysql_select_db("cart");
$result=mysql_query("select product_id as pid from product order by product_id desc limit 2");
global $indexed;
while($res=mysql_fetch_array($result))
{
$pid[$indexed]=$res['pid'];
$indexed++;
} 

echo $pid[$indexs++];
mysql_close($conn); ?>'" />
            </form>


          <?php if ($products[$j]['rating']) { ?>
          <img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
		  
          <?php } ?>
          <?php } ?></td>
        <?php } ?>
      </tr>
      <?php } ?>
    </table>
  </div>
  
  
  <div class="bottom">&nbsp;</div>
</div>
<?php echo $footer; ?>

Newbie

Posts

Joined
Tue Dec 29, 2009 9:01 pm

Post by mohan » Wed Dec 30, 2009 2:58 pm

Thanks pravin,
Thanks a lot....

Newbie

Posts

Joined
Tue Dec 15, 2009 5:30 pm

Post by pravinbhat » Wed Dec 30, 2009 8:11 pm

111

Newbie

Posts

Joined
Tue Dec 29, 2009 9:01 pm

Post by pravinbhat » Wed Dec 30, 2009 8:15 pm

eadadad

Newbie

Posts

Joined
Tue Dec 29, 2009 9:01 pm

Post by huhitschris » Sun Jan 24, 2010 6:34 am

For those of you who might have a hard time figuring out how to code this functionality yourselves, I have a mod for OpenCart that will create an Add to Cart button for all pages with products listed and fully works with the AJAX Add to Cart feature. Please PM me if you are interested in purchasing a copy and I will be glad to help you install this feature into your store.

PM me for custom OpenCart template design and development.


New member

Posts

Joined
Wed Aug 19, 2009 3:12 pm

Post by pvtsales » Tue Mar 30, 2010 5:40 am

Is it possible to have an "add to cart" for all related products?

Version 1.4.4

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by pvtsales » Wed Mar 31, 2010 5:30 am

I've added:

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">

<div class="content"><?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product_<?php echo $j;?>').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />

</form>
in product.tpl. Go to checkout but don't add the related product.

Newbie

Posts

Joined
Sat Jan 16, 2010 1:50 am

Post by kunszun88 » Thu Apr 01, 2010 11:54 am

pvtsales wrote:I've added:

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">

<div class="content"><?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="1" />
<a onclick="$('#product_<?php echo $j;?>').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />

</form>
in product.tpl. Go to checkout but don't add the related product.
I've just added these code, but it doesn't work as i expected. because we have many button and the id of all are the same: id="add_to_cart", so only one button works. nothing happens when i click on other buttons.

how can i solve this problem??

Newbie

Posts

Joined
Tue Mar 09, 2010 11:20 am

Post by scottalanmcghee » Sat Feb 19, 2011 6:33 am

Try changing theis line of code:
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />
To the following:
<input type="hidden" name="product_id" value="<?php echo $products[$j]['product_id']; ?>" />


Posts

Joined
Sat Feb 19, 2011 6:30 am

Post by MrSmileyJr » Wed May 25, 2011 9:44 pm

What if I want to add "add to cart" buttons that will automatically add items to cart from another website (say wordpress):

Customer sees wordpress page w/ product description.

Clicks on Buy now.

Click takes him to opencart, with item inside cart.

Possible?

Never lose data again! Use Dropbox - DO THIS BEFORE YOU SIGNUP for Extra Space!!
http://db.tt/inKP3mv Signing up via this link gives you a bonus of 256 MB
More Bonuses: http://www.dropbox.com/free .5 GB
http://www.dropbox.com/edu = double your bonus referrals by giving an edu address.
Total ~ 3gb


New member

Posts

Joined
Fri Mar 11, 2011 5:07 am

Post by Jacqueline » Sun Aug 04, 2013 2:09 pm

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="product_<?php echo $j;?>">
<input type="hidden" name="quantity" size="3" value="1" />
<a onclick="$('#product_<?php echo $j;?>').submit();"id="add_to_cart" class="button"><span>Add to Cart</span></a>
<input type="hidden" name="product_id" value="<?php echo $products[$j]['id']; ?>" />
</form>
tried the following, it gave an error on top of the cart button not showing properly. Basically i have a long product description and i wanna add an ''add to cart'' button ....any html code to share? TIA O0

''Forbidden

You don't have permission to access /testsite/< on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.''

New member

Posts

Joined
Sun Jun 03, 2012 12:05 am
Who is online

Users browsing this forum: No registered users and 69 guests