2

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>
  • 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 Jun 26 '15 at 16:34
  • The table was there when I joined the company, I am looking into the code to find out though – JasonDavis Jun 26 '15 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 Jun 26 '15 at 16:38
  • If the module is Company_Web it has everything you need. It is a demo module i saw around. – mbalparda Jun 26 '15 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 Jun 26 '15 at 17:30
2
  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 Jul 16 '15 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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