S
S
skdon2016-01-26 13:47:23
opencart
skdon, 2016-01-26 13:47:23

$items = $this->cart->getProducts() Returns an empty array. Why?

Good afternoon!
In the controller file /catalog/controller/checkout/success.php I need to get data about the product in the cart.
I write such code
$items = $this->cart->getProducts();
As a result I receive an empty array. Tell me, please, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Mitrushchenkov, 2016-01-26
@skdon

Hello. I'm not very familiar with opencart, but purely logically, judging by the fact that you are trying to get goods in the successful payment controller, you are unlikely to succeed, since in theory the basket should already be cleared.
Googling a little, I found such things as:
$this->session->data['order_id']- the last order of the user, as I understand it, from which we can do this:

$this->load->model('account/order');
$order_id = $this->session->data['order_id'];
$products = $this->model_account_order->getOrderProducts($order_id);

Plus, on the same Google, I see that there is some version in checkout/success.php. $this->cart->clear();
If you do after that, then I think everything is clear. If possible, push your code up to this line, or try using what I described at the very beginning.
I repeat that I am generally not familiar with opencart and my found solutions may not help you because of just the wrong version of cms, but I tried =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question