0
我想知道如何選擇列。在上面你可以看到我想要寫入控制器的sql。但我想以這種方式做到這一點。像其他在magento中的sql語句一樣。選擇列magento
我試圖添加 - >列('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');
我不調整核心模塊,我正在開發一個自定義模塊。 我解決了這個問題,現在它工作起來就像我希望它工作。但是,我擔心,就像你說的那樣,我做錯了。我可以看看有什麼好的資源來看看它是如何完成的? – 2012-07-10 12:51:38
如果你不知道Magento的基礎知識,幾乎Magento在網絡上的每一個資源都是絕對錯誤/過時的,或者太難遵循。我發現的唯一真正好的是[這是Mage Dev Fundamentals一週課程的錄音](http://www.magentocommerce.com/training/descriptions#fundamentals-of-magento-development)。 – 2012-07-10 13:13:29
另外,我沒有說你正在編輯核心模塊。我試圖說,你應該在非常高的層次上使用Magento的核心功能 - 模型或資源模型。沒有比這更深。 :) – 2012-07-10 13:27:46