CMS Development Magento

How to join sales order with custom table in magento 1.x

I have created a new table in Magento 1 like this

enter image description here

How to join table sales_order and custom_table where increment_id = order_number. I try this code but it did not work for me, it hasn’t data and shows error


Integrity constraint violation: 1052 Column '`created_at`' in where clause is ambiguous

My Code

    $tbl_faq_item = Mage::getSingleton('core/resource')->getTableName('custom_table');
    $ordershippeddays = Mage::getStoreConfig('custom/customgroup/x_day');
    $fromDate         = gmdate("Y-m-d H:i:s", gmmktime(0, 0, 0, gmdate("m"), gmdate("d") - $ordershippeddays, gmdate("Y")));
    $toDate           = gmdate("Y-m-d H:i:s", gmmktime(23, 59, 59, gmdate("m"), gmdate("d"), gmdate("Y")));
    $collection = Mage::getModel('sales/order')->getCollection();
    $collection->addFieldToFilter('customer_id', array('eq'=> $this->getCustomerLogin()->getId()));
    $collection->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
    $collection->addFieldToFilter('status', array('in' => array('complete','processing')));
       ->join(array('t2' => $tbl_faq_item),'main_table.increment_id = t2.order_number')->where('main_table.increment_id = t2.order_number');

Leave a Reply

Your email address will not be published. Required fields are marked *