I have a new field varient_id in sales_flat_quote_item and sales_flat_order_item table.

I want to save item_id as varient_id in sales_flat_quote_item and sales_flat_order_item table. ie,quote item_id as quote varient_id and order item_id as order item_id.

How can I do it?

2 Answers 2


Beste way i think is creating a observer on the sales_model_service_quote_submit_after action and there manipulate the database to process the data needed. hope this helps.

In config.xml


In Observer

  public function setVariantId($observer)
        $order = $observer->getEvent()->getOrder();
        $quote = $observer->getEvent()->getQuote();
        $orderId = $order->getId();
        $orderItems = $order->getAllItems();
        foreach($orderItems as $item){      

                $parentId = 0;
                $orderItemCollection = Mage::getModel('sales/order_item')->getCollection()
                            ->addFieldToFilter('quote_item_id', $item->getVariantId())
                            ->addFieldToFilter('order_id', $orderId);
                foreach($orderItemCollection as $col){
                    $parentId = $col->getItemId();              


I have a solution here for Magento 2. I am sharing this for basic Idea. You can create an observer in 1.9 for sales_model_service_quote_submit_after in your XML file.


In observer file you can update your item ID. Here is the code that we need to add observer file.

protected $_checkoutSession;
public function __construct ( \Magento\Checkout\Model\Session $_checkoutSession ) {
    $this->_checkoutSession = $_checkoutSession;
public function saveData(\Magento\Framework\Event\Observer $observer)
  $cartData = $this->_checkoutSession->getQuote()->getAllVisibleItems();
    foreach( $cartData as $item ):
        /* Here we can manipulate data */

for manipulate database and to process data you need block or model files. you also need to initialize resource, then you need to call connection. I hope it will give you an idea to save varient_id. Also here is a link can help you that How to manipulate db tables helplink1 helplink2

Your Answer

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

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