0

I have created a set of custom variable in my sales_flat_quote_item and sales_flat_order_item and saved custom field values into sales_flat_quote_item using the observer <checkout_cart_product_add_after> as below,

        <checkout_cart_product_add_after>
            <observers>
                <ucs_catalogorder_checkout_cart_product_add_after>
                    <type>model</type>
                    <class>Ucs_CatalogOrder_Model_Observer</class>
                    <method>checkoutCartProductAddAfter</method>
                </ucs_catalogorder_checkout_cart_product_add_after>
            </observers>
        </checkout_cart_product_add_after>

Then added the same into sales_flat_order_item using below code snippet

    <fieldsets>
       <sales_convert_quote_item>
           <card_wallet_amount>
               <to_order_item>*</to_order_item>
           </card_wallet_amount>
           <card_handling_charges>
               <to_order_item>*</to_order_item>
           </card_handling_charges>
           <user_preferred_delivery_mode>
               <to_order_item>*</to_order_item>
           </user_preferred_delivery_mode>
           <message_title>
               <to_order_item>*</to_order_item>
           </message_title>
           <message_description>
               <to_order_item>*</to_order_item>
           </message_description>
           <card_library_image>
               <to_order_item>*</to_order_item>
           </card_library_image>
           <wrapper_library_image>
               <to_order_item>*</to_order_item>
           </wrapper_library_image>
       </sales_convert_quote_item>
   </fieldsets>

But after completing the payment process the same has not been saved into either sales_flat_order or sales_flat_quote

  • Then added the same into sales_flat_order_item using below code snippet cannot understand question and But after completing the payment process the same has not been saved into either sales_flat_order or sales_flat_quote – Amit Bera Oct 13 '15 at 7:47
  • It happened because you are working at the order-item level, not at the whole order level. – Prateek Oct 13 '15 at 7:55
  • @AmitBera When I am adding a product into cart, using the observers checkout_cart_product_add_after custom values are being saved into sales_flat_quote_item so <fieldsets>... </fieldsets> save the same into sales_flat_order_item. But $order = Mage::getModel('sales/order')->load($orderId); get the details from sales_flat_order` so those custom fields on sales_flat_order_item should be saved into sales_flat_order. Its not happening. – Butterfly Oct 13 '15 at 8:03
  • @Prateek so, after completing order wont't it get all the available values from sales_flat_order_item to sales_flat_order – Butterfly Oct 13 '15 at 8:06
  • 1
    @version.beta, No, it won't. They are completely different things. You should first decide whether you really want that information at both tables or not. If it's order specific info, it will go into sales_flat_order, and if its order item specific, then it will go into sales_flat_order_item table. – Prateek Oct 13 '15 at 8:51
2

You'll need to decide whether you want that information at the entire order level or at the order line-item level.

Both these tables, sales_flat_order_item and sales_flat_order, serve different purposes in context of an order. The way you created the attribute, information will be saved at the order-item level, like SKU of a product. It is specific to every line item of an order, but can not be stored at the entire order level.

If you are dealing with information that is scoped at the entire order level, like shipping method of order, only then you'll need to save that info into sales_flat_order table. Magento will not do this automatically, you'll need to do that yourself. It will be done the same way you created attribute for order item. You'll just need to observe the different event for that, sales_model_service_quote_submit_after might be a good choice.

  • 1
    An example of data that might want to be at both item level and order level might be something aggregated like cost. Each item will have a cost, and then the total will be saved to the order. As Prateek explains though, there is nothing automatic about the saving of data to the order if you have data in an order item. How could there be? The logic of how to join the data from the items to the order itself has to be defined, whether a total, average, concatenation or some other selection like last or first saved. Perhaps you should explain what exactly you want to save to the order? – Robert Egginton Oct 13 '15 at 13:44

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.