Skip to content

Instantly share code, notes, and snippets.

@razbakov
Created December 7, 2011 14:46
Show Gist options
  • Save razbakov/1443068 to your computer and use it in GitHub Desktop.
Save razbakov/1443068 to your computer and use it in GitHub Desktop.
Shipment
<?php
/** @var $order Mage_Sales_Model_Order */
$order = Mage::getModel('sales/order');
$order->load($orderId);
/** @var $shipment Mage_Sales_Model_Order_Shipment */
$shipment = Mage::getModel('sales/order_shipment');
$shipment->setOrder($order);
foreach($trackingNumbers as $trackingNumber) {
/** @var $shipmentTrack Mage_Sales_Model_Order_Shipment_Track */
$shipmentTrack = Mage::getModel('sales/order_shipment_track');
$shipmentTrack->setCarrierCode('Hega');
$shipmentTrack->setNumber($trackingNumber);
$shipmentTrack->save();
$shipment->addTrack($shipmentTrack);
}
$shipment->save();
$order->setState($afterImportStatus, true, $orderMessage, $isCutomerNotified);
$order->save();
// I have this error:
/*
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`sales_flat_shipment_track`, CONSTRAINT `FK_BCD2FA28717D29F37E10A153E6F2F841` FOREIGN KEY (`parent_id`) REFERENCES `sales_flat_shipment` (`entity_id`) ON DELETE CASCADE ON UPDATE CAS)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment