** Magento 2.4 order process with marketplace flow:-**
I have one issue with order. We are using marketplace and we can order multiple products from different vendors. If we go with admin payment method and credential everything is working fine and payment is captured in admin payment account. and all products is ordered with one order id.
We have two payment method stripe and paynet secure. Stripe is also providing marketplace feature at their end. But paynet secure has not support of marketplace feature.so vendor payment with stripe is automatically distributed as per ordered vendors. But paynet does not have this feature. When we go to purchase multiple vendors products in which have paynet secure and stripe both, then payment is debited from customer credit card and credited to respective vendor payment provider account.
My requirement is explained below with an example:-
Suppose customer have 3 vendors(A,B and C) products in cart.and their respective payment method is Atripe, B:-Paynet, C:-Paynet. So when customer placed this order(with all 3 vendors products) then customer can put their credit card details once and internally amount will credited to respective vendor payment account as per calculation.
I am stuck at a point to distribute order and assign payment method into it. there are two scenario i'm getting:
public function aroundPlaceOrder(QuoteManagement $subject, callable $proceed, $cartId, $payment = null) { $currentQuote = $this->quoteRepository->getActive($cartId); // Separate all items in quote into new quotes. $quotes = $this->quoteHandler->normalizeQuotes($currentQuote); if (empty($quotes)) { return $result = array_values([($proceed($cartId, $payment))]); } // Collect list of data addresses. $addresses = $this->quoteHandler->collectAddressesData($currentQuote); /** @var \Magento\Sales\Api\Data\OrderInterface[] $orders */ $orders = []; $orderIds = []; foreach ($quotes as $items) { /** @var \Magento\Quote\Model\Quote $split */ $split = $this->quoteFactory->create(); // Set all customer definition data. $this->quoteHandler->setCustomerData($currentQuote, $split); $this->toSaveQuote($split); // Map quote items. foreach ($items as $item) { // Add item by item. $item->setId(null); $split->addItem($item); } \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote 1st :-'. print_r($split->getData(),true)); $this->quoteHandler->populateQuote($quotes, $split, $items, $addresses, $payment); // $split->getPayment()->setMethod('nmi_directpost'); // if ($payment) { // $split->getPayment()->setQuote($split); // $data = $payment->getData(); // $paymentDetails = $paymentCardDetails = ''; // $postData = file_get_contents("php://input");//Get all param // $postData = (array)json_decode($postData);//Decode all json param // foreach ($postData as $key => $value) { // if ($key == 'paymentMethod') { //Get paymentMethod details // $paymentDetails = (array)$value; // foreach ($paymentDetails as $key1 => $paymentValue) { // if ($key1 == 'additional_data') { //get paymentMethod Details like card details // $paymentCardDetails = (array)$paymentValue; // } // } // } // } // $split->setMethod('checkmo'); \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('Paynet :-'); // $payment = $quotes->getPayment(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); $quote = $cart->getQuote(); $paymentMethod = $quote->getPayment()->getMethod(); $payment = $this->checkoutSession->getQuote()->getData(); \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('second Paynet :-'); \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($paymentMethod,true)); // $split->setPayment($payment); // $split->getPayment()->importData(array( // 'method' =>'nmi_directpost', // 'cc_type' =>'VI', // 'cc_number' =>'4111111111111111', // 'cc_exp_year' =>'2025', // 'cc_exp_month'=>'10', // )); // } // \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('original quote :-'. print_r($quotes->getData(),true)); \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($split->getData(),true)); // \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($payment->getData(),true)); // Dispatch event as Magento standard once per each quote split. $this->eventManager->dispatch( 'checkout_submit_before', ['quote' => $split] ); $this->toSaveQuote($split); $order = $subject->submit($split); $orders[] = $order; $orderIds[$order->getId()] = $order->getIncrementId(); if (null == $order) { throw new LocalizedException(__('Please try to place the order again.')); } } $currentQuote->setIsActive(false); $this->toSaveQuote($currentQuote); $this->quoteHandler->defineSessions($split, $order, $orderIds); $this->eventManager->dispatch( 'checkout_submit_all_after', ['orders' => $orders, 'quote' => $currentQuote] ); return $this->getOrderKeys($orderIds); }
If anyone have solution regarding this then please share you solution/Opinion?
I'll be really thankful for this.