Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $Id$
- /**
- * @file
- * I could not yet find a way to complete UC Addresses integration
- * for Extra Fields Pane without modifying UC Addresses.
- *
- * This module, together with the attached patch will make UC Addresses
- * integration for Extra Fields Pane complete.
- * I see this as a temporary solution, UC Addresses should be modified
- * in a better and nicer way than the way I have done it now.
- * See also http://drupal.org/node/851658
- *
- * Apply these patches on UC Addresses (v1.0):
- * - 851658-uc_addresses_MC_001.patch
- */
- // -------------------------------------------------------------------
- // DRUPAL HOOKS
- // -------------------------------------------------------------------
- // MegaChriz: already available in uc_extra_fields_pane, but code of this module also must be executed after uc_addresses.
- /**
- * Implementation of hook_enable().
- * Make sure code of this module is executed after 'uc_addresses' (if available)
- */
- function ucxfdev_ucaddresses_enable() {
- // Get weight of uc_addresses module
- $sQuery = "SELECT weight
- FROM {system}
- WHERE name = 'uc_addresses'
- AND type = 'module'
- ";
- $iWeight = db_result(db_query($sQuery)) + 8;
- // Increase the weight of this module, making it 8 heavier then uc_addresses.
- db_query("UPDATE {system} SET weight = %d WHERE name = 'ucxfdev_ucaddresses' AND type = 'module'", $iWeight);
- }
- // -------------------------------------------------------------------
- // UBERCART HOOKS
- // -------------------------------------------------------------------
- /**
- * Implementation of hook_uc_checkout_complete().
- * Saves extra address values for uc_addresses when order is complete.
- * @param object $order
- * @param object $user
- * @return void
- */
- function ucxfdev_ucaddresses_uc_checkout_complete($order, $user) {
- $addresstypes = array('billing', 'delivery');
- foreach ($addresstypes as $addresstype) {
- if ($order->{$addresstype . '_address_id'}) {
- // Save extra values for this address
- $fields = uc_extra_fields_pane_load_fields_from_db('extra_' . $addresstype);
- // Save values
- foreach ($fields as $fieldname => $field) {
- uc_extra_fields_pane_value_save(
- array(
- 'element_id' => $order->{$addresstype . '_address_id'},
- 'element_type' => UCXF_VALUE_ADDRESS,
- 'field_id' => $field->field_id,
- 'value' => check_plain($order->extra_fields[$fieldname . '_' . $addresstype]),
- )
- );
- }
- }
- }
- }
- // -------------------------------------------------------------------
- // THEMING
- // -------------------------------------------------------------------
- /**
- * Implementation of hook_theme().
- */
- function ucxfdev_ucaddresses_theme() {
- return array(
- 'ucxfdev_ucaddresses_list_address' => array(
- 'arguments' => array('address' => NULL, 'panes' => array()),
- ),
- );
- }
- /**
- * Theming an address on address list page to show values of extra address fields.
- * In order to show the extra values, override theme_uc_addresses_list_address()
- * in your theme and call this function there.
- *
- * EXAMPLE:
- * function mytheme_uc_addresses_list_address($address, $panes) {
- * return theme('ucxfdev_ucaddresses_list_address', $address, $panes);
- * }
- *
- * @param object $address
- * @param array $panes
- * @return string
- */
- function theme_ucxfdev_ucaddresses_list_address($address, $panes) {
- $fields = uc_extra_fields_pane_load_fields_from_db('extra_address');
- $values = uc_extra_fields_pane_value_list_load($address->aid, UCXF_VALUE_ADDRESS);
- // Get address pane with id address
- $addresspanes = _address_pane_list();
- foreach ($addresspanes as $addresspane) {
- if ($addresspane['id'] == 'address') {
- // Display value of each extra address field
- foreach ($values as $fieldname => $aValue) {
- // Only display if value is not empty
- if ($aValue['value'] !== '') {
- $panes[$addresspane['title']][] = array(
- 'title' => t($fields[$fieldname]->label),
- 'data' => $aValue['value'],
- );
- }
- }
- }
- }
- return theme_uc_addresses_list_address($address, $panes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement