F
F
Fortoo2021-11-30 02:00:11
opencart
Fortoo, 2021-11-30 02:00:11

Opencart cart disappears immediately after adding, why?

I add an item to my cart, the item is added to the mini cart, but when I go to the main cart, my cart is empty!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortoo, 2021-11-30
@Fortoo

I found this solution in the open spaces:
So, the problem is in your session in system/library/cart/cart.php
After logging in, the client class is initiated and the __construct.
on the file you can see how it works:line 22system/library/cart/cart.php

// this code queries the current cart of your session id. so before you were logged int, your cart was saved to the database under a session id.
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");

//after it finds your card products, it adds them to your CUSTOMER id.
foreach ($cart_query->rows as $cart) {
    $this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'");

    // The advantage of using $this->add is that it will check if the products already exist and increaser the quantity if necessary.
    $this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
}

So the reason your cart is not getting filled up after logging in is because in that session. Maybe some part of your code is deleting the $ this-> session-> getId (), so the script can't find the products in the cart.
To debug this just print_r, session_id and results like this
//print out the session id.
print_r($this->session->getId());
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");

//print out the result of the query
print_r($cart_query->rows);
foreach ($cart_query->rows as $cart) {
    $this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'");

    // The advantage of using $this->add is that it will check if the products already exist and increaser the quantity if necessary.
    $this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
}

to see what's there. if it's empty, you'll need to dig deeper to see who deletes it.
if it's full, visit the phpmyadmin oc_cart table to look for entries and try to figure out why it's not returning cart items. hope this helps. HOWEVER .... now I will tell (the author of the question). It's a good idea to look for a problem in sessions, so I'll share my experience. Indeed, when the session is lost, the basket disappears, in my case the problem was that the site on the hosting was configured according to the protocol , and the pages themselves could be opened using . Therefore, when sending goods to the basket, the protocol changed and what fell into the mini-basket eventually disappeared from the main basket. As a result, in the config I registered all connections throughsession_id=$this->session->getId()
https://wwwand configured редирект с www.site.com, на https://www.site.comin .htaccess and it all worked!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question