2013-02-08 2 views
0

Я должен упорядочить порядок по группам клиентов в Magento 1.7.0.2, я стараюсь следовать Magento вики:Сортировка заказов по группам клиентов в Magento 1.7

http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/sort_order_by_customer_groups

Но это не работает.

Я копирую приложение/код/​​ядро ​​/ Mage/Adminhtml/Block/Sales/Order/Grid.php для app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php, чтобы не трогать magento core ,

добавить этот код этой функции

protected function _prepareColumns(){ 

$this->addColumn('customer_group_id', array(
       'header'=> Mage::helper('customer')->__('Customer Group'), 
       'width' => '80px', 
       'index' => 'group_id', 
       'renderer' => new Mage_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup(), 
       'type' => 'options', 
       'options' => Mage_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup::getCustomerGroupsArray(), 
     )); 

// now the code original 
} 

Во-вторых, в том же файле добавить эту функцию преодолевания

protected function _addColumnFilterToCollection($column) { 

     if ($this->getCollection()) { 
      $field = ($column->getFilterIndex()) ? $column->getFilterIndex() : $column->getIndex(); 
      if ($column->getFilterConditionCallback()) { 
       call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column); 
      } 
      else { 
       $cond = $column->getFilter()->getCondition(); 
       if ($field && isset($cond)) { 
        if (in_array('NULL', array_values($cond))) { 
         $this->getCollection()->addFieldToFilter($field, array('null' => true)); 
        } 
        else {      
         $this->getCollection()->addFieldToFilter($field, $cond); 
        } 
       } 
      } 
     } 
     return $this; 
    } 

треть, в Grid.php я изменить эту функцию:

protected function _prepareCollection() 
    { 
     $collection = Mage::getResourceModel($this->_getCollectionClass()); 

     $collection->getSelect()->joinLeft(
      array('ce'=>'customer_entity'), 
      'ce.entity_id=main_table.customer_id', 
      array('ce.group_id') 
     ); 
     $this->setCollection($collection); 
     return parent::_prepareCollection(); 
    } 

Теперь я создаю этот файл в app/code/local/Mage/Adminhtml/Block/Sales/Order/Renderer/CustomerGroup.php wi го этого кода:

class Mage_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup 
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { 

    // Holds an associative array with customer_group_id and the associated label 
    private static $_customerGroups = array(); // "singleton" 

    public static function getCustomerGroupsArray() { 
     // Make sure the static property is only populated once 
     if (count(self::$_customerGroups) == 0) { 
      $customer_group = new Mage_Customer_Model_Group(); 
      $customer_groups = $customer_group->getCollection()->toOptionHash(); 
      self::$_customerGroups = $customer_groups; 
     } 

     return self::$_customerGroups; 
    } 

    // Transforms the customer_group_id into corresponding label 
    public function render(Varien_Object $row) 
    { 
     $val = $this->_getValue($row); 
     $customer_groups = self::getCustomerGroupsArray(); 
     return isset($customer_groups[$val]) ? $customer_groups[$val] : false; 
    } 

} 

И у меня есть эта ошибка:

: 5: {я: 0; s: 92: "SQLSTATE [42S22]: Column не найдено: 1054 Неизвестный столбец 'customer_group_id' в 'где п' "я: 1, S: 5645:" # 0 MyProjectFolder \ Lib \ Varien \ Db \ Отчет \ PDO \ Mysql.php (111): Zend_Db_Statement_Pdo -> _ Execute (Array)

Спасибо заранее !

+0

попробовать заменить customer_group_id на group_id в первый код, чтобы соответствовать имени столбца, или добавить псевдоним – dagfr

ответ

0

Я нашел решение в Magento форуме, кто-то дает мне правильное решение:

protected function _prepareCollection() 
{ 
     $collection = Mage::getResourceModel($this->_getCollectionClass()); 

     $collection->getSelect()->join(
      array('oe'=>'sales_flat_order'), 
      'oe.entity_id=main_table.entity_id', 
      array('oe.customer_group_id') 
     ); 
     $this->setCollection($collection); 
     return parent::_prepareCollection(); 
} 
Смежные вопросы