为什么付款方式没有显示在我的销售>订单网格?
我可以使用付款选项的下拉列表显示列,但付款方式值未显示在订单列表中。
这是生成订单列表的查询:
SELECT `main_table`.*, `payment`.`method`
FROM
`sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order_payment` AS `payment`
ON main_table.entity_id=payment.parent_id
我需要显示值的列名为method
并返回正确的结果,例如worldpay_cc
。这些值从查询返回,但不会显示在网格中。
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->join(array('payment'=>'sales/order_payment'),'main_table.entity_id=payment.parent_id','method');
$collection->addProductData();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array(
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
有什么想法吗?
答案 0 :(得分:1)
我的猜测是你没有正确映射付款方式:
Mage_Adminhtml_Block_Sales_Order_Grid
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array( // <--- The mapping, here
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
我会将上述内容更改为:
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => $this->getActivePaymentMethods()
));
return parent::_prepareColumns();
}
public function getActivePaymentMethods()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array();
foreach ($payments as $paymentCode=>$paymentModel) {
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = $paymentTitle;
}
return $methods;
}
参考我的评论,addProductData
是一个自定义函数:
Mage_Sales_Model_Order_Grid_Collection
public function addProductData($attributesCodes)
{
foreach ($attributesCodes as $attributeCode) {
$attributeTableAlias = $attributeCode . '_table';
$attribute = Mage::getSingleton('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$this->getSelect()->join(
array($attributeTableAlias => $attribute->getBackendTable()),
"main_table.product_id = {$attributeTableAlias}.entity_id AND {$attributeTableAlias}.attribute_id={$attribute->getId()}",
array($attributeCode => 'value')
);
$this->_map['fields'][$attributeCode] = 'value';
}
return $this;
}