Skip to content

Commit

Permalink
Products Description import mod 4.0.31c
Browse files Browse the repository at this point in the history
Modified the Products Description import section to not depend on the product's name being included in the import file in order to update the
other fields within the product's description data table.
Added notify points in the import file to be able to incorporate other product's description fields as necessary/desired through an observer class.
Broke out the Product's Description SQL to use ZC's bindVars which will format data for the database in accordance with the appropriate rules.
  • Loading branch information
mc12345678 committed Dec 12, 2015
1 parent aed7122 commit e6437fe
Showing 1 changed file with 73 additions and 27 deletions.
100 changes: 73 additions & 27 deletions admin/easypopulate_4_import.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// $Id: easypopulate_4_import.php, v4.0.31 08-01-2015 mc12345678 $
// $Id: easypopulate_4_import.php, v4.0.31c 12-12-2015 mc12345678 $

if (!defined(EP4_REPLACE_BLANK_IMAGE)) {
define('EP4_REPLACE_BLANK_IMAGE', 'false'); // Values to be 'true' and 'false' true, if on import the image path evaluates to '' then if true, stores the value of PRODUCTS_IMAGE_NO_IMAGE as the image, otherwise will leave it as blank.;
Expand Down Expand Up @@ -1728,51 +1728,97 @@

// BEGIN: Products Descriptions
// the following is common in both the updating an existing product and creating a new product // mc12345678 updated to allow omission of v_products_description in the import file.
if (isset($v_products_name)) {
foreach ($v_products_name as $key => $name) {
$add_products_description_data = false;
$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_ADD_OR_CHANGE_DATA');
if (isset($v_products_name) || isset($v_products_description) || ($ep_supported_mods['psd'] == true && isset($v_products_short_desc) ) || isset($v_products_url) || $add_products_description_data) { //
// Effectively need a way to step through all language options, this section to be "accepted" if there is something to be updated. Prefer the ability to verify update need without having to loop on anything, but just by "presence" of information.
foreach ($languages as $lang) {
// foreach ($v_products_name as $key => $name) { // Decouple the dependency on the products_name being imported to update the products_name, description, short description and/or URL. //mc12345678 2015-Dec-12
$lang_id = $lang['id'];
$sql = "SELECT * FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE
products_id = " . $v_products_id . " AND
language_id = " . $key;
products_id = :v_products_id: AND
language_id = :language_id:";
$sql = $db->bindVars($sql, ':v_products_id:', $v_products_id, 'integer');
$sql = $db->bindVars($sql, ':language_id:', $lang_id, 'integer');
$result = ep_4_query($sql);

if (($ep_uses_mysqli ? mysqli_num_rows($result) : mysql_num_rows($result)) == 0) {
$sql = "INSERT INTO " . TABLE_PRODUCTS_DESCRIPTION . " (
products_id,
language_id,
products_name, " .
((isset($filelayout['v_products_description_' . $key]) || ( isset($filelayout['v_products_description_' . $key]) && $product_is_new) ) ? " products_description," : "");
if ($ep_supported_mods['psd'] == true) {
$sql .= " products_short_desc,";
" . (isset($filelayout['v_products_name_' . $lang_id]) || $product_is_new ? "products_name, " : "") .
((isset($filelayout['v_products_description_' . $lang_id]) || ( isset($filelayout['v_products_description_' . $lang_id]) && $product_is_new) ) ? " products_description, " : "");
if ($ep_supported_mods['psd'] == true && isset($v_products_short_desc)) {
$sql .= " products_short_desc, ";
}
$sql .= " products_url )
$sql .= (isset($filelayout['v_products_url_' . $lang_id]) ? " products_url, " : "");
$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_INSERT_FIELDS');
$sql .= "
language_id )
VALUES (
'" . $v_products_id . "',
" . $key . ",
'" . addslashes($name) . "', " .
((isset($filelayout['v_products_description_' . $key]) || ( isset($filelayout['v_products_description_' . $key]) && $product_is_new) ) ? "'" . addslashes($v_products_description[$key]) . "'," : "");
if ($ep_supported_mods['psd'] == true) {
$sql .= "'" . addslashes($v_products_short_desc[$key]) . "',";
:v_products_id:,
" . (isset($filelayout['v_products_name_' . $lang_id]) || $product_is_new ? ":v_products_name:, " : "") .
((isset($filelayout['v_products_description_' . $lang_id]) || ( isset($filelayout['v_products_description_' . $lang_id]) && $product_is_new) ) ? ":v_products_description:, " : "");
if ($ep_supported_mods['psd'] == true && isset($v_products_short_desc)) {
$sql .= ":v_products_short_desc:, ";
}
$sql .= "'" . addslashes($v_products_url[$key]) . "')";
$sql .= (isset($filelayout['v_products_url_' . $lang_id]) ? ":v_products_url:, " : "");
$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_INSERT_FIELDS_VALUES');
$sql .= "
:language_id:)";

$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_FIELDS_BIND_START');
$sql = $db->bindVars($sql, ':v_products_id:', $v_products_id, 'integer');
$sql = $db->bindVars($sql, ':v_products_name:', $v_products_name[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_description:', $v_products_description[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_short_desc:', $v_products_short_desc[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_url:', $v_products_url[$lang_id], 'string');
$sql = $db->bindVars($sql, ':language_id:', $lang_id, 'integer');
$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_FIELDS_BIND_END');

$result = ep_4_query($sql);
if ($result) {
zen_record_admin_activity('New product ' . (int) $v_products_id . ' description added via EP4.', 'info');
}
} else { // already in the description, update it
$sql = "UPDATE " . TABLE_PRODUCTS_DESCRIPTION . " SET
products_name ='" . addslashes($name) . "', " .
((isset($filelayout['v_products_description_' . $key]) || ( isset($filelayout['v_products_description_' . $key]) && $product_is_new) ) ? "products_description ='" . addslashes($v_products_description[$key]) . "'," : "");
if ($ep_supported_mods['psd'] == true) {
$sql .= " products_short_desc = '" . addslashes($v_products_short_desc[$key]) . "',";
$sql = "UPDATE " . TABLE_PRODUCTS_DESCRIPTION . " SET ";
$update_count = false;
if (isset($filelayout['v_products_name_' . $lang_id])) {
$sql .= " products_name = :products_name";
$update_count = true;
}
$sql .= " products_url='" . addslashes($v_products_url[$key]) . "'
WHERE products_id = '" . $v_products_id . "' AND language_id = '" . $key . "'";
if (isset($filelayout['v_products_description_' . $lang_id]) || ( isset($filelayout['v_products_description_' . $lang_id]) && $product_is_new)) {
$sql .= ($update_count ? ", " : "") . "products_description = :v_products_description:";
$update_count = true;
}
if ($ep_supported_mods['psd'] == true && isset($v_products_short_desc[$lang_id])) {
$sql .= ($update_count ? ", " : "") . "products_short_desc = :v_products_short_desc:";
}
if (isset($filelayout['v_products_url_' . $lang_id])) {
$sql .= ($update_count ? ", " : "") . " products_url = :v_products_url: ";
$update_count = true;
}

$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_UPDATE_FIELDS_VALUES');

$sql .= " WHERE products_id = :v_products_id: AND language_id = :language_id:";

$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_UPDATE_WHERE');

$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_FIELDS_BIND_START');
$sql = $db->bindVars($sql, ':v_products_id:', $v_products_id, 'integer');
$sql = $db->bindVars($sql, ':v_products_name:', $v_products_name[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_description:', $v_products_description[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_short_desc:', $v_products_short_desc[$lang_id], 'string');
$sql = $db->bindVars($sql, ':v_products_url:', $v_products_url[$lang_id], 'string');
$sql = $db->bindVars($sql, ':language_id:', $lang_id, 'integer');
$zco_notifier->notify('EP4_IMPORT_FILE_PRODUCTS_DESCRIPTION_FIELDS_BIND_END');

$result = ep_4_query($sql);
if ($result) {
zen_record_admin_activity('Updated product ' . (int) $v_products_id . ' description via EP4.', 'info');
}
}
}
} // END: already in description, update it
} // END: foreach on languages
} // END: Products Descriptions End

//==================================================================================================================================
Expand Down

0 comments on commit e6437fe

Please sign in to comment.