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

2)myFunction()
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" )){
document.getElementById("myForm").submit();
}

}

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

Posts

Joined
Mon May 19, 2014 9:01 pm
Who is online

Users browsing this forum: No registered users and 30 guests