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

    '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...


$order = $observer->getEvent()->getOrder();
Mage::log(var_export($order->debug(), true), null, 'nam_order_event.log');

$orderId = $order->getId();


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

  • When you set up your additional table, did you set up model resources as well? The general idea is that you can set these up and then grab your table data with a typical Mage::getModel('web/web')->getCollection() and basically using it like you would any other Magento model.
    – pspahn
    Commented Jun 26, 2015 at 16:34
  • The table was there when I joined the company, I am looking into the code to find out though
    – JasonDavis
    Commented Jun 26, 2015 at 16:35
  • Check out the module's config.xml - You should have a node under global >> models that might look like <web_resource> that defines a model resource class and any entities and their table.
    – pspahn
    Commented Jun 26, 2015 at 16:38
  • If the module is Company_Web it has everything you need. It is a demo module i saw around.
    – mbalparda
    Commented Jun 26, 2015 at 16:39
  • @pspahn Sorry got tied up with the boss. You are correct it is a module some Indians built before I joined company and they didn't even bother to rename! Based on this info, do you think it;s possible to get the data from my existing Event Observer code?
    – JasonDavis
    Commented Jun 26, 2015 at 17:30

1 Answer 1

  1. Get a dev environment you can test what you are doing, this is a horrible comment:

    All I can do is log data since I cant stop the event to see it;s output when a live order is made.

  2. You can just load your data via: Mage::getModel('web/web')->load($orderId, 'order_original_id');

  • 1) I know it;s horrrribbbble! I'm embarrassed to admit to it but my bosses site is so large I just haven't been able to get it for a dev server yet but you are right, it;s a bad choice! 2) I believe that is basically how I ended up doing it, thanks
    – JasonDavis
    Commented Jul 16, 2015 at 21:53

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.