0

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,
));
8
  • I installed the attribute using that and similar tutorials but I don't how it helps with observing the save event and updating a collection which is separate from customer/address? Specifically, the only hint I can find is the <fieldsets> directives, i.e. <sales_copy_order_billing_address> <jobtitle><to_order>*</to_order></jobtitle> </sales_copy_order_billing_address> which I don't understand.
    – blisstdev
    Oct 30, 2014 at 17:53
  • Normally <fieldsets> <sales_copy_order_billing_address>... should copy it assuming you add the filed to quote address Oct 30, 2014 at 17:58
  • Did not work, see Edit.
    – blisstdev
    Oct 30, 2014 at 18:57

1 Answer 1

1

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>
2
  • Its acceptable of stack exchange to allow self answers feel free to mark as solved.
    – B00MER
    Oct 30, 2014 at 22:09
  • 2 days are over ;) Nov 19, 2014 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.