I'm trying to update a sales_order_item data without success. No exception or error is returned with method A):

$data = array('order_item_custom_field'=> $product->getCustomFieldData());
$model = Mage::getModel('sales/order_item')->load($itemId)->addData($data);
try {
    Mage::Log("Data updated successfully.", null, "system.log");
} catch (Exception $e){
    Mage::Log("Error:". $e->getMessage(), null, "system.log");               

Method B) give nothing better (and also any error):

$writeDb = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "UPDATE sales_flat_order_item SET order_item_custom_field = '". $product->getCustomFieldData() ."' WHERE item_id = ". $item->getItemId();            

Note: order_item_custom_field exists and was created by module installer script.

Is someone know if there is any limitation with direct query on Magento?

Edit: I tried a RAW update statement on a custom db table and it worked as expected.

The problem is probably the sales_flat_order_item itself ? But why it is working when I execute the query directly on MySQL Workbench?

  • are you sure you are working on the correct database? I mean the second method should work, It's kind of a raw query. – Marius Apr 20 '15 at 16:04
  • Yes, of course;) Maybe a MySQL notice/error is dispatched without Php exception. Do you have an advice how I can fully check the MySQL execution? – DarkCowboy Apr 21 '15 at 5:20

Can you confirm the following please:

  1. order_item_custom_field column exists in table sales_flat_order_item
  2. $product->getCustomFieldData() returns a value and if so, what is the output
  3. the sales item loaded exists and what the output is.

Also since your are getting an exception using the second method, it might be helpful if you added the output for the exception as well.

  • 1) Yes. 2) The output an alphanumeric value, as expected. Regarding the 2nd method, I've added the $sql var value into my logs. Then I copy/paste the log output into my mysqlwork bench, exec the query, and it worked as expected (row updated successfully). 3) The sales_order_item loaded exists and I can output each field. This script is placed into a method called by a custom event fired by an sales export extension (it is a check before exporting each order). Is that context be a possible cause of trouble? – DarkCowboy Apr 20 '15 at 19:34

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.