Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 410 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing the Order object from the Cart Id in Prestashop

#1
I am POSTing the Cart id to my module method. From that I can obviously create the Cart object using that id. But how do I access the Order object that corresponds to that Cart object?

I've tried something like;

$cart = new Cart($_POST['id']);

var_dump($this->context->order);

And also trying to do a sort of where() query on the Order (where id_cart is equal to the id in my Cart object);

$order = new Order('id_cart', $cart->id);

It is probably really obvious but I just don't know Prestashop very well.

The reason I am trying to do this is so I change the status of an Order if the payment has timed out.

Reply

#2
I win;

$order = Order::getOrderByCartId((int)($cart->id));
Reply

#3
Try

$order = Order::getByCartId($cart->id)
Reply

#4
I am passing ```$cart->id``` to function in my module and then I pass it to .tpl where I can access it.

But in function in controller I can not get to an order object

Either:
```php
$order = Order::getByCartId($cart->id)
```
or
```php
$order = Order::getOrderByCartId((int)($cart->id));
```
no results.
I have

```php
public function displayMyHooKName($params) {

$id_cart = $params['id_cart'];
/* $id_cart has value of cart id - I have checked */


}
```

I tried:
```php
$cart = new Cart($params['id_cart']);

$order = Order::getOrderByCartId((int)($cart->id));
/*or*/
$order = Order::getByCartId($cart->id);


```

so how to access ```php$order``` knowing ```$cart->id``` ?

*******
OK
```php
$order = Order::getOrderByCartId((int)($cart->id));
```
gives back
```php
#order_id
```

so I did:
```php

$cart = new Cart($params['id_cart']);
$orderID = Order::getOrderByCartId((int)($cart->id));
$order = new Order($orderID);

$products = $order->getProducts();
```

and my
```php
$products
```
is empty

*******
SOLVED

OK I got it. Code above is 100% correct and it works as it should.

I was smart enough to try to get data from order object - before order was placed:) Was calling my hook on order-address.tpl.

So products data were in
```php
$cart->getProducts();
```

However maybe my case will help someone.

@Mike Nguyen post should be marked as answer, Mike has a point.


Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through