Magento使用事件观察器在订单网格中添加电话号码

时间:2015-01-26 11:30:59

标签: magento events grid

我想添加按订单使用的客户电话号码 - >运费或结算。按顺序网格。我可以在网格中添加标题,但我不知道怎么没有电话。用于此的事件是sales_order_grid_collection_load_before.即使我无法使用此获取订单ID。 这是我的代码。

config.xml中

<?xml version="1.0"?>
<config>
  <modules>
    <Elavarasan_OrderGrid>
      <version>0.1.0</version>
    </Elavarasan_OrderGrid>
  </modules>
  <global>
    <helpers>
      <ordergrid>
        <class>Elavarasan_OrderGrid_Helper</class>
      </ordergrid>
    </helpers>
    <models>
      <ordergrid>
        <class>Elavarasan_OrderGrid_Model</class>
        <resourceModel>ordergrid_mysql4</resourceModel>
      </ordergrid>
    </models>
    <events>
      <core_block_abstract_to_html_before> <!-- identifier of the event we want to catch -->
        <observers>
          <core_block_abstract_to_html_before_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>ordergrid/observer</class> <!-- observers class alias -->
            <method>getGrid</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </core_block_abstract_to_html_before_handler>
        </observers>
      </core_block_abstract_to_html_before>

      <sales_order_grid_collection_load_before> <!-- identifier of the event we want to catch -->
        <observers>
          <sales_order_grid_collection_load_before_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>ordergrid/observer</class> <!-- observers class alias -->
            <method>addPhoneNo</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </sales_order_grid_collection_load_before_handler>
        </observers>
      </sales_order_grid_collection_load_before>
    </events>
  </global>
</config> 

Observer.php

<?php
class Elavarasan_OrderGrid_Model_Observer
{

            public function getGrid(Varien_Event_Observer $observer)
            {
                $block = $observer->getEvent()->getBlock();
                if ($block->getId() == 'sales_order_grid') {
                    $block->addColumnAfter(
                            'telephone',
                            array(
                                    'header'   => Mage::helper('sales')->__('Telephone No'),
                                    'align'    => 'left',
                                    'type'     => 'options',
                                    'options'  => $paymentMethods,
                                    'index'    => 'telephone',
                                    'filter_index' => 'telephone.telephone'
                            ),
                            'shipping_name'
                    );

                    //$block->sortColumnsByOrder();

                }

            }

            public function addPhoneNo(Varien_Event_Observer $observer)
            {
              echo $phone = $observer->getOrder()->getCustomer()->getPrimaryBillingAddress()->getTelephone();

            }

}

请帮帮我们..

1 个答案:

答案 0 :(得分:1)