2

I store my custom data in my ajax CartController issuing:

foreach ( $quote->getAllItems() as $item ) {
    /* @var $item Mage_Sales_Model_Quote_Item */
    $item->setMyCustomData( 'OK' );
    $item->setOriginalCustomPrice( 777 );
    $item->save();
}

and I want to read these data again in my Order/Pdf/Invoice.php:

foreach ($invoice->getAllItems() as $item){
    Mage::log($item->getOrderItem()->getData()); // Here I wish to see my data set previously
}

The problem is I can only see the price update, but I can not see my MyCustomData field. So I suppose that my custom data stored just as protected _data array don't transfer from quoteItem to orderItem.

How to make it work? Should I rather use some another way to set my custom data? I thought about product options way, but I don't want to affect all the products, only particular ones.

Thanks.

5
  • add a new column to the sales_flat_quote_item table called my_custom_data.
    – Marius
    Commented Oct 20, 2014 at 19:52
  • Thanks, @Marius, is there another way to resolve the issue? Commented Oct 20, 2014 at 20:03
  • create another table that holds your value and a reference to the order item table.
    – Marius
    Commented Oct 20, 2014 at 20:05
  • I think it's too complicated and global. It should be a more elegant solution. Commented Oct 20, 2014 at 20:11
  • Take a look at atwix.com/magento/custom-product-attribute-quote-order-item Commented Oct 20, 2014 at 20:14

1 Answer 1

2

If you attributes are set up correctly on both the order_item and the quote_item then you maybe missing the xml that copies the attribute value when you save and order.

<fieldsets>
    <sales_convert_quote_item>
        <your_attribute_code>
            <to_order_item>*</to_order_item>
        </your_attribute_code>
    </sales_convert_quote_item>
    <sales_convert_order_item>
        <your_attribute_code>
            <to_quote_item>*</to_quote_item>
        </your_attribute_code>
    </sales_convert_order_item>
</fieldsets>

This will copy the attribute value from quote item to order item when saving the order and also from order item to quote item when recreating a quote from an order via the admin or customer section.

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.