I would really appreciate someones help with the problem problem. I'm in Magento by the way I have this method which basically takes two sets of data and creates an sql statement with them.
private function _getInsertSql($data, $itemData)
{
$sql = 'insert into orders_headers (';
$keys = array_keys($data);
$sql .= implode(', ', $keys);
$sql .= ') values (';
foreach($data as $value) {
$type = $value['type'];
$vv = $value['value'];
if ($type == 'number') {
$sql .= $vv;
} else {
$sql .= $this->_db->quote($vv);
}
$sql .= ',';
}
$sql = substr($sql, 0, strlen($sql)-1);
$sql .= ');';
$first = 0;
$sql .= 'insert into orders_lines (';
foreach($itemData as $data) {
if ($first <= 0) {
$keys = array_keys($data);
$sql .= implode(', ', $keys);
$sql .= ') values (';
} else {
$sql .= '(';
}
foreach($data as $value) {
$type = $value['type'];
$vv = $value['value'];
if ($type == 'number') {
$sql .= $vv;
} else {
$sql .= $this->_db->quote($vv);
}
$sql .= ',';
}
$sql = substr($sql, 0, strlen($sql)-1);
$sql .= '),';
$first++;
}
$sql = substr($sql, 0, strlen($sql)-1);
$sql .= ';';
Mage::log("START" .$sql . "END", NULL, 'sql.log');
return $sql;
}
As you can see at the end I'm logging out .sql and weirdly it produces the same query twice. Therefore inserting the same row twice in the DB.
I can't for the life of me see where its looping to the top and creating the query again.
The output sql is:
2013-06-11T15:37:45+00:00 DEBUG (7): STARTinsert into orders_headers (orderID, datetime, ip, customerID, forename, surname, address1, address2, town, county, country, postcode, telephone, fax, email, company, deliveryName, deliveryAddress1, deliveryAddress2, deliveryTown, deliveryCounty, deliveryCountry, deliveryPostcode, deliveryTelephone, goodsTotal, shippingTotal, taxTotal, discountTotal, order_state, order_status, order_comments, order_save_time, status, shippingMethod, paymentID, paymentName, paymentDate, shippingID, orderNotes, paymentNameNative, shippingMethodNative, referURL, accTypeID, offerCode, randID, e_website, e_status, e_purchaseordref, e_statuschk, e_accepted) values ('100004952','20130611153744','127.0.0.1',0,'TES','S','S','','S','','GB','S','SA','','[email protected]','','TES S','S','','S','','GB','S','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default',5,'Cheque','',0,'','Cheque','udropship_default','master/site/',0,'','100004952','master/site/','ZZZ888','','2106','');insert into xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) values ('100004952',2106,'UGWA050','Stainless Steel
wine ice bucket, magnum 9 pt',1,10.0900,16.82,'Stainless Steel
wine ice bucket, magnum 9 pt',3.36,0,0,5,10.0900,1,'new','pending_awaiting_payment','20130611153745');END
2013-06-11T15:37:45+00:00 DEBUG (7): STARTinsert into orders_headers (orderID, datetime, ip, customerID, forename, surname, address1, address2, town, county, country, postcode, telephone, fax, email, company, deliveryName, deliveryAddress1, deliveryAddress2, deliveryTown, deliveryCounty, deliveryCountry, deliveryPostcode, deliveryTelephone, goodsTotal, shippingTotal, taxTotal, discountTotal, order_state, order_status, order_comments, order_save_time, status, shippingMethod, paymentID, paymentName, paymentDate, shippingID, orderNotes, paymentNameNative, shippingMethodNative, referURL, accTypeID, offerCode, randID, e_website, e_status, e_purchaseordref, e_statuschk, e_accepted) values ('100004952','20130611153744','127.0.0.1',0,'TES','S','S','','S','','GB','S','SA','','[email protected]','','TES S','S','','S','','GB','S','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default',5,'Cheque','',0,'','Cheque','udropship_default','master/site/',0,'','100004952','/master/site/','ZZZ888','','2106','');insert into xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) values ('100004952',2106,'UGWA050','Stainless Steel
wine ice bucket, magnum 9 pt',1,10.0900,16.82,'Stainless Steel
wine ice bucket, magnum 9 pt',3.36,0,0,5,10.0900,1,'new','pending_awaiting_payment','20130611153745');END
Can anyone offer their help?
Thanks