伙计们,我对 Magento 很陌生所以有人可以帮助我吗?以下是我在管理员中的销售订单网格上获取礼品消息的代码:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->join('sales/order_item','`sales/order_item`.order_id=`main_table`.entity_id',array(
'giftavail' => new Zend_Db_Expr('group_concat(`sales/order_item`.gift_message_available SEPARATOR ",")'),
'giftid' => new Zend_Db_Expr('group_concat(`sales/order_item`.gift_message_id SEPARATOR ",")'),
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
'name' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),)
);
$collection->getSelect()->group('main_table.entity_id');
$collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),
'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));
$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),
'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight',
'sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status',
'sfo.base_grand_total','sfo.grand_total'));
$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),
'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street',
'sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone' , 'sfoa.country_id'));
$collection->getSelect()->joinLeft(array('gfm' => 'gift_message'),
'main_table.giftid = gfm.gift_message_id',array('gfm.message'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
这是生成的 SQL 查询:
"SELECT main_table
.*, group_concat( sales/order_item
.gift_message_available SEPARATOR ",") AS giftavail
, group_concat( sales/order_item
.gift_message_id SEPARATOR ",") AS giftid
, group_concat( sales/order_item
.sku SEPARATOR ",") AS skus
, group_concat( sales/order_item
.name SEPARATOR ",") AS name
, sfog
. shipping_name
, sfog
. billing_name
, sfo
. customer_email
, sfo
. weight
, sfo
. discount_description
, sfo
. increment_id
, sfo
. store_id
, sfo
. created_at
, sfo
. status
, sfo
. base_grand_total
, sfo
. grand_total
, sfoa
. street
, sfoa
. city
, sfoa
. region
, sfoa
. postcode
, sfoa
. telephone
, sfoa
. country_id
, gfm
_ message
_sales_flat_order_grid
AS内部main_table
加入sales_flat_order_item
.order_id = sales/order_item
.entity_id左加入main_table.entity_id = sfog.entity_id 左加入sfo.entity_id =main_table.entity_id 左加入main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping “在main_table.entity_id = gfm.giftid GROUP BY上左加入。"sales/order_item
main_table
sales_flat_order_grid
sfog
sales_flat_order
sfo
sales_flat_order_address
sfoa
gift_message
gfm
main_table
entity_id
但这不起作用,有人可以帮忙吗???提前致谢