I'm looking at setting up an Ubercart [UC] store which will be in more than one language. The ussue is that admins can create their own product types in UC and these act as their own types. The i18nsync (Synchronization) modules readme.txt states:

The available list of fields to synchronize will include standard node fields and cck fields.
To have aditional fields, add the list in a variable in the settings.php file, like this:
...

// More fields for a specific content type 'nodetype' only.
$conf['i18nsync_fields_node_nodetype'] = array(
  'field3' => t('Field 3 name'),
   ...
);

Which is fine if you have a static type.

Well, actually even then this is far from automatic and doesn't give module authors the chance to integrate and take car of this for the use, and the module author is really the one who knows best about fields their types have and changes to those fields in the future. Also this approach makes handling dynamic types error prone.

I was thinking it would be much easier to just define a hook that returns this array, thus handing the job over to the module author and letting them be as tricky as they like. Something like:

i18nsync_get_fields()
{
    return module_invoke_all('i18n_get_fields');
}

I guess cache the results per request... what do you think?

Comments

mathieu’s picture

Subscribe.

Jose Reyero’s picture

Version: master » 6.x-1.x-dev
Status: Needs review » Fixed

Added an alter hook, this should be more flexible as it allows adding/changing/removing fields. And caching too, as suggested.

I think this should work for this and other casses, let me know if we need anything else.

/**
 * Returns list of available fields for given content type.
 * 
 * There are two hidden variables (without UI) that can be used to add fields
 * with the form array('field' => 'Field name')
 *  - i18nsync_fields_node
 *  - i18nsync_fields_node_$type;
 * 
 * Variables can also be changed using hook_i18nsync_fields_alter($fields, $type)
 * 
 * @param $type
 *   Node type.
 */
function i18nsync_node_available_fields($type) {}
cpill’s picture

Thanks Jose, I'm not exactly clear how this is to work. Is there some module that is using this as an example?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

cpill’s picture

Category: feature » task
Status: Closed (fixed) » Active

Need some examples here. This is important to Ubercart developers trying to do multi-lingual shops as many variables for a Product node are handled by other modules in other forms...?

asak’s picture

subscribing. i'll try to help but i'm not sure i totally understand what we're doing here... ;)

Docc’s picture

You can use the new hook to add additional fields

like so:

function hook_i18nsync_fields_alter($fields, $type) {
  $fields['uc_products']['#title'] = 'Products';
  $fields['uc_products']['#options'] = array ('model' => 'SKU');
}

Didnt really test it yet but it seems to me this will work for normal text fields but things like attributes etc would require a litle bit more.

keereel’s picture

Can someone help me to configure sync for "Features" field (for downloadable product) and for "Sell price"?

keereel’s picture

please, help me

Bartezz’s picture

Keereel, have a read here; http://www.firewing1.com/node/27

Cheers

longwave’s picture

Status: Active » Fixed

This is now supported in Ubercart 6.x-2.x-dev.

#894760: Synchronize product data across translated nodes

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.