7

我想将自定义信息保存在order_item-table. 这些信息在购物车中创建。所以我像这篇文章中描述的那样做。

我已经安装了属性:

$installer->addAttribute('quote_item', 'final_delivery_time', $settings);

$installer->addAttribute('order_item', 'final_delivery_time', $settings);

在 config.xml 中声明字段集

<fieldset>
        <sales_convert_quote_item>
            <final_delivery_time>
                <to_order_item>final_delivery_time</to_order_item>
            </final_delivery_time>
        </sales_convert_quote_item>

        <sales_convert_order_item>
            <final_delivery_time>
                <to_quote_item>*</to_quote_item>
                <to_invoice_item>*</to_invoice_item>
                <to_shipment_item>*</to_shipment_item>
                <to_cm_item>*</to_cm_item>
            </final_delivery_time>
        </sales_convert_order_item>
</fieldset>

例如购物车中的一些代码

$oQuote = Mage::getSingleton('checkout/session')->getQuote();
    foreach ( $oQuote->getAllItems() as $_item )
    {
        $orderItemId = $_item->getId();
        $_item->setFinalDeliveryTime('some Value');
        $_item->save();
    }

所以我得到了一个报价,我在表格final_delivery_time中有这个值的字段sales_flat_quote_item

在我下订单后onepage-review,我应该在 中也有这个字段sales_flat_order_item table,但是什么都没有。立柱null中。所以我需要按顺序保存的字段的值。

4

1 回答 1

6

I found the solution

it's an observer I add the following code

config.xml

...  
<events>
        <sales_convert_quote_item_to_order_item>
            <observers>
                <quoteitem_set_custom_data>
                    <class>DeliveryTime/observer</class>
                    <method>setCustomDataOnQuoteItem</method>
                </quoteitem_set_custom_data>
            </observers>
        </sales_convert_quote_item_to_order_item>
</events>
...

Observer.php

...
public function setCustomDataOnQuoteItem(Varien_Event_Observer $observer)
{

    $quote = Mage::getModel('checkout/cart')->getQuote();
    $orderItem = $observer->getOrderItem();
    foreach ( $quote->getAllVisibleItems() as $_item )
    {
        if ($_item->getSku() == $orderItem->getSku())
        {
            $orderItem->setFinalDeliveryTime($_item->getFinalDeliveryTime());
        }
    }
}
...

so everything is saved in the order

于 2012-07-13T13:26:52.407 回答