2

Edited Question

After the suggestion from Khoa TruongDinh I made changes in savePaymentInformationAndPlaceOrder() and followed this to implement order splitting but it's not working can anyone suggest me my mistakes.

Previous Question

I want to split order depending on no of items in Magento 2. I know in Magento 1.x it is possible by rewriting saveOrder() of Magento\Checkout\Model\Type\Onepage I tried the same way in Magento 2 but it is not working. I also tried to make changes directly in the core file for testing purpose only, but system not visiting saveOrder().

Can anyone please tell me why this is not visiting.

I enabled Onepage Checkout configuration in Admin.

1

As far as I know, Magento uses API: /V1/carts/mine/payment-information on the onepage checkout. So, it's doesn't call your method.

vendor/magento/module-checkout/Model/PaymentInformationManagement.php

public function savePaymentInformationAndPlaceOrder(
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {
        $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
        return $this->cartManagement->placeOrder($cartId);
}

You take a look this file to see more: vendor/magento/module-quote/Model/QuoteManagement.php

  • @AshishMadankar Do you able to split the orders? – blakcaps Mar 6 '17 at 7:16
  • @AshishMadankar I would appreciate, if can you shed more light on how did you split the order – blakcaps Mar 7 '17 at 4:32
  • @AshishMadankar I want to split order in magento2 and I Saw system not visiting saveOrder(). Can you elaborate to split order in magento2 – Pradeep Singh May 23 '17 at 6:07
1

As per I can see in comments you already found a solution, but you never set this as solved, for others looking for a solution you can got an easy example here and another with a different solution here

Please Ashish if you think those are good approaches for get this issue solved let me know in order to help others.

1

Recently I had an experience to split order in checkout and I used a plugin to handle the placeOrder function with around:

public function aroundPlaceOrder(
    \Magento\Quote\Model\QuoteManagement $subject,
    callable $proceed,
    $cartId,
    $paymentMethod = null
) {

    $quote = $this->quoteRepository->getActive($cartId);
    ...

And then, split the quote by product SKU, of course, you can change the separation to any attribute you want.

I split the function into parts to make it easy to understand or modify, please take a look at https://github.com/magestat/magento2-split-order/blob/develop/Plugin/SplitQuote.php file to get more reference or details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.