Post by danguz74 » Wed Mar 09, 2016 3:06 am

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!

Newbie

Posts

Joined
Wed Feb 24, 2016 12:45 am

Post by ocart777 » Wed Mar 09, 2016 3:32 am

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>

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by danguz74 » Wed Mar 09, 2016 4:03 am

Thanks!
I added an "onclick='cart.add(54)'" to my link and it doesn't seem to be working. Am I missing something?

Newbie

Posts

Joined
Wed Feb 24, 2016 12:45 am

Post by danguz74 » Wed Mar 09, 2016 5:05 am

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!

Newbie

Posts

Joined
Wed Feb 24, 2016 12:45 am

Post by Randem » Wed Mar 09, 2016 5:16 am

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/

NEVER take serious; anyone who gives negative impact statements with no ABSOLUTE proof!
OpenCart Helpful Information * Upgrade 1.5 to 2.1 * Upgrade 2.1 to 2.2
"Why do people NEVER have enough time to do it right but ALWAYS enough time to do it over?"
DO NOT EVER GIVE SOMEONE YOU DON"T KNOW ADMIN ACCESS TO ANYTHING!
I am NOT affiliated with OpenCart


User avatar
Active Member

Posts

Joined
Sat Sep 27, 2014 9:17 am

Post by ocart777 » Wed Mar 09, 2016 11:12 am

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" ?

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia
Who is online

Users browsing this forum: No registered users and 15 guests