Post by AdieB » Thu Nov 07, 2019 7:11 pm

I have an HTML form inside a very customised Opencart v2.3.0.2 site.

Onsubmit, the form executes two JS functions.

1)myFunction2()adds a product and

submits the form data,

while routing to (`action="index.php?route=checkout/checkout"`)

I need to force the user to login if they are not already logged in before these two functions execute. So, I would want to add another JS function that forces login before executing the next two JS functions. Maybe there is an easier way.

Opencarts built-in function for checking if a user is logged is `$data['logged'] = $this->customer->isLogged();`

Form Submit

<button type="submit" class="btn btn-success btn-lg"><a id="addtocart" onclick="myFunction2(); myFunction()">Continue to Checkout</a></button>

JS Functions

function myFunction2() { //adds product to cart............

$.get( "index.php?route=checkout/cart/addToCart&product_id=30", function( data ) {
$( "#myForm" ).addClass( "product-added" );


function myFunction() { //submits form option with associated variables.........

if($( "#myForm" ).hasClass( "product-added" )){


So, Ideally to create a third JS function that executes first and checks if the user is logged. If user is logged continues with the second and third functions. If user is not logged "popup" with a login request, then once logged executes the second and third functions to checkout.

New member


Mon May 19, 2014 9:01 pm

Post by straightlight » Fri Dec 20, 2019 11:30 pm

It would be suggested to create a new service request in the Commercial Support section of the forum to get this done as a custom job.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

Straightlight Administrator / Quality Assurance Analyst / Programmer / Opencart Tester

Legendary Member


Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 19 guests