Thursday, June 20, 2013

Magento : Create CSV file for any custom data in magento

It can be done by using Varien_File_Csv class
Exp:

$file_path = '/your_dir_path/sample.csv';
$mage_csv = new Varien_File_Csv(); //mage CSV 
$products_ids = array(1,2,3); //product ids or make array of any data
$products_model = Mage::getModel('catalog/product');
$products_row = array();
foreach ($products_ids as $pid)
{
   $prod = $products_model->load($pid);
   $data = array();
   $data['sku'] = $prod->getSku();
   $data['name'] = $prod->getName();
   $data['price'] = $prod->getPrice();    
   $products_row[] = $data;              
}
$mage_csv->saveData($file_path, $products_row);

Sunday, June 16, 2013

Magento : Order State and Status in Magento

In Magento, there are two columns in sales_flat_order table.
These are state and status, They both are different. State is used by magento to tell if the order is new, processing, complete, holded, closed, canceled, etc.

while Statuses are the one that YOU would be defining at the backend in System -> Order Statuses. Magento displays order STATUSES and not STATES in the backend order detail page to let you know which status is assigned as per your mapping.

Remember, multiple statuses can be mapped with one state, while vice versa is not possible.

Also you may know more, reading file /app/code/core/Mage/Sales/etc/config.xml