I can get information regarding orders using 3rd party API but when I want to save it into 3 tables, for sales_flat_order and sales_flat_order_adress the data has been saved and for sales_flat_order_grid I've gotten this error I think that I want to save the Parent_id in the entity_id as it should be same. But I don't know how.
<br />
<b>Fatal error</b>: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`sales_flat_order_grid`, CONSTRAINT `FK_SALES_FLAT_ORDER_GRID_ENTITY_ID_SALES_FLAT_ORDER_ENTITY_ID` FOREIGN KEY (`entity_id`) REFERENCES `sales_flat_order` (`entity_id`) ON DELETE CA)' in D:\wamp\www\magento1.9\lib\Zend\Db\Statement\Pdo.php:228
this array that I want to save for 3 tables
Foreach($array as $value){
$array = array('status' => $value['status'],
'base_grand_total' => $value['price'],
'grand_total' => $value['price'],
'increment_id' => $value['number'],
'base_currency_code' => 'MXN',
'customer_email' => $value['email'],
'customer_firstname' => $value['name'],
'customer_lastname' => $value['apellido'],
'global_currency_code' => 'MXN',
'order_currency_code' => 'MXN',
'store_name' => 'linio marketplace',
'created_at' => $value['created'],
'updated_at' => $value['created'],
'total_item_count' => $value['item']);
$modele = Mage::getModel('thorleif/order')->setData($array);
$modele->save();
$id = $modele->getId();
$array = array(
'parent_id' => $id,
'region' => $value['region'],
'postcode' => $value['zip'],
'street' => $value['address'].'.'.$value['country'],
'city' => $value['city'],
'email' => $value['email'],
'telephone' => $value['tel'],
'firstname' => $value['name'],
'lastname' => $value['apellido'],
'address_type' => 'shipping');
$modele = Mage::getModel('thorleif/address')->setData($array);
$modele->save();
$array = array(
'parent_id' => $id,
'status' => $value['status'],
'base_grand_total' => $value['price'],
'grand_total' => $value['price'],
'increment_id' => $value['number'],
'base_currency_code' => 'MXN',
'shipping_name' => $value['name'],
'global_currency_code' => 'MXN',
'order_currency_code' => 'MXN',
'store_name' => 'linio marketplace',
'created_at' => $value['created'],
'updated_at' => $value['created']);
$modele = Mage::getModel('thorleif/grid')->setData($array);
$modele->save();
}
if ($order->getPayment()->getMethodInstance()->getCode() != 'free') { return $this; }– javaTodev Jul 09 '17 at 19:36