我已經看到了如何做到這一點在許多這樣的例子。但所有的例子都是針對不同版本的Magento。他們都沒有在我的案件中工作。我的版本是1.4.0.0rc-1。是的,我知道這不應該在生產環境中,但不幸的是在這裏就是這種情況。如何添加SKU爲了電網頁
的問題是在法師/ Adminhtml /座/銷售/訂單/ Grid.php類_prepareCollection()函數是比所有我見過的其他例子不同。所以不知道該怎麼做。
這是這個函數的代碼如何:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
->joinAttribute('sku','sales_flat_order_item', null, null, 'left')
->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
->addExpressionAttributeToSelect('billing_name',
'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
array('billing_firstname', 'billing_lastname'))
->addExpressionAttributeToSelect('shipping_name',
'CONCAT({{shipping_firstname}}, IFNULL(CONCAT(\' \', {{shipping_lastname}}), \'\'))',
array('shipping_firstname', 'shipping_lastname'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
我嘗試添加左加入,但沒有奏效。這是setCollection語句之前我曾嘗試:
$collection->getSelect()->join('sales_flat_order_item', 'order_id=entity_id', array('name'=>'name', 'sku' =>'sku'), null,'left');
但它打印出以下錯誤:
SELECT `e`.*, `_table_billing_address_id`.`value` AS `billing_address_id`, `_table_billing_firstname`.`value` AS `billing_firstname`, `_table_billing_lastname`.`value` AS `billing_lastname`, `_table_shipping_address_id`.`value` AS `shipping_address_id`, `_table_shipping_firstname`.`value` AS `shipping_firstname`, `_table_shipping_lastname`.`value` AS `shipping_lastname`, CONCAT(_table_billing_firstname.value, " ", _table_billing_lastname.value) AS `billing_name`, CONCAT(_table_shipping_firstname.value, IFNULL(CONCAT(' ', _table_shipping_lastname.value), '')) AS `shipping_name`, `sales_flat_order_item`.`name`, `sales_flat_order_item`.`sku` FROM `sales_order` AS `e`
LEFT JOIN `sales_order_int` AS `_table_billing_address_id` ON (_table_billing_address_id.entity_id = e.entity_id) AND (_table_billing_address_id.attribute_id='112')
LEFT JOIN `sales_order_entity_varchar` AS `_table_billing_firstname` ON (_table_billing_firstname.entity_id = _table_billing_address_id.value) AND (_table_billing_firstname.attribute_id='202')
LEFT JOIN `sales_order_entity_varchar` AS `_table_billing_lastname` ON (_table_billing_lastname.entity_id = _table_billing_address_id.value) AND (_table_billing_lastname.attribute_id='204')
LEFT JOIN `sales_order_int` AS `_table_shipping_address_id` ON (_table_shipping_address_id.entity_id = e.entity_id) AND (_table_shipping_address_id.attribute_id='113')
LEFT JOIN `sales_order_entity_varchar` AS `_table_shipping_firstname` ON (_table_shipping_firstname.entity_id = _table_shipping_address_id.value) AND (_table_shipping_firstname.attribute_id='202')
LEFT JOIN `sales_order_entity_varchar` AS `_table_shipping_lastname` ON (_table_shipping_lastname.entity_id = _table_shipping_address_id.value) AND (_table_shipping_lastname.attribute_id='204')
INNER JOIN `sales_flat_order_item` ON order_id=entity_id WHERE (e.entity_type_id = '11') ORDER BY `e`.`created_at` desc, `e`.`created_at` desc LIMIT 20
是否有人可以幫助我如何解決這個問題?而對於您的信息,該SKU字段是在「Sales_flat_order_item」表。
有什麼打算做的每個訂單,其中有多個SKU的/產品? – Andrew
@Andrew:感謝您的答覆。但我已經解決了這個問題。 :) – blackRider
@meraz請發表您的解決方案作爲一個答案,然後接受它給別人看的。 – clockworkgeek