Multiple order per cart

Hello, I have to create multiple orders per cart depending product supplier, but from what I read is impossible, what I already tried :

      $suppliers = [];
        foreach ($cart->getItems() as $item) {
            $supplier = $item->getProduct()->getSuppliers();
            $suppliers[$supplier[0]->getId()][] = $item;
        }
        foreach ($suppliers as $supplier => $items) {
            $order = $this->createOrder($cart, $items);
        }
private function createOrder($cart, $items)
    {
        /** @var CoreShopOrder $order */
        $order = $this->orderFactory->createNew();
        $order->setPublished(true);
        $order->setOrderDate(Carbon::now());
        $order->setStore($this->shopperContext->getStore());
        $order->setKey(uniqid());
        $order->setCustomer($this->customer);

//        $order = $this->proposalTransformer->transform($cart, $order);
        foreach ($items as $item) {
            $order->addItem($item);
        }

        $order->save();

        return $order;
    }

I get the error : Validation failed: Invalid relation in fielditems[type: manyToManyRelation] fieldname=items
Have you an idea about that ? Thx in advance.
@dpfaffenbauer have you an idea how to transform cart item to order item ? or exist another way to do that ? thx

Hi,

did you create a custom new OrderItem Type? If so, you also have to allow it in Order->Items relation in the Pimcore Class Editor.

Cheers

Thank you for you answer, but now I getting a very strange error :

$order = $this->orderFactory->createNew();
$order->setPublished(true);
$order->setOrderDate(Carbon::now());
$order->setStore($this->shopperContext->getStore());
$order->setKey(uniqid());
$order->setCustomer($this->customer);
$order->setBaseCurrency($cart->getStore()->getCurrency());
$order->setCurrency($cart->getStore()->getCurrency());
$order->setParent($this->objectService->createFolderByPath('/project/orders/'));
$order->setPath($this->objectService->createFolderByPath('/project/orders/'));

$path = $order->getFullPath();

In the path I get the value : /project/orders5d26ea3839cd1. Have you an idea @dpfaffenbauer why after orders I don’t have a / ? Thx in advance.

nope, sorry, thats not a CoreShop issue

@fash have you an idea about this issue ? Thx in advance