Hi mate, thanks for looking
the field I am trying to add is called mediacat_part_no
I think I have got all the sections of code covered where it needs to be added.
Code:
while ($row){
// OK, since we got a row, the item already exists.
// Let's get all the data we need and fill in all the fields that need to be defaulted to the current values
// for each language, get the description and set the vals
foreach ($langcode as $key => $lang){
$sql2 = "SELECT *
FROM ".TABLE_PRODUCTS_DESCRIPTION."
WHERE
products_id = " . $row['v_products_id'] . " AND
language_id = '" . $lang['id'] . "'
";
$result2 = tep_db_query($sql2);
$row2 = tep_db_fetch_array($result2);
// Need to report from ......_name_1 not ..._name_0
$row['v_products_name_' . $lang['id']] = $row2['products_name'];
$row['v_products_description_' . $lang['id']] = $row2['products_description'];
$row['v_mediacat_part_no_' . $lang['id']] = $row2['mediacat_part_no'];
$row['v_products_url_' . $lang['id']] = $row2['products_url'];
// support for Header Controller 2.1 here
if(isset($filelayout['v_products_head_title_tag_' . $lang['id'] ])){
$row['v_products_head_title_tag_' . $lang['id']] = $row2['products_head_title_tag'];
$row['v_products_head_desc_tag_' . $lang['id']] = $row2['products_head_desc_tag'];
$row['v_products_head_keywords_tag_' . $lang['id']] = $row2['products_head_keywords_tag'];
}
// end support for Header Controller 2.0
}
Code:
// Begin writting new data to current data
// this is an important loop. What it does is go thru all the fields in the incoming file and set the internal vars.
// Internal vars not set here are either set in the loop above for existing records, or not set at all (null values)
// the array values are handled separatly, although they will set variables in this loop, we won't use them.
foreach( $filelayout as $key => $value ){
$$key = $items[ $value ];
}
// so how to handle these? we shouldn't built the array unless it's been giving to us.
// The assumption is that if you give us names and descriptions, then you give us name and description for all applicable languages
foreach ($langcode as $lang){
$l_id = $lang['id'];
if (isset($filelayout['v_products_name_' . $l_id ])){
//we set dynamically the language values
$v_products_name[$l_id] = tep_db_encoder($items[$filelayout['v_products_name_' . $l_id]]);
$v_products_description[$l_id] = tep_db_encoder($items[$filelayout['v_products_description_' . $l_id ]]);
$v_mediacat_part_no = tep_db_encoder($items[$filelayout['v_mediacat_part_no']]);
$v_products_url[$l_id] = $items[$filelayout['v_products_url_' . $l_id ]];
$v_products_head_title_tag[$l_id] = $items[$filelayout['v_products_head_title_tag_' . $l_id]];
$v_products_head_desc_tag[$l_id] = $items[$filelayout['v_products_head_desc_tag_' . $l_id]];
$v_products_head_keywords_tag[$l_id] = $items[$filelayout['v_products_head_keywords_tag_' . $l_id]];
}
}
Code:
// the following is common in both the updating an existing product and creating a new product
if ( isset($v_products_name)){
foreach( $v_products_name as $key => $name){
if ($name!=''){
$sql = "SELECT * FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE
products_id = $v_products_id AND
language_id = " . $key;
$result = tep_db_query($sql);
if (tep_db_num_rows($result) == 0) {
// nope, this is a new product description
$result = tep_db_query($sql);
$sql =
"INSERT INTO ".TABLE_PRODUCTS_DESCRIPTION."
(products_id,
language_id,
products_name,
products_description,
mediacat_part_no,
products_url,
products_head_title_tag,
products_head_desc_tag,
products_head_keywords_tag)
VALUES (
'" . $v_products_id . "',
" . $key . ",
'" . $name . "',
'". $v_products_description[$key] . "',
'". $v_mediacat_part_no[$key] . "',
'". $v_products_url[$key] . "',
'". $v_products_head_title_tag[$key] . "',
'". $v_products_head_desc_tag[$key] . "',
'". $v_products_head_keywords_tag[$key] . "')";
$result = tep_db_query($sql);
} else {
// already in the description, let's just update it
$sql =
"UPDATE ".TABLE_PRODUCTS_DESCRIPTION." SET
products_name='$name',
products_description='".$v_products_description[$key] . "',
mediacat_part_no='" . $v_mediacat_part_no[$key] . "',
products_url='" . $v_products_url[$key] . "',
products_head_title_tag = '" . $v_products_head_title_tag[$key] ."',
products_head_desc_tag = '" . $v_products_head_desc_tag[$key] ."',
products_head_keywords_tag = '" . $v_products_head_keywords_tag[$key] ."'
WHERE
products_id = '$v_products_id' AND
language_id = '$key'";
$result = tep_db_query($sql);
}
}
}
}