Opencart Пустая корзина Проблема при входе на сайт - PullRequest
0 голосов
/ 28 мая 2019

Я добавляю продукт в корзину, но моя проблема начинается, когда я захожу на сайт, моя корзина пуста

1 Ответ

0 голосов
/ 29 мая 2019

Так что проблема с вашей сессией в system/library/cart/cart.php

После того, как вы вошли в систему, инициируется класс клиента и запускается метод __construct.

на line 22 файла system/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']);
}

Таким образом, причина, по которой вы не заполняете свою корзину после входа, заключается в том, что в этом сеансе Возможно, какая-то часть вашего кода удаляет $ this-> session-> getId (), поэтому скрипт не может найти товары в корзине.

Чтобы отладить это просто print_r session_id и результаты, подобные этому

//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']);
}

чтобы увидеть, что там. если он пуст, вам нужно будет копать глубже, чтобы увидеть, кто его удаляет.

если он заполнен, зайдите в таблицу phpmyadmin oc_cart, чтобы найти записи session_id=$this->session->getId() и попытаться выяснить, почему он не возвращает товары корзины.

надеюсь, это поможет.

...