Virtuemart 3.2 bug on translate Product with child products

Started by Jordi B, March 25, 2017, 12:20:27 PM

Previous topic - Next topic

Jordi B

I recently updated my site to Virtuemart 3.2 and now the translation of  products with children is not working.
In the new version when you select a new language the ajax function gets the translation from the parent and all his children products and the result is that the fields are filled with the data of last children.
After reviewing the code I have found the following solution. In Javascript file /administration/components/com_virtuemart/assets/js/vmlang.js there are the functions that make the update. In function updateLaguageValues I check if a field is yet translated with parent data in order not to override the correct information.
The code with the solution is :
function updateLanguageValues(data, langCode, flagClass) {
var items = [];

var theForm = document.forms["adminForm"];
if(typeof theForm.vmlang==="undefined"){
var input = document.createElement("input");
input.type = "hidden";
input.name = "vmlang";
input.value = langCode;
theForm.appendChild(input);
} else {
theForm.vmlang.value = langCode;
}
if (data.fields !== "error" ) {
var cible = null;
var tmce_ver = 0;
if(typeof window.tinyMCE!=="undefined"){
var tmce_ver=window.tinyMCE.majorVersion;
}

if (data.structure == "empty") alert(data.msg);
jQuery.each(data.fields , function(key, val) {
cible = jQuery("#"+key);
if (window.oldflag !== "") jQuery('.allflags').removeClass(window.oldflag)
if (! cible.parent().hasClass(flagClass))
{
if (tmce_ver>="4") {
if ((cible.parent().addClass('allflags '+flagClass).children().hasClass("mce_editable") || cible.parent().children().hasClass("wf-editor")) && data.structure !== "empty" ) {
tinyMCE.get(key).execCommand("mceSetContent", false,val);
cible.val(val);
} else if (data.structure !== "empty") cible.val(val);
} else {
if (cible.parent().addClass('allflags '+flagClass).children().hasClass("mce_editable") && data.structure !== "empty" ) {
tinyMCE.execInstanceCommand(key,"mceSetContent",false,val);
cible.val(val);
} else if (data.structure !== "empty") cible.val(val);
}
}
//custom for child products:
if (typeof data.requested_id != 'undefined')
if (key == 'product_name') {
var cible = jQuery("#child"+data.requested_id+"product_name");

cible.parent().addClass('allflags '+flagClass);
cible.val(data.fields.product_name);
jQuery("#child"+data.requested_id+"slug").val(data.fields["slug"]);
}
});



} else {
alert(data.msg);
}


}


I hope that in the new version this bug is solved, I don't like to override core code.

Milbo

I just tried it and it works for me to rename children in the children tab, when I use a product with generic child variants. I stored both languages with 3 children and anything works.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jordi B

Yes but, the problem is not to translate the children in children tab, the problem is translate the parent when it has children. If the information of last children (name, description ...) is different from parent this information override the parent information when select the second language. When I debug Javascript in function updateLanguageVars after the ajax request I get in data.multiple and array with parent information in data.multiple[0] and children information in data.multiple[1]. The function call updateLanguageValues first with parent information data.multiple[0] after that all information in the page is correct but then call again updateLanguageValues with children data.multiple[1] and all fields are override with the children data and this second call fill also the information for that children in children tab. If this is not the normal behaviour I don't know where I have the problem.

Jordi Buscallà

Milbo

Ahh, yes, thank you. Good explanation, could reproduce it directly. So you just added this? yes?

if (! cible.parent().hasClass(flagClass))
{

seems to work.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jordi B

Yes, with this line we control if the field has translated yet and not override it.