Question

I have a custom customer/address attribute gmap_lat which I would like to be included in the sales/order_address_collection.

I would like to observe the customer_address_save_before event, but it isn't dispatched and I'm not sure how to hook into the Observer:

magento\app\code\core\Mage\Customer\etc\config.xml:

422              <customer_address_save_before>
423                  <observers>
424:                     <customer_address_before_save_viv_observer>
425                          <class>customer/observer</class>
426                          <method>beforeAddressSave</method>
427:                     </customer_address_before_save_viv_observer>
428                  </observers>
429              </customer_address_save_before>

Should I make my own observer in addition to this one, or extend the customer/observer or what? What is the best and fastest approach here?

** EDIT **:

By the way, this attribute is HIDDEN, installed in part by:

//Add attribute that will be used for Google Maps as a coordinate lat
$installer->addAttribute('customer_address', 'gmap_lat', array(
    'type'     => 'varchar',
    'input'    => 'hidden',
    'visible'  => false,
    'required' => false,
    'label'    =>   'GMap Latitude',
    'user_defined' => 0,
    'visible_on_front' => 0,
));
Was it helpful?

Solution

R.S made me realize my question didn't make sense anyway, and he directed me to the right answer.

No one should want to update the sales/order_address_collection on save! I was getting confused between installing the attributes for the first time and how the attributes should work in the future.

If one installs the attribute as shown in http://www.magentocommerce.com/wiki/5_-_modules_and_development/how_to_add_custom_field_in_billing_and_shipping_address_in_frontend_and_backend

Then this config file will correctly copy an attribute (here called gmap_lat and gmap_lng) to and from customer_address and sales_flat_order_address, sales_flat_quote_address, at the appropriate times (during checkout).

<global>
  <resources>
  <sw_firsttime_setup>
      <setup>
          <module>StrollingWild_FirstTimeCustomer</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
      </setup>
      <connection>
          <use>core_setup</use>
      </connection>
  </sw_firsttime_setup>
  <sw_firsttime_write>
      <connection>
          <use>core_write</use>
      </connection>
  </sw_firsttime_write>
  <sw_firsttime_read>
      <connection>
          <use>core_read</use>
      </connection>
  </sw_firsttime_read>
 </resources>
  <helpers>
  <firsttimecustomer>
      <class>StrollingWild_FirstTimeCustomer_Helper</class>
  </firsttimecustomer>
 </helpers>
  <admin>
    <fieldsets>
        <customer_dataflow>
             <gmap_lng><billing>1</billing><shipping>1</shipping></gmap_lng>
             <gmap_lat><billing>1</billing><shipping>1</shipping></gmap_lat>
        </customer_dataflow>
    </fieldsets>
 </admin>
<fieldsets>
  <customer_address>
    <gmap_lat><to_quote_address>*</to_quote_address></gmap_lat>
    <gmap_lng><to_quote_address>*</to_quote_address></gmap_lng>
  </customer_address>
  <sales_copy_order_billing_address>
    <gmap_lat><to_order>*</to_order></gmap_lat>
    <gmap_lng><to_order>*</to_order></gmap_lng>
  </sales_copy_order_billing_address>
  <sales_copy_order_shipping_address>
    <gmap_lat><to_order>*</to_order></gmap_lat>
    <gmap_lng><to_order>*</to_order></gmap_lng>
  </sales_copy_order_shipping_address>
<sales_convert_quote_address>
    <gmap_lat>
      <to_order_address>*</to_order_address>
      <to_customer_address>*</to_customer_address>
    </gmap_lat>
    <gmap_lng>
      <to_order_address>*</to_order_address>
      <to_customer_address>*</to_customer_address>
    </gmap_lng>
 </sales_convert_quote_address>
<sales_convert_order_address>
    <gmap_lat><to_quote_address>*</to_quote_address></gmap_lat>
    <gmap_lng><to_quote_address>*</to_quote_address></gmap_lng>
</sales_convert_order_address>
 </fieldsets>
</global>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top