Jump to content

[SOLVED] How to get all orders with certain status


Piotr Kaczor
 Share

Recommended Posts

  • 1 year later...
  • 6 years later...

As the new Prestashop is using Symfony, this is how to query the database:

$this->entityManager = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Foundation\\Database\\EntityManager');

$id_order_state = 5;

$orders = $this->entityManager->getRepository('Order')
  ->findBy([
  	'current_state' => $id_order_state
  ]);

You can use this in a front controller like this:

<?php

use PrestaShop\PrestaShop\Adapter\ServiceLocator;

class MymoduleTestcontrollerModuleFrontController extends ModuleFrontController
{
    private $entityManager;

    public function __construct()
    {
        parent::__construct();
        $this->entityManager = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Foundation\\Database\\EntityManager');
    }

    public function initContent()
    {
        parent::initContent();                          

        $id_order_state = 5;

        $orders = $this->entityManager->getRepository('Order')
            ->findBy([
                'current_state' => $id_order_state
            ]);

        echo '<pre>'; print_r($orders); echo '</pre>'; die;
    }
}

 

Edited by stifler97 (see edit history)
  • Like 2

Share this post


Link to post
Share on other sites

You can also use a filter with Order::getOrdersWithInformations(), eg

 $records = array_filter(Order::getOrdersWithInformations(), function ($record) use ($level) {
return $record['current_state'] == 10;
 });

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More