2015-04-14 36 views
0

以下代码允许向订单/销售页面添加一列,其中显示送货方式为包含所有送货承运人的送货说明。Magento - 完整性约束违规:1052 - 运输方法

_prepareCollection

$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description')); 

_prepareColumn

$this->addColumn('shipping_method', array(
'header' => Mage::helper('sales')->__('Shipping Method'), 
'index' => 'shipping_description', 
'filter_index' => 'main_table.status', 
)); 

的送货方式似乎完美后,我编译的一切。现在,当我尝试将订单由prcessing排序,并砸在搜索谈到这个错误:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous, query was: SELECT COUNT(*) FROM `sales_flat_order_grid` AS `main_table` INNER JOIN `sales_flat_order` ON main_table.entity_id = sales_flat_order.entity_id WHERE (status = 'processing') 

一些研究,这意味着有当表进行接合的双重身份之后,现在怎么创建一个alians从这个以及如何应用它。此外,如果有人知道过滤/按此列排序的方式会很棒。

PS。该文件位于: 应用程序/代码/本地/法师/ Adminhtml /座/销售/订单

编辑:现在想弄清楚如何选择下拉列表基于数据库中的值来创建。这里是我试图去上班代码:您需要使用自定义渲染

protected function _getAttributeOptions($attribute_code) 
    { 
     $attribute = Mage::getModel('sales/order')->getAttribute('shipping_description', $attribute_code); 
     $options = array(); 
     foreach($attribute->getSource()->getAllOptions(true, true) as $option) { 
      $options[$option['value']] = $option['label']; 
     } 
     return $options; 
} 

回答

1

:在Grid.php

$this->addColumn('shipping_method', array(
    'header' => Mage::helper('sales')->__('Shipping Method'), 
    'renderer' => 'Vehence_Module_Block_Adminhtml_Block_Sales_Order_Desc', 
    'type' => 'options', 
    'options' => Vehence_Module_Block_Adminhtml_Block_Sales_Order_Desc::getDeliveryArray(), 
    )); 

private static $_deliveryGroups = array(); 

public static function getDeliveryArray() { 
if (count(self::$_deliveryGroups) == 0) { 
    $delivery_group = new Mage_Shipping_Model_Group(); 
    $delivery_groups = $delivery_group->getColection()->toOptionHash(); 
    self::$_deliveryGroups = $delivery_groups; 
} 
return self::$_deliveryGroups; 
} 

和附加价值与该为你的新领域。然后在renderer方法中你有orderId。使用该ID,您可以实例化订单对象并获取并输出您喜欢的任何字段。

下面是一个例子:https://magento.stackexchange.com/questions/62856/how-to-get-latest-order-comment-on-the-order-grid-column/62859#62859

class Vendor_Module_Block_Renderer_Shipping extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
{ 
    public function render(Varien_Object $row) 
    { 
     $orderId = $row->getId(); 
     $order = Mage::getModel('sales/order')->load($orderId); 
     return $order->getData('shipping_description'); 
    } 
} 

以下方法(与改写更好)补充一点:

$this->addColumn('history', array(
    'header' => Mage::helper('sales')->__('History status'), 
    'type' => 'text', 
    'renderer' => new Vendor_Module_Block_Renderer_Shipping() 
)); 

upd.1

所以... 我没有应用任何过滤器到我的解决方案。问题在于收集。从外观上看,它看起来很好,但所有的过滤器都应用了不包含必要过滤区域的集合。因为我拒绝了我的解决方案。

因为我认为你的解决方案对于这个目的好得多,我决定修复它。我为该模块创建了git存储库。它应该工作。检查:https://github.com/zhartaunik/AddField

希望这将有助于

+0

你能否详细说明如何创建这个定制的渲染,我不知道有关文件的管理在这方面,如果我可以在grid.php或外部类中创建此 - 在那里将它放置。我真的不想创建一个模块。 – damek132

+0

已更新。我不建议你重写或编辑核心文件。更好地创建新模块。 – zhartaunik

+0

不知道你是否注意到,但我复制了核心文件并使用本地文件夹中的相同文件: app/code/local/Mage/Adminhtml/Block/Sales/Order – damek132

0

您需要添加额外的阵列选项来解决这个问题,即filter_index

$this->addColumn('status', array(
     'header' => Mage::helper('sales')->__('Status'), 
     'index' => 'status', 
     '**filter_index' => 'main_table.status**', 
     'type' => 'options', 
     'width' => '70px', 
     'options' => Mage::getSingleton('sales/order_config')->getStatuses(), 
)); 
相关问题