2

I am using plugin for converting "quote_item" to "sales_order_item" from below give code it work.

public function aroundConvert(
        \Magento\Quote\Model\Quote\Item\ToOrderItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item\AbstractItem $item,
        $additional = []
    ) {
        /** @var $orderItem \Magento\Sales\Model\Order\Item */
        $orderItem = $proceed($item, $additional);
        $orderItem->setCurrentSellerId($item->getCurrentSellerId());
        return $orderItem;
    }

But now i am want to convert my custom attribute("current_seller_id") data into "sales_order" custom column.

1

You can create an observer for the event sales_model_service_quote_submit_before. This happens directly before the converted order is placed. In your observer you can access the quote and the order object and can transfer your custom attribute value from the quote to the order.

Try something like this in your observer:

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $quote = $observer->getData('order');
    $order = $observer->getData('order');

    //get the current_seller_id from quote 
    $order->setCurrentSellerId($quote->getCurrentSellerId());

    //alternative: get the current_seller_id from the first quote_item where it is set 
    $quoteItems = $quote->getItems();
    foreach ($quoteItems as $quoteItem){
        if ($quoteItem->getCurrentSellerId() != ""){
            $order->setCurrentSellerId($quoteItem->getCurrentSellerId());
            break;
        }
    }
    return $this;
}
  • Thanks for answering But Your answer for convert data from Quote To Order. But actually i need Convert from quote_item to quote OR order_item to order. – HaFiz Umer Feb 18 at 14:40
  • since you might have more than one item in an order that's not really a consistent way, but anyway you can iterate over the quote items or even the order items in the same method. I've updated my response with that variant to – HelgeB Feb 18 at 14:48
  • Thank you so much HeleB you help me alot. It work good . But 1 thing i changed you set value in sales_order in foreach loop ,due to this value replace in each loop finally just 1 current_seller_id put in db. I set value in sales_order out of the foreach loop then it work and set all value like (1,2,3) . . . foreach ($quoteItems as $quoteItem){ if ($quoteItem->getCurrentSellerId() != ""){ $items[]=$quoteItem->getCurrentSellerId(); } } $seller_ids=implode(',',$items); $order->setCurrentSellerId($seller_ids); – HaFiz Umer Feb 19 at 11:03

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.