0

magento1.7のSales_Order_Gridに配送または請求の郵便番号を追加する方法を探しています

いくつかの異なる方法を試しましたが、これまでのところ、カスタム列を検索しようとすると、エラーが発生するか、メインダッシュボードにリダイレクトされます。

これを行うためのモジュールを作成しましたが、ページにアクセスしようとするとエラーが発生します。

リクエストの処理中にエラーが発生しましたセキュリティ上の理由から、例外の印刷はデフォルトで無効になっています。

エラーログレコード番号:903668493355

   a:5:{i:0;s:92:"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'shipping_postcode' in 'where clause'";i:1;s:6422:"#0 /var/www/mysite.com/htdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /var/www/mysite.com/htdocs/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /var/www/mysite.com/htdocs/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /var/www/mysite.com/htdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT COUNT(*)...', Array)
#4 /var/www/mysite.com/htdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('SELECT COUNT(*)...', Array)
#5 /var/www/mysite.com/htdocs/lib/Zend/Db/Adapter/Abstract.php(825): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
#6 /var/www/mysite.com/htdocs/lib/Varien/Data/Collection/Db.php(225): Zend_Db_Adapter_Abstract->fetchOne(Object(Varien_Db_Select), Array)
#7 /var/www/mysite.com/htdocs/lib/Varien/Data/Collection.php(225): Varien_Data_Collection_Db->getSize()
#8 /var/www/mysite.com/htdocs/lib/Varien/Data/Collection.php(211): Varien_Data_Collection->getLastPageNumber()
#9 /var/www/mysite.com/htdocs/lib/Varien/Data/Collection/Db.php(516): Varien_Data_Collection->getCurPage()
#10 /var/www/mysite.com/htdocs/lib/Varien/Data/Collection/Db.php(563): Varien_Data_Collection_Db->_renderLimit()
#11 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(533): Varien_Data_Collection_Db->load()
#12 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php(61): Mage_Adminhtml_Block_Widget_Grid->_prepareCollection()
#13 /var/www/mysite.com/htdocs/app/code/local/Thaneuk/CustomGrid/Block/Adminhtml/Sales/Order/Grid.php(25): Mage_Adminhtml_Block_Sales_Order_Grid->_prepareCollection()
#14 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(626): Thaneuk_CustomGrid_Block_Adminhtml_Sales_Order_Grid->_prepareCollection()
#15 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(632): Mage_Adminhtml_Block_Widget_Grid->_prepareGrid()
#16 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(862): Mage_Adminhtml_Block_Widget_Grid->_beforeToHtml()
#17 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(582): Mage_Core_Block_Abstract->toHtml()
#18 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(526): Mage_Core_Block_Abstract->_getChildHtml('grid', true)
#19 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php(77): Mage_Core_Block_Abstract->getChildHtml('grid')
#20 /var/www/mysite.com/htdocs/app/design/adminhtml/default/default/template/widget/grid/container.phtml(36): Mage_Adminhtml_Block_Widget_Grid_Container->getGridHtml()
#21 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/uk-dev...')
#22 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#23 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#24 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#25 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Widget/Container.php(308): Mage_Adminhtml_Block_Template->_toHtml()
#26 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(863): Mage_Adminhtml_Block_Widget_Container->_toHtml()
#27 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#28 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(863): Mage_Core_Block_Text_List->_toHtml()
#29 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(582): Mage_Core_Block_Abstract->toHtml()
#30 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(526): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#31 /var/www/mysite.com/htdocs/app/design/adminhtml/default/default/template/page.phtml(74): Mage_Core_Block_Abstract->getChildHtml('content')
#32 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/uk-dev...')
#33 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#34 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#35 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/Block/Template.php(81): Mage_Core_Block_Template->_toHtml()
#36 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Block/Abstract.php(863): Mage_Adminhtml_Block_Template->_toHtml()
#37 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#38 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#39 /var/www/mysite.com/htdocs/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php(95): Mage_Core_Controller_Varien_Action->renderLayout()
#40 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Adminhtml_Sales_OrderController->indexAction()
#41 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#42 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#43 /var/www/mysite.com/htdocs/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#44 /var/www/mysite.com/htdocs/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#45 /var/www/mysite.com/htdocs/index.php(87): Mage::run('', 'store')
#46 {main}";s:3:"url";s:29:"/index.php/admin/sales_order/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}

郵便番号の列を検索して正しい注文データを取得する必要があるので、私を助けてくれる人はいますか?!?

      <?php
class Thaneuk_CustomGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
public function __construct()
    {
        parent::__construct();
        $this->setId('sales_order_grid');
        $this->setUseAjax(true);
        $this->setDefaultSort('created_at');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
    }

    protected function _getCollectionClass()
    {

        return 'sales/order_grid_collection';
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id AND sales_flat_order_address.address_type =           shipping',array('postcode'));
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {

        $this->addColumn('real_order_id', array(
            'header'=> Mage::helper('sales')->__('Order #'),
            'width' => '80px',
            'type'  => 'text',
            'index' => 'increment_id',
        ));

        if (!Mage::app()->isSingleStoreMode()) {
            $this->addColumn('store_id', array(
                'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
                'index'     => 'store_id',
                'type'      => 'store',
                'store_view'=> true,
                'display_deleted' => true,
            ));
        }

        $this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Purchased On'),
            'index' => 'created_at',
            'type' => 'datetime',
            'width' => '100px',
        ));

        $this->addColumn('billing_name', array(
            'header' => Mage::helper('sales')->__('Bill to Name'),
            'index' => 'billing_name',
        ));

        $this->addColumn('shipping_name', array(
            'header' => Mage::helper('sales')->__('Ship to Name'),
            'index' => 'shipping_name',
        )); 

        $this->addColumnAfter('shipping_postcode', array(
        'header' => Mage::helper('sales')->__('Shipping Postcode'),
         'filter_index'=>'main_table.postcode',
        'index' => 'shipping_postcode',
        ),'method');

        $this->addColumn('base_grand_total', array(
            'header' => Mage::helper('sales')->__('G.T. (Base)'),
            'index' => 'base_grand_total',
            'type'  => 'currency',
            'currency' => 'base_currency_code',
        ));

        $this->addColumn('grand_total', array(
            'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
            'index' => 'grand_total',
            'type'  => 'currency',
            'currency' => 'order_currency_code',
        ));

        $this->addColumn('status', array(
            'header' => Mage::helper('sales')->__('Status'),
            'index' => 'status',
            'type'  => 'options',
            'width' => '70px',
            'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
        ));

        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
            $this->addColumn('action',
                array(
                    'header'    => Mage::helper('sales')->__('Action'),
                    'width'     => '50px',
                    'type'      => 'action',
                    'getter'     => 'getId',
                    'actions'   => array(
                        array(
                            'caption' => Mage::helper('sales')->__('View'),
                            'url'     => array('base'=>'*/sales_order/view'),
                            'field'   => 'order_id'
                        )
                    ),
                    'filter'    => false,
                    'sortable'  => false,
                    'index'     => 'stores',
                    'is_system' => true,
            ));
        }

        $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
        $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));

        return parent::_prepareColumns();
    }

        protected function _prepareMassaction()
    {
        $this->setMassactionIdField('entity_id');
        $this->getMassactionBlock()->setFormFieldName('order_ids');
        $this->getMassactionBlock()->setUseSelectAll(false);

        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
            $this->getMassactionBlock()->addItem('cancel_order', array(
                 'label'=> Mage::helper('sales')->__('Cancel'),
                 'url'  => $this->getUrl('*/sales_order/massCancel'),
            ));
        }

        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
            $this->getMassactionBlock()->addItem('hold_order', array(
                 'label'=> Mage::helper('sales')->__('Hold'),
                 'url'  => $this->getUrl('*/sales_order/massHold'),
            ));
        }

        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
            $this->getMassactionBlock()->addItem('unhold_order', array(
                 'label'=> Mage::helper('sales')->__('Unhold'),
                 'url'  => $this->getUrl('*/sales_order/massUnhold'),
            ));
        }

        $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
             'label'=> Mage::helper('sales')->__('Print Invoices'),
             'url'  => $this->getUrl('*/sales_order/pdfinvoices'),
        ));

        $this->getMassactionBlock()->addItem('pdfshipments_order', array(
             'label'=> Mage::helper('sales')->__('Print Packingslips'),
             'url'  => $this->getUrl('*/sales_order/pdfshipments'),
        ));

        $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
             'label'=> Mage::helper('sales')->__('Print Credit Memos'),
             'url'  => $this->getUrl('*/sales_order/pdfcreditmemos'),
        ));

        $this->getMassactionBlock()->addItem('pdfdocs_order', array(
             'label'=> Mage::helper('sales')->__('Print All'),
             'url'  => $this->getUrl('*/sales_order/pdfdocs'),
        ));

        $this->getMassactionBlock()->addItem('print_shipping_label', array(
             'label'=> Mage::helper('sales')->__('Print Shipping Labels'),
             'url'  => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'),
        ));

        return $this;
    }

    public function getRowUrl($row)
    {
        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
            return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
        }
        return false;
    }

    public function getGridUrl()
    {
        return $this->getUrl('*/*/grid', array('_current'=>true));
    }

}

ヘルプは常にありがたいです。

4

3 に答える 3

1

where句エラーで不明な列が表示された場合は、このコードを試してください

 $this->addColumnAfter('shipping_postcode', array(
        'header' => Mage::helper('sales')->__('Shipping Postcode'),
         'filter_index'=>'main_table.postcode',
        'index' => 'shipping_postcode',
    ),'method');

グリッド列コードにfilter_indexパラメーターを指定します。それはあなたの問題を解決します。

于 2013-03-11T11:29:14.410 に答える
1

sales_flat_order_addressのそのフィールドの固有名はではありpostcodeません'shipping_postcode'。(Magento CE 1.7をチェック)。

address_type = 'shipping'郵便番号を請求ではなく配送から取得するために、WHERE句を追加することもできます。

メソッドを修正します_prepareCollection()

于 2013-03-11T11:31:36.640 に答える
1
Before return parent::_prepareCollection(); You should create a join:
$collection->getSelect()->joinLeft(array('billing'=>'sales_flat_order_address'),
    'main_table.entity_id = billing.parent_id AND billing.address_type="billing"',array('billing.postcode AS bp'));
And in the method _prepareColumns paste:
$this->addColumn('bp', array(
        'header' => Mage::helper('sales')->__('Billing Postcode'),
        'index' => 'bp',
        'width' => '60px',
        'filter_index'  => 'billing.postcode'
    ));
于 2014-12-26T11:20:29.790 に答える