0

我真的很感谢有人帮助解决问题。顺便说一句,我在 Magento 中,我有这种方法,它基本上需要两组数据并用它们创建一个 sql 语句。

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;
}

正如您在最后看到的那样,我正在注销 .sql 并且奇怪的是它两次生成相同的查询。因此在数据库中插入同一行两次。

我一辈子都看不到它循环到顶部并再次创建查询的位置。

输出sql为:

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, phone, 传真,电子邮件,公司,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) 值 ('100004952','20130611153744','127.0.0.1',0,'TES','S','S ','','S','','GB','S','SA','','S@gmila.com','','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','');插入xm1_orders_lines(orderID,productID,code,名称、数量、重量、价格、nameNative、taxamount、ooprice、ootaxamount、supplierID、supplierCost、supplierCostCurrencyID、order_state、order_status、order_save_time)值('100004952',2106,'UGWA050','Stainless Steel'','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','');插入xm1_orders_lines(orderID,productID,code,name,qty,weight,price,nameNative,taxamount,ooprice,ootaxamount ,supplierID,supplierCost,supplierCostCurrencyID,order_state,order_status,order_save_time) 值 ('100004952',2106,'UGWA050','Stainless Steel'','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','');插入xm1_orders_lines(orderID,productID,code,name,qty,weight,price,nameNative,taxamount,ooprice,ootaxamount ,supplierID,supplierCost,supplierCostCurrencyID,order_state,order_status,order_save_time) 值 ('100004952',2106,'UGWA050','Stainless SteelS','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default',5,'支票','',0,' ','Cheque','udropship_default','master/site/',0,'','100004952','master/site/','ZZZ888','','2106','');插入xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,'UGWA050','Stainless钢S','SA',28.88,7.25,4.81,0,'new','pending_awaiting_payment','','20130611153745','P','udropship_default',5,'支票','',0,' ','Cheque','udropship_default','master/site/',0,'','100004952','master/site/','ZZZ888','','2106','');插入xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,'UGWA050','Stainless钢',0,'','支票','udropship_default','master/site/',0,'','100004952','master/site/','ZZZ888','','2106',' '); 插入 xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,' UGWA050','不锈钢',0,'','支票','udropship_default','master/site/',0,'','100004952','master/site/','ZZZ888','','2106',' '); 插入 xm1_orders_lines (orderID, productID, code, name, qty, weight, price, nameNative, taxamount, ooprice, ootaxamount, supplierID, supplierCost, supplierCostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,' UGWA050','不锈钢供应商CostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,'UGWA050','Stainless Steel供应商CostCurrencyID, order_state, order_status, order_save_time) 值 ('100004952',2106,'UGWA050','Stainless Steel
酒冰桶,大酒瓶 9 pt',1,10.0900,16.82,'不锈钢
酒冰桶, 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): START插入orders_headers (orderID, datetime, ip, customerID, forename, surname, address1, address2, town, County, country, postcode, phone, 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) 值 ('100004952','20130611153744','127.0.0.1',0,'TES','S','S','','S','','GB','S','SA','','S @gmila.com','','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','');插入xm1_orders_lines(orderID, productID, code, name, qty, weight, price, nameNative、taxamount、ooprice、ootaxamount、supplierID、supplierCost、supplierCostCurrencyID、order_state、order_status, order_save_time) 值 ('100004952',2106,'UGWA050','不锈钢
酒冰桶, magnum 9 pt',1,10.0900,16.82,'不锈钢
酒冰桶, magnum 9 pt',3.36,0,0,5,10.0900,1,'new','pending_awaiting_payment','20130611153745' );结尾

任何人都可以提供帮助吗?

谢谢

4

2 回答 2

2

我认为 foreach 没有给你两次查询,但你的方法被调用了两次。代码中的 log 方法位于 foreach 循环之外,并且日志文件本身包含 2 个条目(包含在 START 和 END 中)。最好找出你在哪里调用该方法并在那里调试。

于 2013-06-11T16:08:58.820 回答
0

经过一番挖掘,我发现 afterordersaved 事件被调用了两次。

我相信它是由 customer_save_observer_executed 为了解决这个问题,我刚刚完成了以下操作:-

if(Mage::register('customer_save_observer_executed')) {
return;
}
Mage::log('afterOrderSavedObserver call', NULL, 'method_calls.log');                
$model = Mage::getModel('ordersintegration/export');
$model->afterOrderSavedXm1($order);
Mage::register('customer_save_observer_executed', true);

这现在有效

于 2013-06-12T08:16:29.777 回答