Hello David!
I'm creating a modification that gets the product name from the feed, translates it and saves it in the database. This happens with the feed importing process. I've figured some things out but I'm having a hard time finding how to get the product name on the importing process.
As I understood the code for importing is in admin.php, I want to do something like this:
<?php
/* create product record */
$importRecordSQL = "";
foreach($importRecord as $field => $v)
{
$importRecordSQL .= $field."='".database_safe($v)."',";
}
$productname = $importRecordSQL['name'];
?>
$productname being the final, stripped and clean version of the product name, ready to be put in the products and to be translated. This code doesn't work.
How can I fetch the $productname?
Thank you very much, David.
It works but I've been thinking about this and I think that the best way to do this is to duplicate the products MySQL table but with the translated name, description, category, search_name, and normalized_name fields. This will create a very big database but will be easier for me to modify.
Can you help getting all these variables and creating the query that allows me to do this? Something like:
<?php
$merchant=$?
$filename=$?
$name_english=translated($?);
$search_name_translated=no_spaces($name_english);
$normalised_name_translated= ?
$sql2 = "INSERT INTO `".$config_databaseTablePrefix."products_english` SET
merchant='$merchant', filename='$filename',
name='$name_english', search_name='$search_name_translated',
normalised_name='$normalized_name_translated'
//etc...
";
database_queryModify($sql2,$insertId);
?>
Also, where should I put this code so that it will import the information simultaneously as the info to the main product table?
I hope I'm not annoying you with some many questions and posts... This is the cornerstone of my website and would me extremely thankful if you helped me with this.
Regards,
Pedro
Hi Pedro,
Shortly after the SQL is constructed you'll find this code in includes/admin.php, which is where the SQL is actually executed:
if (database_queryModify($sql,$insertId))
{
$admin_importProductCount++;
}
After this point, I would suggest translating whichever fields you wish to do so out of $importRecord; and then duplicate the SQL construction and execution code for your products_english table, for example:
/* create products_english record */
$importRecord["name"] = translated($importRecord["name"]);
$importRecord["description"] = translated($importRecord["description"]);
/* etc. etc. */
$searchName = tapestry_search($importRecord["name"]);
$normalisedName = tapestry_normalise($importRecord["name"]);
$importRecordSQL = "";
foreach($importRecord as $field => $v)
{
$importRecordSQL .= $field."='".database_safe($v)."',";
}
$sql = sprintf("INSERT INTO `".$config_databaseTablePrefix."products_english` SET
merchant='%s',
filename='%s',
%s
search_name='%s',
normalised_name='%s',
dupe_hash='%s'
",
database_safe($merchant),
database_safe($admin_importFeed["filename"]),
$importRecordSQL,
database_safe($searchName),
database_safe($normalisedName),
$dupe_hash
);
if (database_queryModify($sql,$insertId))
{
$admin_importProductCount++;
}
Finally, don't forget to DELETE from products_english when importing a feed - lower down in includes/admin.php you'll find the following code at around line 441:
$sql = "DELETE FROM `".$config_databaseTablePrefix."products` WHERE filename='".database_safe($admin_importFeed["filename"])."'";
database_queryModify($sql,$insertId);
...simply duplicate that section for products_english which should do the trick...
Cheers,
David.
--
PriceTapestry.com
Thank you very much, David. It works great. I just had to take out $admin_importProductCount++;, otherwise it would just import every other product.
Hi,
You actually want to perform your translation immediately before this comment instead of afterwards:
/* create product record */
At that point, the product name will be in
$importRecord["name"]
which is the variable you need to translate!Hope this helps,
Cheers,
David.
--
PriceTapestry.com