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.

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69

3 Answers3

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

Khoa TruongDinh
  • 32,054
  • 11
  • 88
  • 155
  • @AshishMadankar Do you able to split the orders? – blakcaps Mar 06 '17 at 07:16
  • @AshishMadankar I would appreciate, if can you shed more light on how did you split the order – blakcaps Mar 07 '17 at 04: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 06:07
  • Your are right. I get api authorisatio error. Could you please help me with this https://magento.stackexchange.com/questions/313143/magento-2-split-order-based-on-product-attribute – Ramesh KR May 19 '20 at 19:16
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.

Matias Hidalgo
  • 453
  • 3
  • 10
  • Could you pls help me with it https://magento.stackexchange.com/questions/313143/magento-2-split-order-based-on-product-attribute – Ramesh KR May 23 '20 at 07:50
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.