Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据订单Magento Admin在销售订单网格中显示礼品消息_Magento_Grid - Fatal编程技术网

根据订单Magento Admin在销售订单网格中显示礼品消息

根据订单Magento Admin在销售订单网格中显示礼品消息,magento,grid,Magento,Grid,伙计们,我对Magento很陌生,有人能帮我吗? 以下是我在管理中获取销售订单网格上的礼品信息的代码: protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); $collection->join('sales/order_item','`sales/order_item`.order_id=`main

伙计们,我对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查询:

选择main_table.*,group_concatsales/order_item.gift_message_available SEPARATOR,AS giftavail,group_concatsales/order_item.gift_message_id SEPARATOR,AS giftid,AS giftid,group_concatsales/order_item.sku SEPARATOR,AS sku,group_concatsales/order_item.name SEPARATOR,AS name,AS name,AS name,AS name,sfog,sfo.shipping_name,sfo.customer_email,sfo.weight,sfo.discount\u description,sfo.increment\u id,sfo.store\u id,sfo.created\u at,sfo.status,sfo.base\u grand\u total,sfo.grand\u total,sfo.street,sfo.city,sfo.region,sfo.postcode,sfo.telephone,sfo.country\u id,gfm.message FROM sales\u flat\u order\u grid AS main\u table内部连接sales\u flat\u order\u商品作为sales/order\u商品作为sales/order\u商品在sales/order\u商品。order\u id=main\u table.entity\u id左连接sales\u flat\u order作为主表上的sfog。entity\u id=sfo主_表上的sfoa.entity_id=sfoa.parent_id和sfoa.address_type=shipping LEFT JOIN gift_消息作为主_表上的gfm.entity_id=gfm.giftid按主_表.entity_id分组

但这不起作用,有人能帮忙吗???
提前感谢

使用以下代码更新您的代码:

protected function _prepareCollection(){

$collection->join(array('order_item'=>'sales/order_item'),'`order_item`.order_id=`main_table`.entity_id',array(
'giftavail' => new Zend_Db_Expr('group_concat(`order_item`.gift_message_available SEPARATOR ",")'),
'giftid' => new Zend_Db_Expr('group_concat(`order_item`.gift_message_id SEPARATOR ",")'),
'skus' => new Zend_Db_Expr('group_concat(`order_item`.sku SEPARATOR ",")'),
'name' => new Zend_Db_Expr('group_concat(`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'),
'order_item.gift_message_id = gfm.gift_message_id',array('gfm.message'));

$this->setCollection($collection);

return parent::_prepareCollection();

}
然后,您将得到工作的sql查询

SELECT `main_table`.*, group_concat(`order_item`.gift_message_available SEPARATOR ",") AS `giftavail`,
group_concat(`order_item`.gift_message_id SEPARATOR ",") AS `giftid`, 
group_concat(`order_item`.sku SEPARATOR ",") AS `skus`,
group_concat(`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` 
FROM `sales_flat_order_grid` AS `main_table` 
INNER JOIN 
   `sales_flat_order_item` AS `order_item` 
ON `order_item`.order_id=`main_table`.entity_id 
LEFT JOIN 
   `sales_flat_order_grid` AS `sfog`
ON main_table.entity_id = sfog.entity_id 
LEFT JOIN 
   `sales_flat_order` AS `sfo` 
ON sfo.entity_id=main_table.entity_id 
LEFT JOIN 
   `sales_flat_order_address` AS `sfoa` 
ON main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping" 
LEFT JOIN 
   `gift_message` AS `gfm` 
ON order_item.gift_message_id = gfm.gift_message_id 
GROUP BY 
   `main_table`.`entity_id`
问题是销售\公寓\订单\项目表alise name和最后一行的礼品信息。您使用的是main_table.giftid而不是order_item.gift_message_id


希望会有帮助

在$this->setCollection$collection之前;行打印$collection->getSelect;出口并手动运行该sql查询。然后共享,如果收到任何错误。当我在数据库中运行该查询时,我会收到以下错误:“1054-未知列”main_table.giftid“in”on clausecan you share sql query?我收到的是与订单相关的礼品消息Id,但我想要与该礼品消息相关的消息。。。有人知道吗??