protected function importAddField($table_name, $field_name, $field_value) { $this->debugMessage("Featured::importAddField ({$table_name}, {$field_name}, {$field_value})"); switch ($table_name) { case TABLE_FEATURED: if ($this->import_is_insert) { if ($field_name === 'featured_date_added') { $field_value = 'now()'; } elseif ($field_name === 'featured_last_modified') { $field_value = self::DBIO_NO_IMPORT; } } else { if ($field_name === 'featured_last_modified') { $field_value = 'now()'; } } parent::importAddField($table_name, $field_name, $field_value); break; default: break; } //-END switch interrogating $table_name }
protected function importAddField($table_name, $field_name, $field_value) { $this->debugMessage("Products::importAddField ({$table_name}, {$field_name}, {$field_value})"); global $db; switch ($table_name) { case TABLE_PRODUCTS: if ($this->import_is_insert) { if ($field_name === 'products_date_added') { $field_value = 'now()'; } elseif ($field_name === 'products_last_modified') { $field_value = self::DBIO_NO_IMPORT; } } else { if ($field_name === 'products_last_modified') { $field_value = 'now()'; } } parent::importAddField($table_name, $field_name, $field_value); break; case self::DBIO_SPECIAL_IMPORT: switch ($field_name) { case 'manufacturers_name': if (empty($field_value)) { $manufacturers_id = 0; } else { $manufacturer_check_sql = "SELECT manufacturers_id FROM " . TABLE_MANUFACTURERS . " WHERE manufacturers_name = :manufacturer_name: LIMIT 1"; $manufacturer_check = $db->Execute($db->bindVars($manufacturer_check_sql, ':manufacturer_name:', $field_value, 'string'), false, false, 0, true); if (!$manufacturer_check->EOF) { $manufacturers_id = $manufacturer_check->fields['manufacturers_id']; } else { $this->debugMessage("[*] Import, creating database entry for manufacturer named \"{$field_value}\"", self::DBIO_ACTIVITY); $sql_data_array = array(); $sql_data_array[] = array('fieldName' => 'manufacturers_name', 'value' => $field_value, 'type' => 'string'); $sql_data_array[] = array('fieldName' => 'date_added', 'value' => 'now()', 'type' => 'noquotestring'); $db->perform(TABLE_MANUFACTURERS, $sql_data_array); $manufacturers_id = $db->Insert_ID(); foreach ($this->languages as $language_code => $language_id) { $sql_data_array = array(); $sql_data_array[] = array('fieldName' => 'manufacturers_id', 'value' => $manufacturers_id, 'type' => 'integer'); $sql_data_array[] = array('fieldName' => 'languages_id', 'value' => $language_id, 'type' => 'integer'); $db->perform(TABLE_MANUFACTURERS_INFO, $sql_data_array); } } } $this->import_sql_data[TABLE_PRODUCTS]['manufacturers_id'] = array('value' => $manufacturers_id, 'type' => 'integer'); break; case 'tax_class_title': if (zen_not_null($field_value)) { $tax_class_check_sql = "SELECT tax_class_id FROM " . TABLE_TAX_CLASS . " WHERE tax_class_title = :tax_class_title: LIMIT 1"; $tax_class_check = $db->Execute($db->bindVars($tax_class_check_sql, ':tax_class_title:', $field_value, 'string')); if ($tax_class_check->EOF) { $this->debugMessage('[*] Import line #' . $this->stats['record_count'] . ", undefined tax_class_title ({$field_value}). Defaulting product to untaxed.", self::DBIO_WARNING); } $tax_class_id = $tax_class_check->EOF ? 0 : $tax_class_check->fields['tax_class_id']; $this->import_sql_data[TABLE_PRODUCTS]['products_tax_class_id'] = array('value' => $tax_class_id, 'type' => 'integer'); } break; case 'categories_name': $parent_category = 0; $categories_name_ok = true; $language_id = $this->languages[DEFAULT_LANGUAGE]; $categories = explode('^', $field_value); foreach ($categories as $current_category_name) { $category_info_sql = "SELECT c.categories_id FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd\n WHERE c.parent_id = {$parent_category} \n AND c.categories_id = cd.categories_id\n AND cd.categories_name = :categories_name: \n AND cd.language_id = {$language_id} LIMIT 1"; $category_info = $db->Execute($db->bindVars($category_info_sql, ':categories_name:', $current_category_name, 'string'), false, false, 0, true); if (!$category_info->EOF) { $parent_category = $category_info->fields['categories_id']; } elseif ($this->import_is_insert) { $categories_name_ok = false; $this->debugMessage('[*] Product not inserted at line number ' . $this->stats['record_count'] . ", no match found for categories_name ({$current_category_name}).", self::DBIO_WARNING); break; } } if ($categories_name_ok && $this->import_is_insert) { $category_check = $db->Execute("SELECT categories_id FROM " . TABLE_CATEGORIES . " WHERE parent_id = {$parent_category} LIMIT 1", false, false, 0, true); if (!$category_check->EOF) { $categories_name_ok = false; $this->debugMessage("[*] Product not inserted at line number " . $this->stats['record_count'] . "; category ({$field_name}) has categories.", self::DBIO_WARNING); } else { $this->import_sql_data[TABLE_PRODUCTS]['master_categories_id'] = array('value' => $parent_category, 'type' => 'integer'); $this->import_sql_data[TABLE_PRODUCTS_TO_CATEGORIES]['categories_id'] = array('value' => $parent_category, 'type' => 'integer'); } } if (!$categories_name_ok) { $this->record_status = false; } break; default: break; } //-END switch interrogating $field_name for self::DBIO_SPECIAL_IMPORT break; default: parent::importAddField($table_name, $field_name, $field_value); break; } //-END switch interrogating $table_name }