我想知道如何选择列。上面你可以看到我想在控制器中写的sql。但我想以正确的方式做到这一点。像 magento 中的其他 sql 语句一样。
我尝试添加 ->columns('o.sku AS SKU') 但这不起作用。
有任何想法吗?提前致谢!
//sql
$readresult="SELECT o.name AS 'Product', o.sku AS 'SKU', c.entity_id AS 'Order', c.customer_email AS 'Email', c.customer_firstname AS 'Voornaam', c.customer_lastname AS 'Achternaam', c.customer_middlename AS 'Tussenvoegsel', o.product_options AS 'Options', a.telephone AS 'Telefoon', a.postcode AS 'Postcode', a.street AS 'Street', a.city AS 'City', c.increment_id AS 'Bestelnr' FROM magento_sales_flat_order AS c INNER JOIN magento_sales_flat_order_item AS o ON c.entity_id = o.order_id INNER JOIN magento_sales_flat_order_address AS a ON a.parent_id = c.entity_id WHERE o.product_id =".$product." GROUP BY c.entity_id ORDER BY o.sku;";
//THE MAGENTO WAY!
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$o = $resource->getTableName('magento_sales_flat_order');
$o_item = $resource->getTableName('magento_sales_flat_order_item');
$o_address = $resource->getTableName('magento_sales_flat_order_address');
$select = $read->select()->from(array('c'=>$o))
->join(array('o'=>$o_item), 'c.entity_id = o.order_id', array(o.sku AS 'SKU'))
->join(array('a'=>$o_address), 'a.parent_id = c.entity_id', array())
->where('o.product_id', $product)
->group('c.entity_id')
->order('o.sku');