I have this code below that queries the Database for a collection or order records and it makes sure to JOIN
my custom table and return it;s columns off data as well.
The custom table is named web/web
and custom table columns are order_original_id
which will be an ID that matches the order ID on the main table. Also shipbydate
The PHP that gets this data…
$collection = Mage::getModel('sales/order')->getCollection();
$collection->addAttributeToFilter('status', array('eq' => $status));
// Filter out Order Types (RMA, RUSH, Normal)
$collection->addAttributeToFilter('ordertype_id', array('in' => $orderType));
$collection->getSelect()->joinLeft(array(
'web' => $collection->getTable('web/web')),
'web.order_original_id = main_table.entity_id'
);
$collection->addOrder('shipbydate', 'ASC');
foreach ($collection as $order) {
$shipping = $order->getShippingAddress()->getData();
$html .= '<tr>';
$html .= ' <td><strong>Order#</strong><br> <a href="work-order/order.php?orderid='.$order->getRealOrderId().'" target="_blank">'.$order->getRealOrderId().'</a></td>';
$html .= ' <td><strong>Status:</strong><br> ' .$status_array[$order->getStatus()]. '</td>';
$html .= ' <td><strong>Shipping Name:</strong><br>' .$shipping['firstname'].' '.$shipping['lastname'].'</td>';
$html .= ' <td><strong>Shipping State:</strong><br>' .$shipping['region'].'</td>';
$html .= ' <td><strong>Order Date:</strong><br> ' .$order->getCreatedAt(). '</td>';
$html .= ' <td><strong>Ship Date:</strong><br>' .$order->getShipbydate(). '</td>';
// Order Type (RMA, Rush, Normal)
$order_type = $order->getOrdertypeId();
}
Moving on now what I am doing is using an Event Observer that is fired when a purchase is made in the shopping cart. It gets the order data and then I have access to it in which I then insert it into a 3rd party DB table.
The problem is that I need to somehow get the data from my custom add-on table in this Observer code!
Here is that code…
observer.php
$order = $observer->getEvent()->getOrder();
Mage::log(var_export($order->debug(), true), null, 'nam_order_event.log');
$orderId = $order->getId();
//$order=$observer->getEvent()->getOrder();
if ($order->getId()) {
$sign_type = 'Neon Sign';
$design_number = '';
$item_qty = $order->items_qty;
$grand_total_price = $order->grand_total;
$customer_id = $order->customer_id;
// insert data into 3rd party DB tables
}
So using the code I just posted for Observer.php I need to somehow get the DB table data from DB table web/web
Any ideas on a solution?
UPDATE 1: Requested Config.xml
<global>
<models>
<web>
<class>Company_Web_Model</class>
<resourceModel>web_mysql4</resourceModel>
</web>
<web_mysql4>
<class>Company_Web_Model_Mysql4</class>
<entities>
<web>
<table>web</table>
</web>
</entities>
</web_mysql4>
</models>
<resources>
<web_setup>
<setup>
<module>Company_Web</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</web_setup>
<web_write>
<connection>
<use>core_write</use>
</connection>
</web_write>
<web_read>
<connection>
<use>core_read</use>
</connection>
</web_read>
</resources>
<blocks>
<web>
<class>Company_Web_Block</class>
</web>
</blocks>
<helpers>
<web>
<class>Company_Web_Helper</class>
</web>
</helpers>
</global>
Best Answer
Get a dev environment you can test what you are doing, this is a horrible comment:
You can just load your data via:
Mage::getModel('web/web')->load($orderId, 'order_original_id');