Advertisement
Guest User

ucxfdev_ucaddresses.module

a guest
Jul 26th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.17 KB | None | 0 0
  1. <?php
  2. // $Id$
  3. /**
  4.  * @file
  5.  * I could not yet find a way to complete UC Addresses integration
  6.  * for Extra Fields Pane without modifying UC Addresses.
  7.  *
  8.  * This module, together with the attached patch will make UC Addresses
  9.  * integration for Extra Fields Pane complete.
  10.  * I see this as a temporary solution, UC Addresses should be modified
  11.  * in a better and nicer way than the way I have done it now.
  12.  * See also http://drupal.org/node/851658
  13.  *
  14.  * Apply these patches on UC Addresses (v1.0):
  15.  * - 851658-uc_addresses_MC_001.patch
  16.  */
  17.  
  18. // -------------------------------------------------------------------
  19. // DRUPAL HOOKS
  20. // -------------------------------------------------------------------
  21.  
  22. // MegaChriz: already available in uc_extra_fields_pane, but code of this module also must be executed after uc_addresses.
  23. /**
  24.  * Implementation of hook_enable().
  25.  * Make sure code of this module is executed after 'uc_addresses' (if available)
  26.  */
  27. function ucxfdev_ucaddresses_enable() {
  28.   // Get weight of uc_addresses module
  29.   $sQuery = "SELECT weight
  30.  FROM {system}
  31.  WHERE name = 'uc_addresses'
  32.  AND type = 'module'
  33.  ";
  34.   $iWeight = db_result(db_query($sQuery)) + 8;
  35.  
  36.   // Increase the weight of this module, making it 8 heavier then uc_addresses.
  37.   db_query("UPDATE {system} SET weight = %d WHERE name = 'ucxfdev_ucaddresses' AND type = 'module'", $iWeight);
  38. }
  39.  
  40. // -------------------------------------------------------------------
  41. // UBERCART HOOKS
  42. // -------------------------------------------------------------------
  43.  
  44. /**
  45.  * Implementation of hook_uc_checkout_complete().
  46.  * Saves extra address values for uc_addresses when order is complete.
  47.  * @param object $order
  48.  * @param object $user
  49.  * @return void
  50.  */
  51. function ucxfdev_ucaddresses_uc_checkout_complete($order, $user) {
  52.   $addresstypes = array('billing', 'delivery');
  53.  
  54.   foreach ($addresstypes as $addresstype) {
  55.     if ($order->{$addresstype . '_address_id'}) {
  56.       // Save extra values for this address
  57.       $fields = uc_extra_fields_pane_load_fields_from_db('extra_' . $addresstype);
  58.  
  59.       // Save values
  60.       foreach ($fields as $fieldname => $field) {
  61.         uc_extra_fields_pane_value_save(
  62.           array(
  63.             'element_id' => $order->{$addresstype . '_address_id'},
  64.             'element_type' => UCXF_VALUE_ADDRESS,
  65.             'field_id' => $field->field_id,
  66.             'value' => check_plain($order->extra_fields[$fieldname . '_' . $addresstype]),
  67.           )
  68.         );
  69.       }
  70.     }
  71.   }
  72. }
  73.  
  74. // -------------------------------------------------------------------
  75. // THEMING
  76. // -------------------------------------------------------------------
  77.  
  78. /**
  79.  * Implementation of hook_theme().
  80.  */
  81. function ucxfdev_ucaddresses_theme() {
  82.   return array(
  83.     'ucxfdev_ucaddresses_list_address' => array(
  84.       'arguments' => array('address' => NULL, 'panes' => array()),
  85.     ),
  86.   );
  87. }
  88.  
  89. /**
  90.  * Theming an address on address list page to show values of extra address fields.
  91.  * In order to show the extra values, override theme_uc_addresses_list_address()
  92.  * in your theme and call this function there.
  93.  *
  94.  * EXAMPLE:
  95.  * function mytheme_uc_addresses_list_address($address, $panes) {
  96.  *   return theme('ucxfdev_ucaddresses_list_address', $address, $panes);
  97.  * }
  98.  *
  99.  * @param object $address
  100.  * @param array $panes
  101.  * @return string
  102.  */
  103. function theme_ucxfdev_ucaddresses_list_address($address, $panes) {
  104.   $fields = uc_extra_fields_pane_load_fields_from_db('extra_address');
  105.   $values = uc_extra_fields_pane_value_list_load($address->aid, UCXF_VALUE_ADDRESS);
  106.  
  107.   // Get address pane with id address
  108.   $addresspanes = _address_pane_list();
  109.   foreach ($addresspanes as $addresspane) {
  110.     if ($addresspane['id'] == 'address') {
  111.       // Display value of each extra address field
  112.       foreach ($values as $fieldname => $aValue) {
  113.         // Only display if value is not empty
  114.         if ($aValue['value'] !== '') {
  115.           $panes[$addresspane['title']][] = array(
  116.             'title' => t($fields[$fieldname]->label),
  117.             'data' => $aValue['value'],
  118.           );
  119.         }
  120.       }
  121.     }
  122.   }
  123.   return theme_uc_addresses_list_address($address, $panes);
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement