1
votes

I have to update the product sku to new sku so that was done easily, but after that only realized i should update the ordered product sku's too.

How can i update the ordered product sku in magento. Please help me.

I tried this one

$orders = Mage::getModel('sales/order')->loadBySku("sku");

But this returns fatal error

Fatal error: Uncaught exception 'Varien_Exception' with message 'Invalid method Mage_Sales_Model_Order::loadBySku(Array ( [0] => koboonyx ) )' in /home/makegood/public_html/mage34/lib/Varien/Object.php:567 Stack trace: #0 /home/makegood/public_html/mage34/sku.php(7): Varien_Object->__call('loadBySku', Array) #1 /home/makegood/public_html/mage34/sku.php(7): Mage_Sales_Model_Order->loadBySku('koboonyx') 2 {main} thrown in /home/makegood/public_html/mage34/lib/Varien/Object.php on line 567

Or do i have to load orders by order id and then should update the sku to new sku

Like this

$order = Mage::getModel('sales/order')->load($order_id);
foreach ($items as $itemId => $item)
{

}

Please help me

1

1 Answers

5
votes

Perhaps you mean to do this:

$orderItems = Mage::getModel('sales/order_item')->getCollection()
    ->addAttributeToFilter('sku', $oldSKU);
foreach ($orderItems as $item) {
    $item->setSku($newSKU)
        ->save();
}