Post by scottyboyyy » Mon Apr 10, 2017 7:08 pm

I am trying to make the cart update on load on a completely custom and separate to the admin userface .html page.

To make this page I have copied the generated product source code produced by the admin userface and product.tpl and pasted the source code into my custom product .html page.

The carts values update when a button is clicked to the correct value. However on refresh it goes back to the defined forced value which in this example is *6 item(s) - £28.55* from the following html code:

Code: Select all

   <button type="button" data-toggle="dropdown" data-loading-text="Loading..."
     class="btn btn-inverse btn-block btn-lg dropdown-toggle"><i class="fa fa-shopping-cart"></i>
     <span id="cart-total">6 item(s) - £28.55</span></button>
The value needed is currently generated on click with javascript - when the add to cart button is clicked the cart is then updated to the correct value from this code:

Code: Select all

   <script type="text/javascript">
    $('#button-cart').on('click', function() {
    	$.ajax({
    		url: 'index.php?route=checkout/cart/add',
    		type: 'post',
    		data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
    		dataType: 'json',
    		beforeSend: function() {
    			$('#button-cart').button('loading');
    		},
    		complete: function() {
    			$('#button-cart').button('reset');
    		},
    		success: function(json) {
    			$('.alert, .text-danger').remove();
    			$('.form-group').removeClass('has-error');
    
    			if (json['success']) {
    				$('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
    
    				$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
    
    				$('html, body').animate({ scrollTop: 0 }, 'slow');
    
    				$('#cart > ul').load('index.php?route=common/cart/info ul li');
    			}
    		},
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
    	});
    });
    //--></script>
The only issue is on page refresh resetting to the preset value. I have attempted using window.onload = function {} to reset the value on page load but this gives me a blank value. Has anyone managed to do it this way?

Is it possible to get the value another way onto a custom html page?

Many thanks!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by thekrotek » Mon Apr 10, 2017 8:37 pm

You need to save the value in session or cookie, when it changes. Then read it from cookie or session and display on page load. If value doesn't exist - display default.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am

Who is online

Users browsing this forum: No registered users and 336 guests