Skip to content

Commit

Permalink
#153: Manufacturers, refactoring prior to change
Browse files Browse the repository at this point in the history
  • Loading branch information
lat9 committed Jan 26, 2020
1 parent 3d67760 commit 55d2984
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
52 changes: 26 additions & 26 deletions YOUR_ADMIN/includes/classes/dbio/DbIoManufacturersHandler.php
@@ -1,23 +1,23 @@
<?php
// -----
// Part of the DataBase Import/Export (aka DbIo) plugin, created by Cindy Merkin (cindy@vinosdefrutastropicales.com)
// Copyright (c) 2017, Vinos de Frutas Tropicales.
// Copyright (c) 2017-2020, Vinos de Frutas Tropicales.
//
if (!defined ('IS_ADMIN_FLAG')) {
exit ('Illegal access');
if (!defined('IS_ADMIN_FLAG')) {
exit('Illegal access');
}

// -----
// This DbIo class handles the customizations required for a basic Zen Cart manufacturers import/export.
//
class DbIoManufacturersHandler extends DbIoHandler
{
public static function getHandlerInformation ()
public static function getHandlerInformation()
{
global $db;
DbIoHandler::loadHandlerMessageFile ('Manufacturers');
return array (
'version' => '1.0.0',
DbIoHandler::loadHandlerMessageFile('Manufacturers');
return array(
'version' => '1.5.8',
'handler_version' => '1.2.0',
'include_header' => true,
'export_only' => false,
Expand All @@ -29,9 +29,9 @@ public static function getHandlerInformation ()
// This function, called at the beginning of an export operation, gives the handler an opportunity to perform
// some special checks.
//
public function exportInitialize ($language = 'all')
public function exportInitialize($language = 'all')
{
$initialized = parent::exportInitialize ($language);
$initialized = parent::exportInitialize($language);
if ($initialized) {
if ($this->where_clause != '') {
$this->where_clause .= ' AND ';
Expand All @@ -48,20 +48,20 @@ public function exportInitialize ($language = 'all')
}


public function exportPrepareFields (array $fields)
public function exportPrepareFields(array $fields)
{
global $db;

$fields = parent::exportPrepareFields ($fields);
$fields = parent::exportPrepareFields($fields);
$default_language_code = $this->first_language_code;

if ($this->export_language == 'all') {
$this->debugMessage ('Manufacturers::exportPrepareFields, language = ' . $this->export_language . ', default language = ' . $default_language_code . ', sql: ' . $this->saved_data['manufacturers_info_sql'] . ', languages: ' . print_r ($this->languages, true));
$this->debugMessage('Manufacturers::exportPrepareFields, language = ' . $this->export_language . ', default language = ' . $default_language_code . ', sql: ' . $this->saved_data['manufacturers_info_sql'] . ', languages: ' . print_r($this->languages, true));
foreach ($this->languages as $language_code => $language_id) {
if ($language_code != $default_language_code) {
$description_info = $db->Execute (sprintf ($this->saved_data['manufacturers_info_sql'], $manufacturers_id, $language_id));
$description_info = $db->Execute(sprintf($this->saved_data['manufacturers_info_sql'], $manufacturers_id, $language_id));
if (!$description_info->EOF) {
$encoded_fields = $this->exportEncodeData ($description_info->fields);
$encoded_fields = $this->exportEncodeData($description_info->fields);
foreach ($encoded_fields as $field_name => $field_value) {
if ($field_name != 'manufacturers_id' && $field_name != 'languages_id') {
$fields[$field_name . '_' . $language_code] = $field_value;
Expand All @@ -82,27 +82,27 @@ public function exportPrepareFields (array $fields)
// This function, called during the overall class construction, is used to set this handler's database
// configuration for the dbIO operations.
//
protected function setHandlerConfiguration ()
protected function setHandlerConfiguration()
{
$this->stats['report_name'] = 'Manufacturers';
$this->config = self::getHandlerInformation ();
$this->config['keys'] = array (
TABLE_MANUFACTURERS => array (
$this->config = self::getHandlerInformation();
$this->config['keys'] = array(
TABLE_MANUFACTURERS => array(
'alias' => 'm',
'capture_key_value' => true,
'manufacturers_id' => array (
'manufacturers_id' => array(
'type' => self::DBIO_KEY_IS_VARIABLE | self::DBIO_KEY_SELECTED,
),
),
);
$this->config['tables'] = array (
TABLE_MANUFACTURERS => array (
$this->config['tables'] = array(
TABLE_MANUFACTURERS => array(
'alias' => 'm',
),
TABLE_MANUFACTURERS_INFO => array (
TABLE_MANUFACTURERS_INFO => array(
'alias' => 'mi',
'language_field' => 'languages_id',
'io_field_overrides' => array (
'io_field_overrides' => array(
'manufacturers_id' => false,
'languages_id' => false,
),
Expand All @@ -120,16 +120,16 @@ protected function setHandlerConfiguration ()
// If we're doing an update (i.e. existing manufacturer), need to update the primary where-clause to make sure that the
// manufacturers table alias isn't part of the string for the non-manufacturers table.
//
protected function importUpdateRecordKey ($table_name, $table_fields, $products_id)
protected function importUpdateRecordKey($table_name, $table_fields, $products_id)
{
if ($table_name != TABLE_MANUFACTURERS) {
if ($this->import_is_insert) {
$table_fields['manufacturers_id'] = array ( 'value' => $products_id, 'type' => 'integer' );
$table_fields['manufacturers_id'] = array('value' => $products_id, 'type' => 'integer');
} else {
$this->where_clause = 'manufacturers_id = ' . (int)$this->key_fields['manufacturers_id'];
}
}
return parent::importUpdateRecordKey ($table_name, $table_fields, $products_id);
return parent::importUpdateRecordKey($table_name, $table_fields, $products_id);
}

} //-END class DbIoManufacturersHandler
2 changes: 2 additions & 0 deletions docs/dbio/readme.html
Expand Up @@ -584,7 +584,9 @@ <h1 id="title">Database I/O Manager (DbIo) for Zen Cart&reg;</h1>
<li>Ensure the export properly outputs possibly not present fields.</li>
<li>Correct management of the (possibly not present) 'products_attributes_downloads' table's fields.</li>
</ol></li>
<li>BUGFIX: Correct <em>Manufacturers</em> only exports default language for multi-lingual stores.</li>
<li>The following files were changed:<ol>
<li>/YOUR_ADMIN/includes/classes/dbio/DbIoManufacturersHandler.php</li>
<li>/YOUR_ADMIN/includes/classes/dbio/DbIoProductsAttribsRawHandler.php</li>
<li>/YOUR_ADMIN/includes/classes/dbio/DbIoProductsHandler.php</li>
<li>/YOUR_ADMIN/includes/init_includes/init_dbio_admin.php</li>
Expand Down

0 comments on commit 55d2984

Please sign in to comment.