【问题标题】:magento add column with coupon code in orders gridmagento 在订单网格中添加带有优惠券代码的列
【发布时间】:2015-04-22 07:39:42
【问题描述】:

我在订单网格中添加到带有优惠券代码的列时遇到问题。我在http://www.atwix.com/magento/customize-orders-grid/ 上使用了教程。

我将 Grid.php 从 /app/code/core/Mage/Adminhtml/Block/Sales/Order/ 复制到 /app/code/local/Mage/Adminhtml/Block/Sales/Order/ 并添加了以下代码:

$select->join('sales_flat_order', '`sales_flat_order`.entity_id = `main_table`.entity_id',array('coupon_code')) 

到函数_prepareCollection() 并在函数_prepareColumns() 中添加列:

$this->addColumn('coupon_code', array(
      'header' => Mage::helper('sales')->__('Coupon Coded'),
           'index' => 'coupon_code'
   ));

但在管理员页面上的销售/订单上没有显示任何内容。有谁知道什么时候可能是问题?

感谢您的意见/想法。

【问题讨论】:

  • 你的代码是对的,检查app/etc/local.xml中是否启用了本地模块并尝试清空缓存
  • 谢谢。它可能是缓存,现在是一个带有优惠券代码的新列,但如果我按特定订单排序。告诉我这个错误 SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'increment_id' in where 子句不明确

标签: php magento


【解决方案1】:
protected function _prepareCollection() { 
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order',
                'main_table.entity_id = sales_flat_order.entity_id',
                array('coupon_code' => 'coupon_code'));        
        $this->setCollection($collection);
       //For sort
        Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}

【讨论】:

    【解决方案2】:

    尝试将您添加到 _prepareCollection() 函数的代码替换为以下代码:

        $adapter = $collection->getResource()->getReadConnection();
        $subSelect = $adapter->select()
            ->from(array('sales_flat_order'), array('entity_id', 'coupon_code'));
    
        $collection->getSelect()
            ->join(array('order' => $subSelect), '`order`.entity_id = `main_table`.entity_id',array('coupon_code'));
    

    【讨论】:

      【解决方案3】:

      现在是一个带有优惠券代码的新列,但如果我按特定订单排序。显示此错误 SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'increment_id' in where 子句不明确

      【讨论】:

      • 您是否尝试过我们之前回答中描述的解决方案?
      【解决方案4】:

      如果你有不明确的列错误,试试这个:

      protected function _addColumnFilterToCollection($column)
      {
          if ($this->getCollection()) {
              $field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
              $field = 'main_table.'.$field;
              if ($column->getFilterConditionCallback()) {
                  call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
              } else {
                  $cond = $column->getFilter()->getCondition();
                  if ($field && isset($cond)) {
                      $this->getCollection()->addFieldToFilter($field , $cond);
                  }
              }
          }
          return $this;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-17
        • 1970-01-01
        • 1970-01-01
        • 2015-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多