Jinandra Jinandra - 9 days ago 5
MySQL Question

Fetching data from table, RewardsPoint Extension: Magento

I am trying to fetch data using this query:[Written in the observer file of RewardPonts extension].

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


But its not returning any result. Can we use direct sql query inside the extension, if yes then what is wrong with my query?

Answer

Yes, You need to debug your code.

$query = 'SELECT mageproownerid FROM '.$table.' WHERE
                               magerealorderid='.$id. ' AND magebuyerid='.$custom;
var_dump($query);  
$result = $readConnection->fetchCol($query);
var_dump($result);

First check query print output of query then also check in database if it is working then there will be no problem.

I think that you need to put space between ' and where & ' and AND in your query.

Comments