Post by heane33 » Wed May 09, 2018 6:14 am

Hi, I previously had code in place which was working great. Basically, I had a custom index page designed how I wanted and code for the 'Add to Cart' button on this page that linked directly to the OpenCart checkout. This was in OpenCart version 2.x. Since I've upgrade to 3.x, the code no longer works. I'm assuming some tweaks need to be made to make it work in 3.x?

Here was the code I was using in 2.x

-------------------------
Code for Add to Cart button:
<div class="add-single" onclick="cart.add('50', '1');"></div>
-------------------------
Script within Body tags:
<script>
var cart = {
'add': function(product_id, quantity) {
$.ajax({
url: 'https://mydomain.com/index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
// $('#cart > button').button('loading');
},
complete: function() {
//$('#cart > button').button('reset');
},
success: function(json) {
//$('.alert, .text-danger').remove();

if (json['redirect']) {
location = json['redirect'];
exit;
}
}
});
}
}
</script>
-------------------------
Is there some slight tweak to make this work in the new version of open cart 3.x?

Thanks in advance.

Newbie

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by heane33 » Wed May 09, 2018 6:25 am

Tinkered with it and got it working! Looks like I just had to re-enable my modifications on the Modifications page. Guess they were defaulted to Off after the install.

After I did that, the existing code works!

Newbie

Posts

Joined
Thu Aug 11, 2016 6:24 am

Post by kestas » Wed May 09, 2018 6:29 am

After installing some extension you always must refresh modifications.

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here and here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am
Who is online

Users browsing this forum: No registered users and 6 guests