Skip to content

Commit

Permalink
Support import/export with language_code (en, de, etc....)
Browse files Browse the repository at this point in the history
Fixes #43

Support export with language code

Export language dependent data as a field to include the language
code suffix (ie. english => `en`, german => `de`, etc...),
the language id suffix (ie. english => 1, german => 2, etc...),
or both fields. Currently the export uses the language_id which
is a number associated with the specific database as the suffix
for fields that are language based
(ie. category_description, product_description, etc...).
Use of the language code will make data transfer/matching more
universal with the existing database and other databases.

Added a define value into
`includes/modules/easypopulate_4_filelayout.php` to support
the export of language fields to have the language code
(ie. english => `en`, german => `de`, etc...)

Define established is: `EASYPOPULATE_4_CONFIG_LANGUAGE_EXPORT`
with expectation of at least three options: `id`, `code`, `all`
where `all` will export language based fields with at least
currently the language id number and the language code to
where the two fields will be adjacent to each other and are
expected to contain the same information on export.

The file contains a define if one has not been set (expected
to be set through the install/upgrade process to be in the
database) to default to the "old" method of using the language
id number as the suffix. Also if the setting is not `code` then
the "default" will be used. If a fourth option is added to the
list then this particular arrangement may need to be revisited.
(ie. what if a third language field were added to the mix, then
there would need to be an option to export just that third
field, and three additional options to export that field
combined with the other existing two and one for the existing
two to be exported alone as well, though it would simply make
more programming sense to either export a single field or all
fields and then the additional fields removed and/or import to
be controlled to allow one or the other, but shouldn't allow a
combination of language characteristics unless the goal is to
change the language assignment data.

With the changes that have been made to the export file, having
`EASYPOPULATE_4_CONFIG_LANGUAGE_EXPORT` set to any of the above
three options will result in the export file containing whatever
has been chosen/set or if it is not set to one of the three
values to export the fields using the language id as the suffix.

Added the configuration option to support "setup" and control
of the export language suffix for fields that are language dependent.
  • Loading branch information
mc12345678 committed Dec 18, 2017
1 parent c70d69c commit 857eb98
Show file tree
Hide file tree
Showing 4 changed files with 529 additions and 85 deletions.
80 changes: 58 additions & 22 deletions admin/easypopulate_4_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,25 @@
if ($ep_dltype == 'attrib_basic') { // special case 'attrib_basic'
$l_id = (int)$row['v_language_id'];

foreach ($langcode as $key => $lang) {
if ($lang['id'] == $l_id) {
$l_id_code = $lang['code'];
break;
}
}

if ($row['v_products_id'] == $active_products_id) {
if ($row['v_options_id'] == $active_options_id) {
// collect the products_options_values_name
if ($active_language_id <> $row['v_language_id']) {

$active_row['v_products_options_type'] = $row['v_products_options_type'];
$active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
$active_row['v_products_options_name_' . $l_id_code] = $active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id_code] = $active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
$active_language_id = $row['v_language_id'];
} else {
$active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id] .= "," . $row['v_products_options_values_name'];
$active_row['v_products_options_name_' . $l_id_code] = $active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id_code] = $active_row['v_products_options_values_name_' . $l_id] .= "," . $row['v_products_options_values_name'];
$active_row['v_products_options_type'] = $row['v_products_options_type'];
}
continue; // loop - for more products_options_values_name on same v_products_id/v_options_id combo
Expand All @@ -250,13 +257,13 @@

$active_options_id = $row['v_options_id'];
$active_language_id = $row['v_language_id'];
$active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
$active_row['v_products_options_name_' . $l_id_code] = $active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id_code] = $active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
$active_row['v_products_options_type'] = $row['v_products_options_type'];
continue; // loop - for more products_options_values_name on same v_products_id/v_options_id combo
} // end of options_id check
} else { // new combo or different product or first time through while-loop
if ($active_row['v_products_model'] <> $last_products_id) {
if ($active_row['v_products_id'] <> $last_products_id) {
// Clean the texts that could break CSV file formatting

$dataRow = ep_4_rmv_chars($filelayout, $active_row, $csv_delimiter);
Expand All @@ -265,7 +272,7 @@
unset($dataRow);

$ep_export_count++;
$last_products_id = $active_row['v_products_model'];
$last_products_id = $active_row['v_products_id'];
} // end if new model

// get current row of data
Expand All @@ -279,8 +286,8 @@
}
$active_row['v_products_options_type'] = $row['v_products_options_type'];

$active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
$active_row['v_products_options_name_' . $l_id_code] = $active_row['v_products_options_name_' . $l_id] = $row['v_products_options_name'];
$active_row['v_products_options_values_name_' . $l_id_code] = $active_row['v_products_options_values_name_' . $l_id] = $row['v_products_options_values_name'];
} // end of special case 'attrib_basic'
} else { // standard export processing // end of special case 'attrib_basic'
if ($ep_dltype == 'orders_1' || $ep_dltype == 'orders_2' || $ep_dltype == 'orders_3' || $ep_dltype == 'orders_4') {
Expand Down Expand Up @@ -356,19 +363,20 @@
// names and descriptions require that we loop thru all installed languages
foreach ($langcode as $key2 => $lang2) {
$lid2 = $lang2['id'];
$lid2_code = $lang2['code'];

$sql2 = 'SELECT * FROM ' . TABLE_PRODUCTS_DESCRIPTION . ' WHERE products_id = :products_id: AND language_id = :language_id: LIMIT 1 ';
$sql2 = $db->bindVars($sql2, ':products_id:', $row['v_products_id'], 'integer');
$sql2 = $db->bindVars($sql2, ':language_id:', $lid2, 'integer');
$result2 = ep_4_query($sql2);
unset($sql2);
$row2 = ($ep_uses_mysqli ? mysqli_fetch_array($result2) : mysql_fetch_array($result2));
$row['v_products_name_' . $lid2] = $row2['products_name'];
$row['v_products_description_' . $lid2] = $row2['products_description'];
$row['v_products_name_' . $lid2_code] = $row['v_products_name_' . $lid2] = $row2['products_name'];
$row['v_products_description_' . $lid2_code] = $row['v_products_description_' . $lid2] = $row2['products_description'];
if ($ep_supported_mods['psd'] == true) { // products short descriptions mod
$row['v_products_short_desc_' . $lid2] = $row2['products_short_desc'];
$row['v_products_short_desc_' . $lid2_code] = $row['v_products_short_desc_' . $lid2] = $row2['products_short_desc'];
}
$row['v_products_url_' . $lid2] = $row2['products_url'];
$row['v_products_url_' . $lid2_code] = $row['v_products_url_' . $lid2] = $row2['products_url'];
unset($row2);
// metaData start
// for each language, get the description and set the vals
Expand All @@ -387,6 +395,7 @@
unset($key2);
unset($lang2);
unset($lid2);
unset($lid2_code);
unset($rowMeta);

$zco_notifier->notify('EP4_EXPORT_LOOP_FULL_OR_SBASTOCK_END');
Expand Down Expand Up @@ -424,10 +433,18 @@
unset($sql2);
while ($row2 = ($ep_uses_mysqli ? mysqli_fetch_array($result2) : mysql_fetch_array($result2))) {
$lid = $row2['language_id'];
foreach ($langcode as $key => $lang) {
if ($lang['id'] == $lid) {
$lid_code = $lang['code'];
break;
}
}
$row['v_category_path_' . $lid] = $row2['categories_name'] . $category_delimiter . $row['v_category_path_' . $lid];
$row['v_category_path_' . $lid_code] = $row2['categories_name'] . $category_delimiter . $row['v_category_path_' . $lid_code];
} //while
unset($row2);
unset($lid);
unset($lid_code);
// look for parent categories ID
$sql3 = 'SELECT parent_id FROM ' . TABLE_CATEGORIES . ' WHERE categories_id = :categories_id:';
$sql3 = $db->bindVars($sql3, ':categories_id:', $thecategory_id, 'integer');
Expand All @@ -443,16 +460,17 @@
// names and descriptions require that we loop thru all languages that are turned on in the store
foreach ($langcode as $key => $lang) {
$lid = $lang['id'];
$lid_code = $lang['code'];
// metaData start
$sqlMeta = 'SELECT * FROM ' . TABLE_METATAGS_CATEGORIES_DESCRIPTION . ' WHERE categories_id = :categories_id: AND language_id = :language_id: LIMIT 1 ';
$sqlMeta = $db->bindVars($sqlMeta, ':categories_id:', $row['v_categories_id'], 'integer');
$sqlMeta = $db->bindVars($sqlMeta, ':language_id:', $lid, 'integer');
$resultMeta = ep_4_query($sqlMeta) or die(($ep_uses_mysqli ? mysqli_error($db->link) : mysql_error()));
$rowMeta = ($ep_uses_mysqli ? mysqli_fetch_array($resultMeta) : mysql_fetch_array($resultMeta));
unset($resultMeta);
$row['v_metatags_title_' . $lid] = $rowMeta['metatags_title'];
$row['v_metatags_keywords_' . $lid] = $rowMeta['metatags_keywords'];
$row['v_metatags_description_' . $lid] = $rowMeta['metatags_description'];
$row['v_metatags_title_' . $lid_code] = $row['v_metatags_title_' . $lid] = $rowMeta['metatags_title'];
$row['v_metatags_keywords_' . $lid_code] = $row['v_metatags_keywords_' . $lid] = $rowMeta['metatags_keywords'];
$row['v_metatags_description_' . $lid_code] = $row['v_metatags_description_' . $lid] = $rowMeta['metatags_description'];
unset($rowMeta);
// metaData end
// for each language, get category description and name
Expand All @@ -462,14 +480,16 @@
$result2 = ep_4_query($sql2);
unset($sql2);
$row2 = ($ep_uses_mysqli ? mysqli_fetch_array($result2) : mysql_fetch_array($result2));
$row['v_categories_name_' . $lid] = $row2['categories_name'];
$row['v_categories_name_' . $lid_code] = $row['v_categories_name_' . $lid] = $row2['categories_name'];
$row['v_category_path_' . $lid] = rtrim($row['v_category_path_' . $lid], $category_delimiter);
$row['v_categories_description_' . $lid] = $row2['categories_description'];
$row['v_categories_description_' . $lid_code] = $row['v_categories_description_' . $lid] = $row2['categories_description'];
$row['v_category_path_' . $lid_code] = rtrim($row['v_category_path_' . $lid_code], $category_delimiter);
unset($row2);
} // foreach
unset($key);
unset($lang);
unset($lid);
unset($lid_code);

if (EASYPOPULATE_4_CONFIG_EXPORT_URI != '0') {
$row['v_html_uri'] = zen_catalog_href_link(FILENAME_DEFAULT, zen_get_path($row['v_categories_id']), 'NONSSL');
Expand Down Expand Up @@ -507,7 +527,14 @@
unset($sql2);
while ($row2 = ($ep_uses_mysqli ? mysqli_fetch_array($result2) : mysql_fetch_array($result2))) {
$lid = $row2['language_id'];
foreach ($langcode as $key => $lang) {
if ($lang['id'] == $lid) {
$lid_code = $lang['code'];
break;
}
}
$row['v_categories_name_' . $lid] = $row2['categories_name'] . $category_delimiter . $row['v_categories_name_' . $lid];
$row['v_categories_name_' . $lid_code] = $row2['categories_name'] . $category_delimiter . $row['v_categories_name_' . $lid_code];
} //while
unset($row2);
unset($lid);
Expand All @@ -527,11 +554,14 @@
// trim off trailing category delimiter '^'
foreach ($langcode as $key => $lang) {
$lid = $lang['id'];
$lid_code = $lang['code'];
$row['v_categories_name_' . $lid] = rtrim($row['v_categories_name_' . $lid], $category_delimiter);
$row['v_categories_name_' . $lid_code] = rtrim($row['v_categories_name_' . $lid_code], $category_delimiter);
} // foreach
unset($key);
unset($lang);
unset($lid);
unset($lid_code);

} // if($ep_dltype == 'full' || $ep_dltype == 'category') delimited categories path

Expand Down Expand Up @@ -790,27 +820,31 @@
$row['v_artists_image'] = $row_record_artists['artists_image'];
foreach ($langcode as $key => $lang) {
$lid = $lang['id'];
$lid_code = $lang['code'];
$sql_record_artists_info = 'SELECT * FROM ' . TABLE_RECORD_ARTISTS_INFO . ' WHERE artists_id = :artists_id: AND languages_id = :languages_id: LIMIT 1';
$sql_record_artists_info = $db->bindVars($sql_record_artists_info, ':artists_id:', $row_music_extra['artists_id'], 'integer');
$sql_record_artists_info = $db->bindVars($sql_record_artists_info, ':languages_id:', $lid, 'integer');
$result_record_artists_info = ep_4_query($sql_record_artists_info);
$row_record_artists_info = ($ep_uses_mysqli ? mysqli_fetch_array($result_record_artists_info) : mysql_fetch_array($result_record_artists_info));
$row['v_artists_url_' . $lid] = $row_record_artists_info['artists_url'];
$row['v_artists_url_' . $lid_code] = $row['v_artists_url_' . $lid] = $row_record_artists_info['artists_url'];
}
unset($key);
unset($lang);
unset($lid);
unset($lid_code);

} else {
$row['v_artists_name'] = ''; // no artists name
$row['v_artists_image'] = '';
foreach ($langcode as $key => $lang) {
$lid = $lang['id'];
$row['v_artists_url_' . $lid] = '';
$lid_code = $lang['code'];
$row['v_artists_url_' . $lid_code] = $row['v_artists_url_' . $lid] = '';
}
unset($key);
unset($lang);
unset($lid);
unset($lid_code);

}
// record company
Expand All @@ -826,19 +860,21 @@
unset($row_record_company);
foreach ($langcode as $key => $lang) {
$lid = $lang['id'];
$lid_code = $lang['code'];
$sql_record_company_info = 'SELECT * FROM ' . TABLE_RECORD_COMPANY_INFO . ' WHERE record_company_id = :record_company_id: AND languages_id = :languages_id: LIMIT 1';
$sql_record_company_info = $db->bindVars($sql_record_company_info, ':record_company_id:', $row_music_extra['record_company_id'], 'integer');
$sql_record_company_info = $db->bindVars($sql_record_company_info, ':languages_id:', $lid, 'integer');
$result_record_company_info = ep_4_query($sql_record_company_info);
$row_record_company_info = ($ep_uses_mysqli ? mysqli_fetch_array($result_record_company_info) : mysql_fetch_array($result_record_company_info));
$row['v_record_company_url_' . $lid] = $row_record_company_info['record_company_url'];
$row['v_record_company_url_' . $lid_code] = $row['v_record_company_url_' . $lid] = $row_record_company_info['record_company_url'];
}
unset($sql_record_company_info);
unset($result_record_company_info);
unset($row_record_company_info);
unset($key);
unset($lang);
unset($lid);
unset($lid_code);

} else {
$row['v_record_company_name'] = '';
Expand Down
Loading

0 comments on commit 857eb98

Please sign in to comment.