Search code examples
modulemodelsprestashopprestashop-1.5

How to create a order in Prestashop?


I'm creating a module to add orders from a API to prestashop.

I wonder though how to do it. I have been trying to create a cart and someway add products to it without any success. I want to create a order into prestashop that's already paid.

I haven't find a way to add a order or a product to the cart or to save it as paid.

I have done this so far with looking into the controllers prestashop have.

$context = Context::getContext();
foreach($ret->objects as $order) {
     $context->cart->add();
     $context->cookie->id_cart = (int)$context->cart->id;
     // What to do now?
}

I don't know if this is to any help but i would love any point to correct direction.


Solution

  • To add an order entry into your database, you can initialize an order object as follows:

    $order = new Order();
    $order->id_shop = 1;
    $order->id_cart = 12;
    $order->id_customer = 23;
    $order->payment = "COD";
    $order->total_paid = 24500;
    $order->add();
    

    Don't forget to perform other related initializations, as well as execute hooks. You'll find pretty much everything you need reverse engineering PrestaShop's github.