Opencart | Redirect to checkout success message

67 Views Asked by At

I'm using opencart V4. I have new custom order controller. When an user click the create order button, It should create order and redirect to success page.

Problem

Now I'm able to create order successfully but not able to redirect to success page. It is redirecting index page. with url like this www.domain.com/index.php?

Order twig file:

     $.ajax({
            type: 'POST', // Use 'POST' to send data to the server
            url: 'index.php?route=quickorder/create', // Adjust the URL to your controller
            data: orderData, // Include the payload data
            success: function(response) {
                alert(response);
                // Handle the response from the server
                if (response.success) {
                    // Display a success message to the user (customize this)
                    alert('Custom order created successfully!');
                } else {
                    // Handle errors if necessary
                    alert(response);
                }
            },
            error: function() {
                alert('error');
                // Handle AJAX errors
                alert('An error occurred while creating the custom order.');
            }
        });

Controller file

  $order_id = $this->model_checkout_order->addOrder($order_data);

                if ($order_id) {
                    $this->session->data['success'] = 'Your custom order has been successfully created!';
                    $this->session->data['order_id'] =  $order_id;
                  $this->response->redirect($this->url->link('checkout/success'));
            }

Order is creating successfully but not able to redirect checkout/success.

alert(response); also not working. It redirects to index.php?

0

There are 0 best solutions below