我正在尝试使用此查询获取数据:[写在RewardPonts扩展的观察者文件中]。
public function salesOrderInvoiceSaveAfter($observer)
{
$id=$observer['invoice']->getOrder()->getRealOrderId();
echo $id;
$custom=$observer['invoice']->getOrder()->getCustomerId();
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$table = $resource->getTableName('marketplace/saleslist');
$result = $readConnection->fetchCol('SELECT mageproownerid FROM '.$table.'WHERE magerealorderid='.$id.
'AND magebuyerid='.$custom);
var_dump($result);
$invoice = $observer->getEvent()->getInvoice();
foreach ($invoice->getAllItems() as $item) {
$name = $item->getName();
$type = $item->getSku();
$id = $item->getProductId();
$qty = $item->getQty();
$price = $item->getPrice();
echo $name.",".$type.",".$id.",".$qty.",".$price;
}
但它没有返回任何结果。我们可以在扩展中使用直接 sql 查询吗,如果是,那么我的查询有什么问题?
是的,你需要调试你的代码。
$query = 'SELECT mageproownerid FROM '.$table.' WHERE
magerealorderid='.$id. ' AND magebuyerid='.$custom;
var_dump($query);
$result = $readConnection->fetchCol($query);
var_dump($result);
首先检查查询的查询打印输出,然后检查数据库是否正常工作,则不会有问题。
我认为您需要在查询中的 ' 和 where&' 和 AND 之间放置空格。