hook_nodeapi

firewing1's picture
Offline
Joined: 07/07/2009
Juice: 125
hook_nodeapi

It turns out hook_nodeapi is what we are looking for... This sample works for displaying the nodes:

<?php
/**
* Implementation of hook_nodeapi().
*/
function custommod_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
    case
'load':
     
$translations = translation_node_get_translations($node->nid);
     
$language = language_default();
     
$sourcenode = $translations[$language->language];
     
$items = db_fetch_object(db_query('SELECT model, list_price, cost, sell_price, weight, weight_units, length, width, height, length_units, pkg_qty, default_qty, unique_hash, ordering, shippable FROM {uc_products} WHERE vid = %d', $sourcenode->nid));
      if(
$items) {
        foreach(
$items as $field => $value) {
         
$node->$field = $value;
        }
      }
      break;
  }
}
?>

Description of the code: First, it looks up all translations for the node being loaded, which includes the original language, and then determines the site's default language. It then uses the same query that uc_product.module performs to retrieve product data, but uses the node ID of the node in site's default language and overrides the current node's ubercart product values with those from the source node.

It works well, however there are three problems:

  1. Editing a translated product will load the correct values, but clicking "Save" will still store the redundant data.
  2. Adding to this function to also handle the update and insert events (so it only saves product info non-redundantly in the source node) will mean that if a node is deleted, all translated nodes must be deleted with it (as their product data would have gone missing, rendering them useless).
  3. If all the above is done it's pretty much the same thing as i18n sync, so may as well use that. As a bonus i18n sync also handles the CCK fields of your choice, which this method cannot do. It would have to use either all CCK fields, or use manually-programmed queries and either of these choices are not very useful.

i18n issues i D6/UC2 for Multilingual sites By: CpILL (150 replies) Mon, 05/11/2009 - 14:02