I am trying to export orders and address using the following code:
$collection = Mage::getModel('sales/order')->getCollection();
$collection->addFieldToFilter('store_id', 3);
if (!$this->isAll()) {
$collection->addFieldToFilter('updated_at', array('from' => date('Y-m-d', strtotime('-1 day'))));
$collection->addFieldToFilter('updated_at', array('to' => date('Y-m-d')));
}
$addressCollection = Mage::getModel('customer/address')->getCollection()->addAttributeToSelect('*');
$addressCollection->getSelect()->limit(1);
$address = $addressCollection->getFirstItem();
foreach ($address->getAttributes() as $attribute) {
if (is_null($attribute->getAttributeID()) || is_null($attribute->getFrontendLabel()) || ($attribute->getFrontendLabel() == '')) {
continue;
}
$collection->joinAttribute($attribute->getName() . '_billing', 'order_address/' . $attribute->getName(), 'billing_address_id', null, 'left');
$collection->joinAttribute($attribute->getName() . '_shipping' , 'order_address/' . $attribute->getName(), 'shipping_address_id', null, 'left');
}
echo $collection->getSelect();
But my select does not contain the joined fields – the output is:
SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` WHERE (store_id = '3') AND (updated_at >= '2014-04-15') AND (updated_at <= '2014-04-16')
Best Answer
The
Mage_Sales_Model_Resource_Collection_Abstract::joinAttribute
method of sales models is empty and thus without any effect:Replace the second part with
join
s