config.xml
Observer.php
<?xml version="1.0"?>
<config>
<modules>
<Test_Test>
<version>0.1.0</version>
</Test_Test>
</modules>
<global>
<helpers>
<test>
<class>Test_Test_Helper</class>
</test>
</helpers>
<models>
<test>
<class>Test_Test_Model</class>
<resourceModel>test_mysql4</resourceModel>
</test>
</models>
<events>
<checkout_onepage_controller_success_action> <!-- identifier of the event we want to catch -->
<observers>
<checkout_onepage_controller_success_action_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>test/observer</class> <!-- observers class alias -->
<method>exportCsvOnCheckout</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</checkout_onepage_controller_success_action_handler>
</observers>
</checkout_onepage_controller_success_action>
</events>
</global>
</config>
Observer.php
<?php
class Test_Test_Model_Observer
{
public function exportCsvOnCheckout(Varien_Event_Observer $observer)
{
$orderIds = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($orderIds);
$customer = Mage::getModel('customer/customer')->load($order->getData('customer_id'));
// echo '<pre>';print_r($customer->getName());exit;
$file_path = "order.csv";
$mage_csv = new Varien_File_Csv();
$data = array();
$data['Email'] = $customer->getEmail();
$data['name'] = $customer->getName();
$products_row[] = $data;
$mage_csv->saveData($file_path, $products_row);
}
} }
No comments:
Post a Comment