0

I am using magento 1.9.

I want to retrieve data from sales_flat_quote_address table in onepagecheckout, after saved the shipping method. I have used the following codes. But no result.

Code 1:

$quote_address = Mage::getModel('sales/quote_address')->getCollection();

$quote_address->addFieldToFilter("address_type", array("eq" => "shipping"));

$quote_address->addFieldToFilter("quote_id", array("eq" => $quote_c->getId()));

Code 2:

$resource = Mage::getSingleton('core/resource');

$connRead = $resource->getConnection('core_read');

$sqlCdnImageName = "SELECT shipping_method FROM sales_flat_quote_address WHERE address_type = 'shipping' AND quote_id = " .$quote_c->getId() . ";";

$results = $connRead->fetchAll($sqlCdnImageName);

Code 2 generates this query:

SELECT shipping_method FROM sales_flat_quote_address WHERE address_type = 'shipping' AND quote_id = 123

But the data is not coming. please help to solve this.

Update: This quote data comes out when user doing checkout by logged in. But the data returns empty when guest checkout at the first time. After refresh the page(i mean 2nd time) the data comes out.

I found the updated time changes in the data printed and the data comes in the phpMyAdmin by executing the query. Is this affect the result in any way?

Data comes from the Model and query in the Phtml file:

[created_at] => 2017-03-09 09:50:06

[updated_at] => 2017-03-09 09:51:04

Data from PhpMyAdmin SqlQuery:

[created_at] => 2017-03-09 09:50:06

[updated_at] => 2017-03-09 09:51:51

2 Answers 2

1

I dont know why you use method2 b'cuz method 1 is right

$quote_address = Mage::getModel('sales/quote_address')->getCollection();

$quote_address->addFieldToFilter("address_type", array("eq" => "shipping"));

$quote_address->addFieldToFilter("quote_id", array("eq" => $quote_c->getId()));

print_r($quote_address->getData());//for printing data

foreach($quote_address as $address){
   print_r($address);   
}  
1
  • I have tried this already. But no result. This quote data comes out when user doing checkout by logged in. But the data returns empty when guest checkout at the first time. After refresh the page(i mean 2nd time) the data comes out. Commented Mar 9, 2017 at 9:32
0

Try,

$sqlCdnImageName = "SELECT shipping_method FROM ". $resource->getTableName('sales/quote_address') . " WHERE address_type = 'shipping' AND  quote_id = $quote_c->getId()";

The reason for not getting data could be that you have used table_prefix in for your magento tables while setup.
$resource->getTableName('sales/quote_address') will give you exact table name with table prefix values if any.

3
  • I have tried this already. But no result. This quote data comes out when user doing checkout by logged in. But the data returns empty when guest checkout at the first time. After refresh the page(i mean 2nd time) the data comes out. Commented Mar 9, 2017 at 9:32
  • You should add full details to your question. So it does not confuse others. Please update your question with your full requirements. Commented Mar 9, 2017 at 9:37
  • Updated the question Commented Mar 9, 2017 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.