Home » Php » php – Rebuild checkout page in opencart on passing registered email as querystring to checkout/cart

php – Rebuild checkout page in opencart on passing registered email as querystring to checkout/cart

Posted by: admin July 12, 2020 Leave a comment


I have a requirement to rebuild checkout page, containing latest abandoned products.

If you are already logged into opencart consumer site and hit this url – http://www.example.com/index.php?route=checkout/cart, it will definitely list all products in cart ( that are yet to be purchased).

Without logging into consumer website, if someone directly hits this url – http://www.example.com/index.php?route=checkout/cart&[email protected] – it will list all products that are yet to be purchased by [email protected] (also known as abandoned products/cart), provided [email protected] is a registered user of opencart website.

I want to pass that email address from the url as a querystring to the checkout/cart page and use that to return abandoned products for that customer email.

How can I take that email in checkout/cart page and show the user the abandoned cart products?

I am very much new to opencart, i don’t know much about core functionality, so i searched how to achieve this, but landed with extensions ( such as THIS) that are paid, my requirement is to have it build within URL, that i explained above.

Provided : Opencart installation is a stock version, no other addon/plugins are installed.


I have tried following.

    $email = $this->request->get['email']; 
    $cart_details = $this->db->query("SELECT cart FROM " . DB_PREFIX . "customer c where c.email = '" . $email . "'"); // just for tesing, i will fix this to prevent SQL injection.
    $this->session->data['cart']= $cart_details->row['cart']; 

when i do echo with "$cart_details->row['cart']", it got required value, but even after setting that value to session checkout page is not rebuilding list of abandoned products.

How to&Answers:

I have changed checkout/controller/checkout/cart.php index method, and added a check to see if the custom url contains “cmail”. Then I validate the email address supplied in the url. At this point, I query the DB to get the customer’s “cart” column ( note i have used escape to prevent SQL injection), which is then decoded and put into session. If you hit the site with the url “localhost/index.php?route=checkout/cart&[email protected]”, you will get the cart rebuilt in the page. I have used following code.

    $email = $this->request->get['cmail'];  
    if(filter_var($email, FILTER_VALIDATE_EMAIL))
        $cart_details = $this->db->query("SELECT cart,customer_id FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");

         if($cart_details->num_rows > 0)
             $cart_data = $cart_details->row['cart'];
             if ($cart_data && is_string($cart_data)) {
                 $cart = unserialize($cart_data);

                 foreach ($cart as $key => $value) {
                    $this->session->data['cart'][$key] = $value;