I am modifying the placeOrder function of the QuoteManagement class, based on some information I found through searches, I was able to change the method so that an order is generated for each seller, but the values are kept the same, ie I get the value total of all items and not just the value of the already separated items. Can someone tell me what place or what should I do so that the total amount is separated according to the items of each order?


public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
    $quote = $this->quoteRepository->getActive($cartId);

    $paymentMethodString = $quote->getPayment()->getMethod(); // edit 19.10.17

    // get data from addresses and remove ids
    $billingAddress = $quote->getBillingAddress()->getData();
    $shippingAddress = $quote->getShippingAddress()->getData();

    $itemsPerVendor = [];
    foreach($quote->getAllItems() as $item) {
        // I don't know how do you keep track of your product vendor, use this as reference only
        $product_id = $item->getProduct()->getId();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

        $itemsPerVendor[$product->getSellerId()][] = $item;

    foreach($itemsPerVendor as $vendor => $items) {
        // init Quote Split
        $quoteSplit = $this->quoteFactory->create();
        if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {

        // save quoteSplit in order to have a quote id for item

        $subtotal = 0;  

        foreach ($items as $item) {
            // add item
            $item->setId(null); // init item id for force to be added to quoteSplit collection

        // set addresses

    // recollect totals into the quote

        // set payment method // edit 19.10.17
        if ($paymentMethod) {
            $data = $paymentMethod->getData();

        // dispatch this event as Magento standard once per each quote split
        $this->eventManager->dispatch('checkout_submit_before', ['quote' => $quoteSplit]);

        $order = $this->submit($quoteSplit);
        $orders[] = $order;

        if (null == $order) {
            throw new LocalizedException(
                __('An error occurred on the server. Please try to place the order again.')

    // disable origin quote
    $this->quoteRepository->save($quote); // edit 19.10.17


    $this->eventManager->dispatch('checkout_submit_all_after', ['orders' => $orders, 'quote' => $quote]);

     * the API declaration and interface describe this function returning int, you can't return an array.
     * in order to do that you will have to create a new end point for that.

How can I set grand total and subtotal of each order after order split?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.