我正在尝试使用此查询获取数据:[写在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查询,如果是,那么我的查询有什么问题?
答案 0 :(得分:3)
是的,您需要调试代码。
$query = 'SELECT mageproownerid FROM '.$table.' WHERE
magerealorderid='.$id. ' AND magebuyerid='.$custom;
var_dump($query);
$result = $readConnection->fetchCol($query);
var_dump($result);
首先检查查询打印输出的查询然后还检查数据库是否正常工作然后就没有问题了。
我认为您需要在'和之间留出空间&
中的'和AND 。