Page 1 of 1
Add To Cart
Posted: Wed Mar 09, 2016 3:06 am
by danguz74
Hi,
This should be an easy question. How do I create a button to add a specific product to the cart from a custom page?
Thanks!
Re: Add To Cart
Posted: Wed Mar 09, 2016 3:32 am
by ocart777
if you have a list of product ready on your custom page, put below code inside the foreach loop of products inside your tpl
Code: Select all
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i></button>
Re: Add To Cart
Posted: Wed Mar 09, 2016 4:03 am
by danguz74
Thanks!
I added an "onclick='cart.add(54)'" to my link and it doesn't seem to be working. Am I missing something?
Re: Add To Cart
Posted: Wed Mar 09, 2016 5:05 am
by danguz74
I changed it to cart.add("53", "1") and it still doesn't work.
I run the command in the console and get the following error.
Uncaught Error: cannot call methods on button prior to initialization; attempted to call method 'loading'(…)
Thanks for any help!
Re: Add To Cart
Posted: Wed Mar 09, 2016 5:16 am
by Randem
Hi danguz74,
Is this something you are looking for?
Add: Ability to add products to OpenCart shopping cart from your website to aid in a better customer experience - 20160206 - v1.12
If so, it is part of a larger group of fixes for v2.1.0.x -
http://www.randemsystems.com/support/op ... n-2-1-0-1/
Re: Add To Cart
Posted: Wed Mar 09, 2016 11:12 am
by ocart777
danguz74 wrote:Thanks!
I added an "onclick='cart.add(54)'" to my link and it doesn't seem to be working. Am I missing something?
do you have common.js included from "catalog\view\javascript" ?