| 1 | <?php
|
|---|
| 2 | /* -----------------------------------------------------------------------------------------
|
|---|
| 3 | $Id: import.php 14126 2022-02-17 15:27:56Z GTB $
|
|---|
| 4 |
|
|---|
| 5 | modified eCommerce Shopsoftware
|
|---|
| 6 | http://www.modified-shop.org
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 2009 - 2013 [www.modified-shop.org]
|
|---|
| 9 | -----------------------------------------------------------------------------------------
|
|---|
| 10 | based on:
|
|---|
| 11 | (c) 2006 XT-Commerce (product.php 1316 2005-10-21)
|
|---|
| 12 |
|
|---|
| 13 | -- over-worked by noRiddle
|
|---|
| 14 | * replaced functions with system functions
|
|---|
| 15 | * stripslashes (xtc_db_prepepare_input()) before xtc_db_perform() import
|
|---|
| 16 | * cast types for values before import
|
|---|
| 17 | * include admin group for access
|
|---|
| 18 | * include order description
|
|---|
| 19 | * fixed bug with CSV_SEPERATOR /t
|
|---|
| 20 | * newly formated code
|
|---|
| 21 | --
|
|---|
| 22 |
|
|---|
| 23 | Released under the GNU General Public License
|
|---|
| 24 | --------------------------------------------------------------
|
|---|
| 25 | */
|
|---|
| 26 | defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | /*******************************************************************************
|
|---|
| 30 | **
|
|---|
| 31 | *C xtcImport . . . . . . . . . . . . . . . . . . . . . . . . . . . . xtcImport
|
|---|
| 32 | **
|
|---|
| 33 | ******************************************************************************/
|
|---|
| 34 | class xtcImport {
|
|---|
| 35 |
|
|---|
| 36 | /*****************************************************************************
|
|---|
| 37 | **
|
|---|
| 38 | *F xtcImport . . . . . . . . . . . . . . . . . . . . . . . . . . . xtcImport
|
|---|
| 39 | **
|
|---|
| 40 | *****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | function __construct($filename) {
|
|---|
| 43 | $this->seperator = CSV_SEPERATOR;
|
|---|
| 44 | $this->TextSign = CSV_TEXTSIGN;
|
|---|
| 45 | if (trim(CSV_TEXTSIGN) == '') {
|
|---|
| 46 | $this->TextSign = '^';
|
|---|
| 47 | }
|
|---|
| 48 | if (CSV_SEPERATOR == '') {
|
|---|
| 49 | $this->seperator = "\t";
|
|---|
| 50 | }
|
|---|
| 51 | if (CSV_SEPERATOR == xtc_db_prepare_input('\t')) { //added stripslashes() since this is called in background in gID=20 (/admin/configuration.php)
|
|---|
| 52 | $this->seperator = "\t";
|
|---|
| 53 | }
|
|---|
| 54 | $this->filename = $filename;
|
|---|
| 55 | $this->ImportDir = DIR_FS_CATALOG.'import/';
|
|---|
| 56 | $this->catDepth = defined('CSV_CAT_DEPTH') ? CSV_CAT_DEPTH : 4;
|
|---|
| 57 | $this->languages = $this->get_lang();
|
|---|
| 58 | $this->counter = array ('prod_new' => 0,
|
|---|
| 59 | 'cat_new' => 0,
|
|---|
| 60 | 'prod_upd' => 0,
|
|---|
| 61 | 'cat_upd' => 0);
|
|---|
| 62 | $this->mfn = $this->get_mfn();
|
|---|
| 63 | $this->errorlog = array ();
|
|---|
| 64 | $this->time_start = time();
|
|---|
| 65 | $this->debug = false;
|
|---|
| 66 | $this->CatTree = array ('ID' => 0);
|
|---|
| 67 | // precaching categories in array ?
|
|---|
| 68 | $this->CatCache = true;
|
|---|
| 69 | $this->CatDefault = CSV_CATEGORY_DEFAULT;
|
|---|
| 70 | $this->FileSheme = array ();
|
|---|
| 71 | $this->Groups = xtc_get_customers_statuses();
|
|---|
| 72 | $this->count_groups = count($this->Groups);
|
|---|
| 73 | $this->sizeof_languages = sizeof($this->languages);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /*****************************************************************************
|
|---|
| 77 | **
|
|---|
| 78 | *F generate_map . . . . . . . . . . . . . . . . . . . . . . . . generate_map
|
|---|
| 79 | **
|
|---|
| 80 | ** generating file layout
|
|---|
| 81 | **
|
|---|
| 82 | ** @param array $mapping standard fields
|
|---|
| 83 | ** @return array
|
|---|
| 84 | **
|
|---|
| 85 | *****************************************************************************/
|
|---|
| 86 |
|
|---|
| 87 | function generate_map() {
|
|---|
| 88 |
|
|---|
| 89 | // lets define a standard fieldmapping array, with importable fields
|
|---|
| 90 | $file_layout = array (
|
|---|
| 91 | 'p_model' => '', // products_model
|
|---|
| 92 | 'p_stock' => '', // products_quantity
|
|---|
| 93 | 'p_tpl' => '', // products_template
|
|---|
| 94 | 'p_sorting' => '', // products_sorting
|
|---|
| 95 | 'p_manufacturer' => '', // manufacturer
|
|---|
| 96 | 'p_fsk18' => '', // FSK18
|
|---|
| 97 | 'p_priceNoTax' => '', // Nettoprice
|
|---|
| 98 | 'p_tax' => '', // taxrate in percent
|
|---|
| 99 | 'p_status' => '', // products status
|
|---|
| 100 | 'p_weight' => '', // products weight
|
|---|
| 101 | 'p_ean' => '', // products ean
|
|---|
| 102 | 'p_man' => '', //products_manufacturers_model
|
|---|
| 103 | 'p_disc' => '', // products discount
|
|---|
| 104 | 'p_opttpl' => '', // options template
|
|---|
| 105 | 'p_image' => '', // product image
|
|---|
| 106 | 'p_vpe' => '', // products VPE
|
|---|
| 107 | 'p_vpe_status' => '', // products VPE Status
|
|---|
| 108 | 'p_vpe_value' => '', // products VPE value
|
|---|
| 109 | 'p_shipping' => '' // product shipping_time
|
|---|
| 110 | );
|
|---|
| 111 | // group prices
|
|---|
| 112 | for ($i = 0; $i < $this->count_groups - 1; $i ++) {
|
|---|
| 113 | $file_layout = array_merge($file_layout, array ('p_priceNoTax.'.$this->Groups[$i +1]['id'] => ''));
|
|---|
| 114 | }
|
|---|
| 115 | // group permissions
|
|---|
| 116 | for ($i = 0; $i < $this->count_groups; $i ++) {
|
|---|
| 117 | $file_layout = array_merge($file_layout, array ('p_groupAcc.'.$this->Groups[$i]['id'] => ''));
|
|---|
| 118 | }
|
|---|
| 119 | // product images
|
|---|
| 120 | for ($i = 1; $i < MO_PICS + 1; $i ++) {
|
|---|
| 121 | $file_layout = array_merge($file_layout, array ('p_image.'.$i => ''));
|
|---|
| 122 | }
|
|---|
| 123 | // add lang fields
|
|---|
| 124 | for ($i = 0; $i < $this->sizeof_languages; $i ++) {
|
|---|
| 125 | $file_layout = array_merge($file_layout, array ('p_name.'.$this->languages[$i]['code'] => '',
|
|---|
| 126 | 'p_desc.'.$this->languages[$i]['code'] => '',
|
|---|
| 127 | 'p_shortdesc.'.$this->languages[$i]['code'] => '',
|
|---|
| 128 | 'p_orderdesc.'.$this->languages[$i]['code'] => '', // add order description
|
|---|
| 129 | 'p_meta_title.'.$this->languages[$i]['code'] => '',
|
|---|
| 130 | 'p_meta_desc.'.$this->languages[$i]['code'] => '',
|
|---|
| 131 | 'p_meta_key.'.$this->languages[$i]['code'] => '',
|
|---|
| 132 | 'p_keywords.'.$this->languages[$i]['code'] => '',
|
|---|
| 133 | 'p_url.'.$this->languages[$i]['code'] => '')
|
|---|
| 134 | );
|
|---|
| 135 | }
|
|---|
| 136 | // add categorie fields
|
|---|
| 137 | for ($i = 0; $i < $this->catDepth; $i ++) {
|
|---|
| 138 | $file_layout = array_merge($file_layout, array ('p_cat.'.$i => ''));
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | foreach(auto_include(DIR_FS_ADMIN.'includes/extra/modules/import/file_layout/','php') as $file) require ($file);
|
|---|
| 142 |
|
|---|
| 143 | return $file_layout;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /*****************************************************************************
|
|---|
| 147 | **
|
|---|
| 148 | *F map_file . . . . . . . . . . . . . . . . . . . . . . . . . . . . map_file
|
|---|
| 149 | **
|
|---|
| 150 | ** generating mapping layout for importfile
|
|---|
| 151 | ** @param array $mapping standard fields
|
|---|
| 152 | ** @return array
|
|---|
| 153 | *****************************************************************************/
|
|---|
| 154 |
|
|---|
| 155 | function map_file($mapping) {
|
|---|
| 156 | if (!file_exists($this->ImportDir.$this->filename)) {
|
|---|
| 157 | // error
|
|---|
| 158 | return 'error';
|
|---|
| 159 | } else {
|
|---|
| 160 | // file is ok, creating mapping
|
|---|
| 161 | $inhalt = array ();
|
|---|
| 162 | $inhalt = file($this->ImportDir.$this->filename);
|
|---|
| 163 | // get first line into array
|
|---|
| 164 | $content = explode($this->seperator, $inhalt[0]);
|
|---|
| 165 |
|
|---|
| 166 | foreach ($mapping as $key => $value) {
|
|---|
| 167 | // try to find our field in fieldlayout
|
|---|
| 168 | foreach ($content as $key_c => $value_c)
|
|---|
| 169 | if ($key == trim($this->RemoveTextNotes($content[$key_c]))) {
|
|---|
| 170 | $mapping[$key] = trim($this->RemoveTextNotes($key_c));
|
|---|
| 171 | $this->FileSheme[$key] = 'Y';
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | }
|
|---|
| 175 | return $mapping;
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /*****************************************************************************
|
|---|
| 180 | **
|
|---|
| 181 | *F get_lang . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_lang
|
|---|
| 182 | **
|
|---|
| 183 | ** Get installed languages
|
|---|
| 184 | **
|
|---|
| 185 | ** @return array
|
|---|
| 186 | *****************************************************************************/
|
|---|
| 187 |
|
|---|
| 188 | function get_lang() {
|
|---|
| 189 | $languages_query = xtc_db_query("SELECT languages_id,
|
|---|
| 190 | name,
|
|---|
| 191 | code,
|
|---|
| 192 | image,
|
|---|
| 193 | directory
|
|---|
| 194 | FROM ".TABLE_LANGUAGES."
|
|---|
| 195 | ORDER BY sort_order
|
|---|
| 196 | ");
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 | while ($languages = xtc_db_fetch_array($languages_query)) {
|
|---|
| 200 | $languages_array[] = array (
|
|---|
| 201 | 'id' => $languages['languages_id'],
|
|---|
| 202 | 'name' => $languages['name'],
|
|---|
| 203 | 'code' => $languages['code']
|
|---|
| 204 | );
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | return $languages_array;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | /*****************************************************************************
|
|---|
| 211 | **
|
|---|
| 212 | *F import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . import
|
|---|
| 213 | **
|
|---|
| 214 | *****************************************************************************/
|
|---|
| 215 |
|
|---|
| 216 | function import($mapping) {
|
|---|
| 217 |
|
|---|
| 218 | // open file
|
|---|
| 219 | $fp = fopen($this->ImportDir.$this->filename, 'r');
|
|---|
| 220 |
|
|---|
| 221 | // read the header line
|
|---|
| 222 | $header = fgetcsv($fp, 20000, $this->seperator, $this->TextSign);
|
|---|
| 223 | foreach($header as $key=>$name) {
|
|---|
| 224 | $mapping[$name] = $key;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | $row = 1; //set row to one to be able to count rows in while loop
|
|---|
| 228 |
|
|---|
| 229 | while ($line = fgetcsv($fp, 20000, $this->seperator, $this->TextSign)) {
|
|---|
| 230 | $row++; //increment row to get line number
|
|---|
| 231 | foreach($mapping as $name => $key) {
|
|---|
| 232 | $line_data[$name] = $line[$key];
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | if ($line_data['p_model'] != '') {
|
|---|
| 236 | if ($line_data['p_cat.0'] != '' || $this->FileSheme['p_cat.0'] != 'Y') { // if cat data field is empty or not existing
|
|---|
| 237 | if ($this->FileSheme['p_cat.0'] != 'Y') { // if cat data field is not existing
|
|---|
| 238 | if ($this->checkModel($line_data['p_model'])) { // if model no. already exists
|
|---|
| 239 | $this->insertProduct($line_data, 'update');
|
|---|
| 240 | } elseif ($this->CatDefault != '0') { // if model no. not existing and cat data field not exsisting and CatDefault is not TOP
|
|---|
| 241 | $this->insertProduct($line_data,'insert');
|
|---|
| 242 | }
|
|---|
| 243 | } else { // if cat data field existing
|
|---|
| 244 | if ($this->checkModel($line_data['p_model'])) {
|
|---|
| 245 | $this->insertProduct($line_data, 'update',true);
|
|---|
| 246 | } else {
|
|---|
| 247 | $this->insertProduct($line_data,'insert',true);
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 | } else { // if cat data field existing but empty
|
|---|
| 251 | if ($this->checkModel($line_data['p_model'])) { // if model no. already exists
|
|---|
| 252 | $this->insertProduct($line_data, 'update');
|
|---|
| 253 | } elseif ($this->CatDefault != '0') { // if model no. not existing and cat data field existing but empty and CatDefault is not TOP
|
|---|
| 254 | $this->insertProduct($line_data,'insert');
|
|---|
| 255 | } else { // cat data field existing but empty and no category choosen (i.e. TOP choosen)
|
|---|
| 256 | $this->errorLog[] = '<b>ERROR:</b> no Categorie, line: '.$row.' dataset: empty field: p_cat.0' . 'and no categrory selected';
|
|---|
| 257 | }
|
|---|
| 258 | }
|
|---|
| 259 | } else {
|
|---|
| 260 | $this->errorLog[] = '<b>ERROR:</b> no Modelnumber, line: '.$row.' dataset: empty field: p_model';
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|
| 263 | return array ($this->counter, $this->errorLog, $this->calcElapsedTime($this->time_start));
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | /*****************************************************************************
|
|---|
| 267 | **
|
|---|
| 268 | *F checkModel . . . . . . . . . . . . . . . . . . . . . . . . . . checkModel
|
|---|
| 269 | **
|
|---|
| 270 | ** Check if a product exists in database, query for model number
|
|---|
| 271 | **
|
|---|
| 272 | ** @param string $model products modelnumber
|
|---|
| 273 | ** @return boolean
|
|---|
| 274 | **
|
|---|
| 275 | *****************************************************************************/
|
|---|
| 276 |
|
|---|
| 277 | function checkModel($model) {
|
|---|
| 278 | $model_query = xtc_db_query("SELECT products_id
|
|---|
| 279 | FROM ".TABLE_PRODUCTS."
|
|---|
| 280 | WHERE products_model = '".xtc_db_input($model)."'
|
|---|
| 281 | ");
|
|---|
| 282 |
|
|---|
| 283 | if (!xtc_db_num_rows($model_query)) {
|
|---|
| 284 | return false;
|
|---|
| 285 | }
|
|---|
| 286 | return true;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | /*****************************************************************************
|
|---|
| 290 | **
|
|---|
| 291 | *F checkImage . . . . . . . . . . . . . . . . . . . . . . . . . . checkImage
|
|---|
| 292 | **
|
|---|
| 293 | ** Check if a image exists
|
|---|
| 294 | **
|
|---|
| 295 | ** @param string $model products modelnumber
|
|---|
| 296 | ** @return boolean
|
|---|
| 297 | **
|
|---|
| 298 | ******************************************************************************/
|
|---|
| 299 |
|
|---|
| 300 | function checkImage($imgID,$pID) {
|
|---|
| 301 | $img_query = xtc_db_query("SELECT image_id
|
|---|
| 302 | FROM ".TABLE_PRODUCTS_IMAGES."
|
|---|
| 303 | WHERE products_id = '".$pID."'
|
|---|
| 304 | AND image_nr = '".$imgID."'
|
|---|
| 305 | ");
|
|---|
| 306 |
|
|---|
| 307 | if (!xtc_db_num_rows($img_query)) {
|
|---|
| 308 | return false;
|
|---|
| 309 | }
|
|---|
| 310 | return true;
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | /*****************************************************************************
|
|---|
| 314 | **
|
|---|
| 315 | *F RemoveTextNotes . . . . . . . . . . . . . . . . . . . . . RemoveTextNotes
|
|---|
| 316 | **
|
|---|
| 317 | ** removing textnotes from a dataset
|
|---|
| 318 | **
|
|---|
| 319 | ** @param String $data data
|
|---|
| 320 | ** @return String cleaned data
|
|---|
| 321 | **
|
|---|
| 322 | ****************************************************************************/
|
|---|
| 323 | function RemoveTextNotes($data) {
|
|---|
| 324 | if(!empty($this->TextSign)) {
|
|---|
| 325 | if (substr($data, -1) == $this->TextSign) {
|
|---|
| 326 | $data = substr($data, 1, strlen($data) - 2);
|
|---|
| 327 | }
|
|---|
| 328 | return $data;
|
|---|
| 329 | }
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | /*****************************************************************************
|
|---|
| 333 | **
|
|---|
| 334 | *F getMAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . getMAN
|
|---|
| 335 | **
|
|---|
| 336 | ** Get/create manufacturers ID for a given Name
|
|---|
| 337 | **
|
|---|
| 338 | ** @param String $manufacturer Manufacturers name
|
|---|
| 339 | ** @return int manufacturers ID
|
|---|
| 340 | **
|
|---|
| 341 | *****************************************************************************/
|
|---|
| 342 |
|
|---|
| 343 | function getMAN($manufacturer) {
|
|---|
| 344 | if ($manufacturer == '') {
|
|---|
| 345 | return;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | if (isset ($this->mfn[$manufacturer]['id'])) {
|
|---|
| 349 | return $this->mfn[$manufacturer]['id'];
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | $man_query = xtc_db_query("SELECT manufacturers_id
|
|---|
| 353 | FROM ".TABLE_MANUFACTURERS."
|
|---|
| 354 | WHERE manufacturers_name = '". xtc_db_input($manufacturer) ."'
|
|---|
| 355 | ");
|
|---|
| 356 |
|
|---|
| 357 | if (!xtc_db_num_rows($man_query)) {
|
|---|
| 358 | $manufacturers_array = array (
|
|---|
| 359 | 'manufacturers_name' => $manufacturer,
|
|---|
| 360 | 'date_added' => 'now()'
|
|---|
| 361 | );
|
|---|
| 362 | xtc_db_perform(TABLE_MANUFACTURERS, $manufacturers_array);
|
|---|
| 363 | $this->mfn[$manufacturer]['id'] = xtc_db_insert_id();
|
|---|
| 364 | for ($i = 0; $i < $this->sizeof_languages; $i ++) {
|
|---|
| 365 | $insert_sql_data = array(
|
|---|
| 366 | 'manufacturers_id' => $this->mfn[$manufacturer]['id'],
|
|---|
| 367 | 'languages_id' => $this->languages[$i]['id']
|
|---|
| 368 | );
|
|---|
| 369 | xtc_db_perform(TABLE_MANUFACTURERS_INFO, $insert_sql_data);
|
|---|
| 370 | }
|
|---|
| 371 | } else {
|
|---|
| 372 | $man_data = xtc_db_fetch_array($man_query);
|
|---|
| 373 | $this->mfn[$manufacturer]['id'] = $man_data['manufacturers_id'];
|
|---|
| 374 |
|
|---|
| 375 | }
|
|---|
| 376 | return $this->mfn[$manufacturer]['id'];
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /*****************************************************************************
|
|---|
| 380 | **
|
|---|
| 381 | *F insertProduct . . . . . . . . . . . . . . . . . . . . . . . insertProduct
|
|---|
| 382 | **
|
|---|
| 383 | ** Insert a new product into Database
|
|---|
| 384 | **
|
|---|
| 385 | ** @param array $dataArray Linedata
|
|---|
| 386 | ** @param string $mode insert or update flag
|
|---|
| 387 | **
|
|---|
| 388 | *****************************************************************************/
|
|---|
| 389 |
|
|---|
| 390 | function insertProduct(& $dataArray, $mode = 'insert', $touchCat = false) {
|
|---|
| 391 |
|
|---|
| 392 | //BOC strip potential slashes and type cast inputs
|
|---|
| 393 | $products_array = array ('products_model' => xtc_db_prepare_input($dataArray['p_model']));
|
|---|
| 394 | if ($this->FileSheme['p_stock'] == 'Y')
|
|---|
| 395 | $products_array = array_merge($products_array, array ('products_quantity' => (int)$dataArray['p_stock']));
|
|---|
| 396 | if ($this->FileSheme['p_priceNoTax'] == 'Y')
|
|---|
| 397 | $products_array = array_merge($products_array, array ('products_price' => (float)$dataArray['p_priceNoTax']));
|
|---|
| 398 | if ($this->FileSheme['p_weight'] == 'Y')
|
|---|
| 399 | $products_array = array_merge($products_array, array ('products_weight' => (float)$dataArray['p_weight']));
|
|---|
| 400 | if ($this->FileSheme['p_status'] == 'Y')
|
|---|
| 401 | $products_array = array_merge($products_array, array ('products_status' => (int)$dataArray['p_status']));
|
|---|
| 402 | if ($this->FileSheme['p_image'] == 'Y')
|
|---|
| 403 | $products_array = array_merge($products_array, array ('products_image' => xtc_db_prepare_input($dataArray['p_image'])));
|
|---|
| 404 | if ($this->FileSheme['p_disc'] == 'Y')
|
|---|
| 405 | $products_array = array_merge($products_array, array ('products_discount_allowed' => (float)$dataArray['p_disc']));
|
|---|
| 406 | if ($this->FileSheme['p_ean'] == 'Y')
|
|---|
| 407 | $products_array = array_merge($products_array, array ('products_ean' => xtc_db_prepare_input($dataArray['p_ean'])));
|
|---|
| 408 | if ($this->FileSheme['p_man'] == 'Y')
|
|---|
| 409 | $products_array = array_merge($products_array, array ('products_manufacturers_model' => xtc_db_prepare_input($dataArray['p_man'])));
|
|---|
| 410 | if ($this->FileSheme['p_tax'] == 'Y')
|
|---|
| 411 | $products_array = array_merge($products_array, array ('products_tax_class_id' => (int)$dataArray['p_tax']));
|
|---|
| 412 | if ($this->FileSheme['p_opttpl'] == 'Y')
|
|---|
| 413 | $products_array = array_merge($products_array, array ('options_template' => xtc_db_prepare_input($dataArray['p_opttpl'])));
|
|---|
| 414 | if ($this->FileSheme['p_manufacturer'] == 'Y')
|
|---|
| 415 | $products_array = array_merge($products_array, array ('manufacturers_id' => $this->getMAN(xtc_db_prepare_input(trim($dataArray['p_manufacturer'])))));
|
|---|
| 416 | if ($this->FileSheme['p_fsk18'] == 'Y')
|
|---|
| 417 | $products_array = array_merge($products_array, array ('products_fsk18' => (int)$dataArray['p_fsk18']));
|
|---|
| 418 | if ($this->FileSheme['p_tpl'] == 'Y')
|
|---|
| 419 | $products_array = array_merge($products_array, array ('product_template' => xtc_db_prepare_input($dataArray['p_tpl'])));
|
|---|
| 420 | if ($this->FileSheme['p_vpe'] == 'Y')
|
|---|
| 421 | $products_array = array_merge($products_array, array ('products_vpe' => xtc_db_prepare_input($dataArray['p_vpe'])));
|
|---|
| 422 | if ($this->FileSheme['p_vpe_status'] == 'Y')
|
|---|
| 423 | $products_array = array_merge($products_array, array ('products_vpe_status' => (int)$dataArray['p_vpe_status']));
|
|---|
| 424 | if ($this->FileSheme['p_vpe_value'] == 'Y')
|
|---|
| 425 | $products_array = array_merge($products_array, array ('products_vpe_value' => (float)$dataArray['p_vpe_value']));
|
|---|
| 426 | if ($this->FileSheme['p_shipping'] == 'Y')
|
|---|
| 427 | $products_array = array_merge($products_array, array ('products_shippingtime' => (int)$dataArray['p_shipping']));
|
|---|
| 428 | if ($this->FileSheme['p_sorting'] == 'Y')
|
|---|
| 429 | $products_array = array_merge($products_array, array ('products_sort' => (int)$dataArray['p_sorting']));
|
|---|
| 430 | //EOC strip potential slashes and type cast inputs
|
|---|
| 431 |
|
|---|
| 432 | foreach(auto_include(DIR_FS_ADMIN.'includes/extra/modules/import/insert_before/','php') as $file) require ($file);
|
|---|
| 433 |
|
|---|
| 434 | if ($mode == 'insert') {
|
|---|
| 435 | $products_array = array_merge($products_array, array ('products_date_added' => date("Y-m-d H:i:s")));
|
|---|
| 436 | $this->counter['prod_new']++;
|
|---|
| 437 | xtc_db_perform(TABLE_PRODUCTS, $products_array);
|
|---|
| 438 | $products_id = xtc_db_insert_id();
|
|---|
| 439 | } else {
|
|---|
| 440 | $products_array = array_merge($products_array, array ('products_last_modified' => date("Y-m-d H:i:s")));
|
|---|
| 441 | $this->counter['prod_upd']++;
|
|---|
| 442 | xtc_db_perform(TABLE_PRODUCTS, $products_array, 'update', 'products_model = \''.xtc_db_input($dataArray['p_model']).'\'');
|
|---|
| 443 |
|
|---|
| 444 | $prod_query = xtc_db_query("SELECT products_id
|
|---|
| 445 | FROM ".TABLE_PRODUCTS."
|
|---|
| 446 | WHERE products_model = '".xtc_db_input($dataArray['p_model'])."'");
|
|---|
| 447 |
|
|---|
| 448 | $prod_data = xtc_db_fetch_array($prod_query);
|
|---|
| 449 | $products_id = $prod_data['products_id'];
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | // Insert group prices Qantity:Price::Quantity:Price
|
|---|
| 453 | for ($i = 0; $i < $this->count_groups - 1; $i ++) {
|
|---|
| 454 | // seperate string ::
|
|---|
| 455 | if (isset ($dataArray['p_priceNoTax.'.$this->Groups[$i +1]['id']]) && $dataArray['p_priceNoTax.'.$this->Groups[$i +1]['id']] != '') {
|
|---|
| 456 |
|
|---|
| 457 | $truncate_query = "DELETE FROM ".TABLE_PERSONAL_OFFERS_BY.$this->Groups[$i +1]['id']."
|
|---|
| 458 | WHERE products_id = '".$products_id."'";
|
|---|
| 459 |
|
|---|
| 460 | xtc_db_query($truncate_query);
|
|---|
| 461 | $prices = $dataArray['p_priceNoTax.'.$this->Groups[$i +1]['id']];
|
|---|
| 462 | $prices = explode('::', $prices);
|
|---|
| 463 | for ($ii = 0, $cp = count($prices); $ii < $cp; $ii ++) {
|
|---|
| 464 | $values = explode(':', $prices[$ii]);
|
|---|
| 465 |
|
|---|
| 466 | if ($values[0] > 0 ) {
|
|---|
| 467 | $group_array = array (
|
|---|
| 468 | 'products_id' => $products_id,
|
|---|
| 469 | 'quantity' => $values[0],
|
|---|
| 470 | 'personal_offer' => $values[1]
|
|---|
| 471 | );
|
|---|
| 472 |
|
|---|
| 473 | xtc_db_perform(TABLE_PERSONAL_OFFERS_BY.$this->Groups[$i +1]['id'], $group_array);
|
|---|
| 474 | }
|
|---|
| 475 | }
|
|---|
| 476 | }
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | // Insert group permissions.
|
|---|
| 480 | for ($i = 0; $i < $this->count_groups; $i ++) {
|
|---|
| 481 | if (isset ($dataArray['p_groupAcc.'.$this->Groups[$i]['id']])) {
|
|---|
| 482 | $insert_array = array ('group_permission_'.$this->Groups[$i]['id'] => $dataArray['p_groupAcc.'.$this->Groups[$i]['id']]);
|
|---|
| 483 | xtc_db_perform(TABLE_PRODUCTS, $insert_array, 'update', 'products_id = \''.$products_id.'\'');
|
|---|
| 484 | }
|
|---|
| 485 | }
|
|---|
| 486 |
|
|---|
| 487 | // insert images
|
|---|
| 488 | for ($i = 1; $i < MO_PICS + 1; $i ++) {
|
|---|
| 489 | if (isset($dataArray['p_image.'.$i]) && $dataArray['p_image.'.$i]!="") {
|
|---|
| 490 | // check if entry exists
|
|---|
| 491 | if ($this->checkImage($i,$products_id)) {
|
|---|
| 492 | $insert_array = array ('image_name' => $dataArray['p_image.'.$i]);
|
|---|
| 493 | xtc_db_perform(TABLE_PRODUCTS_IMAGES, $insert_array, 'update', 'products_id = \''.$products_id.'\' AND image_nr=\''.$i.'\'');
|
|---|
| 494 | } else {
|
|---|
| 495 | $insert_array = array (
|
|---|
| 496 | 'image_name' => $dataArray['p_image.'.$i],
|
|---|
| 497 | 'image_nr'=>$i,
|
|---|
| 498 | 'products_id'=>$products_id
|
|---|
| 499 | );
|
|---|
| 500 | xtc_db_perform(TABLE_PRODUCTS_IMAGES, $insert_array);
|
|---|
| 501 | }
|
|---|
| 502 | }
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | if ($touchCat) $this->insertCategory($dataArray, $products_id, $mode);
|
|---|
| 506 |
|
|---|
| 507 | for ($i_insert = 0; $i_insert < $this->sizeof_languages; $i_insert ++) {
|
|---|
| 508 | $prod_desc_array = array (
|
|---|
| 509 | 'products_id' => $products_id,
|
|---|
| 510 | 'language_id' => $this->languages[$i_insert]['id']
|
|---|
| 511 | );
|
|---|
| 512 |
|
|---|
| 513 | //BOC strip potential slashes
|
|---|
| 514 | if ($this->FileSheme['p_name.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 515 | $prod_desc_array = array_merge($prod_desc_array, array ('products_name' => xtc_db_prepare_input($dataArray['p_name.'.$this->languages[$i_insert]['code']])));
|
|---|
| 516 | if ($this->FileSheme['p_desc.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 517 | $prod_desc_array = array_merge($prod_desc_array, array ('products_description' => xtc_db_prepare_input($dataArray['p_desc.'.$this->languages[$i_insert]['code']])));
|
|---|
| 518 | if ($this->FileSheme['p_shortdesc.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 519 | $prod_desc_array = array_merge($prod_desc_array, array ('products_short_description' => xtc_db_prepare_input($dataArray['p_shortdesc.'.$this->languages[$i_insert]['code']])));
|
|---|
| 520 | if ($this->FileSheme['p_orderdesc.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 521 | $prod_desc_array = array_merge($prod_desc_array, array ('products_order_description' => xtc_db_prepare_input($dataArray['p_orderdesc.'.$this->languages[$i_insert]['code']])));
|
|---|
| 522 | if ($this->FileSheme['p_meta_title.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 523 | $prod_desc_array = array_merge($prod_desc_array, array ('products_meta_title' => xtc_db_prepare_input($dataArray['p_meta_title.'.$this->languages[$i_insert]['code']])));
|
|---|
| 524 | if ($this->FileSheme['p_meta_desc.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 525 | $prod_desc_array = array_merge($prod_desc_array, array ('products_meta_description' => xtc_db_prepare_input($dataArray['p_meta_desc.'.$this->languages[$i_insert]['code']])));
|
|---|
| 526 | if ($this->FileSheme['p_meta_key.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 527 | $prod_desc_array = array_merge($prod_desc_array, array ('products_meta_keywords' => xtc_db_prepare_input($dataArray['p_meta_key.'.$this->languages[$i_insert]['code']])));
|
|---|
| 528 | if ($this->FileSheme['p_keywords.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 529 | $prod_desc_array = array_merge($prod_desc_array, array ('products_keywords' => xtc_db_prepare_input($dataArray['p_keywords.'.$this->languages[$i_insert]['code']])));
|
|---|
| 530 | if ($this->FileSheme['p_url.'.$this->languages[$i_insert]['code']] == 'Y')
|
|---|
| 531 | $prod_desc_array = array_merge($prod_desc_array, array ('products_url' => xtc_db_prepare_input($dataArray['p_url.'.$this->languages[$i_insert]['code']])));
|
|---|
| 532 | //EOC strip potential slashes
|
|---|
| 533 |
|
|---|
| 534 | if ($mode == 'insert') {
|
|---|
| 535 | xtc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $prod_desc_array);
|
|---|
| 536 | } else {
|
|---|
| 537 | xtc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $prod_desc_array, 'update', 'products_id = \''.$products_id.'\' AND language_id=\''.$this->languages[$i_insert]['id'].'\'');
|
|---|
| 538 | }
|
|---|
| 539 | }
|
|---|
| 540 | // check for Category
|
|---|
| 541 | $categories_check_query = xtc_db_query("SELECT categories_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." WHERE products_id='".$products_id."'");
|
|---|
| 542 | if (!xtc_db_num_rows($categories_check_query)) {
|
|---|
| 543 | $this->insertPtoCconnection($products_id, $this->CatDefault);
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | foreach(auto_include(DIR_FS_ADMIN.'includes/extra/modules/import/insert_end/','php') as $file) require ($file);
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | /*****************************************************************************
|
|---|
| 550 | **
|
|---|
| 551 | *F insertCategory . . . . . . . . . . . . . . . . . . . . . . insertCategory
|
|---|
| 552 | **
|
|---|
| 553 | ** Match and insert Categories
|
|---|
| 554 | **
|
|---|
| 555 | ** @param array $dataArray data array
|
|---|
| 556 | ** @param string $mode insert mode
|
|---|
| 557 | ** @param int $pID products ID
|
|---|
| 558 | *****************************************************************************/
|
|---|
| 559 |
|
|---|
| 560 | function insertCategory(& $dataArray, $pID, $mode = 'insert') {
|
|---|
| 561 | if ($this->debug) {
|
|---|
| 562 | echo '<pre>';
|
|---|
| 563 | print_r($this->CatTree);
|
|---|
| 564 | echo '</pre>';
|
|---|
| 565 | }
|
|---|
| 566 | $cat = array ();
|
|---|
| 567 | $catTree = '';
|
|---|
| 568 | for ($i = 0; $i < $this->catDepth; $i ++) {
|
|---|
| 569 | if (trim($dataArray['p_cat.'.$i]) != '') {
|
|---|
| 570 | $cat[$i] = xtc_db_prepare_input(trim($dataArray['p_cat.'.$i]));
|
|---|
| 571 | $catTree .= '[\''.xtc_db_input($cat[$i]).'\']';
|
|---|
| 572 | }
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | $code = '$ID=$this->CatTree'.$catTree.'[\'ID\'];';
|
|---|
| 576 | //debug
|
|---|
| 577 | if ($this->debug) {echo '<pre>FIRST $CODE: ' . $code . '</pre>';}
|
|---|
| 578 | eval ($code);
|
|---|
| 579 | //debug
|
|---|
| 580 | if ($this->debug) echo '<pre>FIRST $ID: '.$ID.'</pre>';
|
|---|
| 581 |
|
|---|
| 582 | if (is_int($ID) || $ID == '0') {
|
|---|
| 583 | $this->insertPtoCconnection($pID, $ID);
|
|---|
| 584 | } else {
|
|---|
| 585 |
|
|---|
| 586 | $catTree = '';
|
|---|
| 587 | $parTree = '';
|
|---|
| 588 | $curr_ID = 0;
|
|---|
| 589 | for ($i = 0, $cc = count($cat); $i < $cc; $i ++) {
|
|---|
| 590 | $catTree .= '[\''.xtc_db_input($cat[$i]).'\']';
|
|---|
| 591 | $code = '$ID=$this->CatTree'.$catTree.'[\'ID\'];';
|
|---|
| 592 | //debug
|
|---|
| 593 | if ($this->debug) {echo '<pre>SECOND $CODE: ' . $code . '</pre>';}
|
|---|
| 594 |
|
|---|
| 595 | eval ($code);
|
|---|
| 596 | //debug
|
|---|
| 597 | if ($this->debug) {echo '<pre>SECOND $ID: ' . $ID . '</pre>';}
|
|---|
| 598 | if (is_int($ID) || $ID == '0') {
|
|---|
| 599 | $curr_ID = $ID;
|
|---|
| 600 | } else {
|
|---|
| 601 | $code = '$parent=$this->CatTree'.$parTree.'[\'ID\'];';
|
|---|
| 602 | //debug
|
|---|
| 603 | if ($this->debug) {echo '<pre>THIRD $CODE: ' . $code . '</pre>';}
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 | eval ($code);
|
|---|
| 607 | //debug
|
|---|
| 608 | if ($this->debug) echo '<pre>$PARENT: '.$parent.'</pre>';
|
|---|
| 609 |
|
|---|
| 610 | // check if categorie exists
|
|---|
| 611 | $cat_query = xtc_db_query("SELECT c.categories_id
|
|---|
| 612 | FROM ".TABLE_CATEGORIES." c
|
|---|
| 613 | JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd
|
|---|
| 614 | ON cd.categories_id = c.categories_id
|
|---|
| 615 | WHERE cd.categories_name = '".xtc_db_input($cat[$i])."'
|
|---|
| 616 | AND cd.language_id = '".$this->languages[0]['id']."'
|
|---|
| 617 | AND c.parent_id = '".$parent."'");
|
|---|
| 618 | if (!xtc_db_num_rows($cat_query)) { // insert categorie
|
|---|
| 619 | $categorie_data = array (
|
|---|
| 620 | 'parent_id' => $parent,
|
|---|
| 621 | 'categories_status' => 1,
|
|---|
| 622 | 'date_added' => 'now()',
|
|---|
| 623 | 'last_modified' => 'now()'
|
|---|
| 624 | );
|
|---|
| 625 |
|
|---|
| 626 | xtc_db_perform(TABLE_CATEGORIES, $categorie_data);
|
|---|
| 627 | $cat_id = xtc_db_insert_id();
|
|---|
| 628 |
|
|---|
| 629 | $this->counter['cat_new']++;
|
|---|
| 630 |
|
|---|
| 631 | $code = '$this->CatTree'.$parTree.'[\''.xtc_db_input($cat[$i]).'\'][\'ID\']='.$cat_id.';';
|
|---|
| 632 | //debug
|
|---|
| 633 | if ($this->debug) {echo '<pre>FOURTH $CODE: ' . $code . '</pre>';}
|
|---|
| 634 |
|
|---|
| 635 | eval ($code);
|
|---|
| 636 | //debug
|
|---|
| 637 | if ($this->debug) echo '<pre>FIRST $CAT_ID: '.$cat_id.'</pre><hr />';
|
|---|
| 638 |
|
|---|
| 639 | $parent = $cat_id;
|
|---|
| 640 | for ($i_insert = 0; $i_insert < $this->sizeof_languages; $i_insert ++) {
|
|---|
| 641 | $categorie_data = array (
|
|---|
| 642 | 'language_id' => $this->languages[$i_insert]['id'],
|
|---|
| 643 | 'categories_id' => $cat_id,
|
|---|
| 644 | 'categories_name' => $cat[$i]
|
|---|
| 645 | );
|
|---|
| 646 | xtc_db_perform(TABLE_CATEGORIES_DESCRIPTION, $categorie_data);
|
|---|
| 647 | }
|
|---|
| 648 | } else {
|
|---|
| 649 | $this->counter['cat_touched']++;
|
|---|
| 650 | $cData = xtc_db_fetch_array($cat_query);
|
|---|
| 651 | $cat_id = $cData['categories_id'];
|
|---|
| 652 | $code = '$this->CatTree'.$parTree.'[\''.xtc_db_input($cat[$i]).'\'][\'ID\']='.$cat_id.';';
|
|---|
| 653 | //debug
|
|---|
| 654 | if ($this->debug) {echo '<pre>FIFTH $CODE: ' . $code . '</pre>';}
|
|---|
| 655 |
|
|---|
| 656 | eval ($code);
|
|---|
| 657 | //debug
|
|---|
| 658 | if ($this->debug) echo '<pre>SECOND $CAT_ID: '.$cat_id.'</pre><hr />';
|
|---|
| 659 | }
|
|---|
| 660 | }
|
|---|
| 661 | $parTree = $catTree;
|
|---|
| 662 | }
|
|---|
| 663 | $this->insertPtoCconnection($pID, $cat_id);
|
|---|
| 664 | }
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | /*****************************************************************************
|
|---|
| 668 | **
|
|---|
| 669 | *F insertPtoCconnection . . . . . . . . . . . . . . . . insertPtoCconnection
|
|---|
| 670 | **
|
|---|
| 671 | ** Insert products to categories connection
|
|---|
| 672 | **
|
|---|
| 673 | ** @param int $pID products ID
|
|---|
| 674 | ** @param int $cID categories ID
|
|---|
| 675 | **
|
|---|
| 676 | *****************************************************************************/
|
|---|
| 677 |
|
|---|
| 678 | function insertPtoCconnection($pID, $cID) {
|
|---|
| 679 | $prod2cat_query = xtc_db_query("SELECT *
|
|---|
| 680 | FROM ".TABLE_PRODUCTS_TO_CATEGORIES."
|
|---|
| 681 | WHERE categories_id = '".$cID."'
|
|---|
| 682 | AND products_id = '".$pID."'
|
|---|
| 683 | ");
|
|---|
| 684 |
|
|---|
| 685 | if (!xtc_db_num_rows($prod2cat_query)) {
|
|---|
| 686 | $insert_data = array (
|
|---|
| 687 | 'products_id' => $pID,
|
|---|
| 688 | 'categories_id' => $cID
|
|---|
| 689 | );
|
|---|
| 690 |
|
|---|
| 691 | xtc_db_perform(TABLE_PRODUCTS_TO_CATEGORIES, $insert_data);
|
|---|
| 692 | }
|
|---|
| 693 | }
|
|---|
| 694 |
|
|---|
| 695 | /*****************************************************************************
|
|---|
| 696 | **
|
|---|
| 697 | *F get_line_content . . . . . . . . . . . . . . . . . . . . get_line_content
|
|---|
| 698 | **
|
|---|
| 699 | ** Parse Inputfile until next line
|
|---|
| 700 | **
|
|---|
| 701 | ** @param int $line taxrate in percent
|
|---|
| 702 | ** @param string $file_content taxrate in percent
|
|---|
| 703 | ** @param int $max_lines taxrate in percent
|
|---|
| 704 | ** @return array
|
|---|
| 705 | *****************************************************************************/
|
|---|
| 706 |
|
|---|
| 707 | function get_line_content($line, $file_content, $max_lines) {
|
|---|
| 708 | // get first line
|
|---|
| 709 | $line_data = array ();
|
|---|
| 710 | $line_data['data'] = $file_content[$line];
|
|---|
| 711 | $lc = 1;
|
|---|
| 712 | // check if next line got ; in first 50 chars
|
|---|
| 713 | while (!strpos(substr($file_content[$line + $lc], 0, 6), 'XTSOL') && $line + $lc <= $max_lines) {
|
|---|
| 714 | $line_data['data'] .= $file_content[$line + $lc];
|
|---|
| 715 | $lc ++;
|
|---|
| 716 | }
|
|---|
| 717 | $line_data['skip'] = $lc -1;
|
|---|
| 718 | return $line_data;
|
|---|
| 719 | }
|
|---|
| 720 |
|
|---|
| 721 | /*****************************************************************************
|
|---|
| 722 | **
|
|---|
| 723 | *F calcElapsedTime . . . . . . . . . . . . . . . . . . . . . calcElapsedTime
|
|---|
| 724 | **
|
|---|
| 725 | ** Calculate Elapsed time from 2 given Timestamps
|
|---|
| 726 | ** @param int $time old timestamp
|
|---|
| 727 | ** @return String elapsed time
|
|---|
| 728 | **
|
|---|
| 729 | ****************************************************************************/
|
|---|
| 730 | function calcElapsedTime($time) {
|
|---|
| 731 |
|
|---|
| 732 | // calculate elapsed time (in seconds!)
|
|---|
| 733 | $diff = time() - $time;
|
|---|
| 734 | $daysDiff = 0;
|
|---|
| 735 | $hrsDiff = 0;
|
|---|
| 736 | $minsDiff = 0;
|
|---|
| 737 | $secsDiff = 0;
|
|---|
| 738 |
|
|---|
| 739 | $sec_in_a_day = 60 * 60 * 24;
|
|---|
| 740 | while ($diff >= $sec_in_a_day) {
|
|---|
| 741 | $daysDiff ++;
|
|---|
| 742 | $diff -= $sec_in_a_day;
|
|---|
| 743 | }
|
|---|
| 744 | $sec_in_an_hour = 60 * 60;
|
|---|
| 745 | while ($diff >= $sec_in_an_hour) {
|
|---|
| 746 | $hrsDiff ++;
|
|---|
| 747 | $diff -= $sec_in_an_hour;
|
|---|
| 748 | }
|
|---|
| 749 | $sec_in_a_min = 60;
|
|---|
| 750 | while ($diff >= $sec_in_a_min) {
|
|---|
| 751 | $minsDiff ++;
|
|---|
| 752 | $diff -= $sec_in_a_min;
|
|---|
| 753 | }
|
|---|
| 754 | $secsDiff = $diff;
|
|---|
| 755 |
|
|---|
| 756 | return ('(elapsed time '.$hrsDiff.'h '.$minsDiff.'m '.$secsDiff.'s)');
|
|---|
| 757 |
|
|---|
| 758 | }
|
|---|
| 759 |
|
|---|
| 760 | /*****************************************************************************
|
|---|
| 761 | **
|
|---|
| 762 | *F get_mfn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_mfn
|
|---|
| 763 | **
|
|---|
| 764 | ** Get manufacturers
|
|---|
| 765 | **
|
|---|
| 766 | ** @return array
|
|---|
| 767 | **
|
|---|
| 768 | ****************************************************************************/
|
|---|
| 769 | function get_mfn() {
|
|---|
| 770 | $mfn_query = xtc_db_query("SELECT manufacturers_id,
|
|---|
| 771 | manufacturers_name
|
|---|
| 772 | FROM ".TABLE_MANUFACTURERS);
|
|---|
| 773 | while ($mfn = xtc_db_fetch_array($mfn_query)) {
|
|---|
| 774 | $mfn_array[$mfn['manufacturers_name']] = array ('id' => $mfn['manufacturers_id']);
|
|---|
| 775 | }
|
|---|
| 776 | return $mfn_array;
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | /*******************************************************************************
|
|---|
| 782 | **
|
|---|
| 783 | *C xtcExport . . . . . . . . . . . . . . . . . . . . . . . . . . . . xtcExport
|
|---|
| 784 | **
|
|---|
| 785 | *******************************************************************************/
|
|---|
| 786 |
|
|---|
| 787 | class xtcExport {
|
|---|
| 788 |
|
|---|
| 789 | /*****************************************************************************
|
|---|
| 790 | **
|
|---|
| 791 | *F xtcExport . . . . . . . . . . . . . . . . . . . . . . . . . . . xtcExport
|
|---|
| 792 | **
|
|---|
| 793 | *****************************************************************************/
|
|---|
| 794 |
|
|---|
| 795 | function __construct($filename) {
|
|---|
| 796 | $this->catDepth = defined('CSV_CAT_DEPTH') ? CSV_CAT_DEPTH : 4;
|
|---|
| 797 | $this->languages = $this->get_lang();
|
|---|
| 798 | $this->filename = $filename;
|
|---|
| 799 | $this->CAT = array ();
|
|---|
| 800 | $this->PARENT = array ();
|
|---|
| 801 | $this->counter = array ('prod_exp' => 0);
|
|---|
| 802 | $this->time_start = time();
|
|---|
| 803 | $this->man = $this->getManufacturers();
|
|---|
| 804 | $this->TextSign = CSV_TEXTSIGN;
|
|---|
| 805 | //BOC set default text sign in export
|
|---|
| 806 | /*if (trim(CSV_TEXTSIGN) == '') {
|
|---|
| 807 | $this->TextSign = '"';
|
|---|
| 808 | }*/
|
|---|
| 809 | //EOC set default text sign in export
|
|---|
| 810 | $this->seperator = CSV_SEPERATOR;
|
|---|
| 811 | if (CSV_SEPERATOR == '')
|
|---|
| 812 | $this->seperator = "\t";
|
|---|
| 813 | if (CSV_SEPERATOR == xtc_db_prepare_input('\t')) //added stripslashes() since this is called in background in gID=20 (/admin/configuration.php)
|
|---|
| 814 | $this->seperator = "\t";
|
|---|
| 815 |
|
|---|
| 816 | $this->Groups = xtc_get_customers_statuses();
|
|---|
| 817 | $this->count_groups = count($this->Groups);
|
|---|
| 818 | $this->sizeof_languages = sizeof($this->languages);
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | /*****************************************************************************
|
|---|
| 822 | **
|
|---|
| 823 | *F get_lang . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_lang
|
|---|
| 824 | **
|
|---|
| 825 | ** Get installed languages
|
|---|
| 826 | **
|
|---|
| 827 | ** @return array
|
|---|
| 828 | **
|
|---|
| 829 | *****************************************************************************/
|
|---|
| 830 |
|
|---|
| 831 | function get_lang() {
|
|---|
| 832 | $languages_query = xtc_db_query('SELECT languages_id,
|
|---|
| 833 | name,
|
|---|
| 834 | code,
|
|---|
| 835 | image,
|
|---|
| 836 | directory
|
|---|
| 837 | FROM '.TABLE_LANGUAGES.'
|
|---|
| 838 | ORDER BY sort_order
|
|---|
| 839 | ');
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 | while ($languages = xtc_db_fetch_array($languages_query)) {
|
|---|
| 843 | $languages_array[] = array (
|
|---|
| 844 | 'id' => $languages['languages_id'],
|
|---|
| 845 | 'name' => $languages['name'],
|
|---|
| 846 | 'code' => $languages['code']
|
|---|
| 847 | );
|
|---|
| 848 | }
|
|---|
| 849 | return $languages_array;
|
|---|
| 850 | }
|
|---|
| 851 |
|
|---|
| 852 | /*****************************************************************************
|
|---|
| 853 | **
|
|---|
| 854 | *F encode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . encode
|
|---|
| 855 | **
|
|---|
| 856 | ****************************************************************************/
|
|---|
| 857 | function encode($data) {
|
|---|
| 858 | $result = $data;
|
|---|
| 859 | $delim = false;
|
|---|
| 860 | if (strpos($data, $this->seperator) !== false) {
|
|---|
| 861 | $delim = true;
|
|---|
| 862 | } elseif(substr($data,0,1)==$this->TextSign) {
|
|---|
| 863 | $delim = true;
|
|---|
| 864 | //BOC set TextSign also when TextSign occurs within $data
|
|---|
| 865 | } elseif(strpos($data, $this->TextSign) !== false) {
|
|---|
| 866 | $delim = true;
|
|---|
| 867 | }
|
|---|
| 868 | //EOC set TextSign also when TextSign occurs within $data
|
|---|
| 869 | if($delim) {
|
|---|
| 870 | $result = $this->TextSign.str_replace($this->TextSign, str_repeat($this->TextSign,2), $data).$this->TextSign;
|
|---|
| 871 | }
|
|---|
| 872 | return $result.$this->seperator;
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | /*****************************************************************************
|
|---|
| 876 | **
|
|---|
| 877 | *F exportProdFile . . . . . . . . . . . . . . . . . . . . . . exportProdFile
|
|---|
| 878 | **
|
|---|
| 879 | ****************************************************************************/
|
|---|
| 880 | function exportProdFile() {
|
|---|
| 881 |
|
|---|
| 882 | $fp = fopen(DIR_FS_CATALOG.'export/'.$this->filename, "w+");
|
|---|
| 883 | $line = '';
|
|---|
| 884 | $headings = array('XTSOL',
|
|---|
| 885 | 'p_model',
|
|---|
| 886 | 'p_stock',
|
|---|
| 887 | 'p_sorting',
|
|---|
| 888 | 'p_shipping',
|
|---|
| 889 | 'p_tpl',
|
|---|
| 890 | 'p_manufacturer',
|
|---|
| 891 | 'p_fsk18',
|
|---|
| 892 | 'p_priceNoTax');
|
|---|
| 893 | foreach($headings as $heading) {
|
|---|
| 894 | $line .= $this->encode($heading);
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | for ($i=1; $i < $this->count_groups; $i++) {
|
|---|
| 898 | $line .= $this->encode('p_priceNoTax.'.$this->Groups[$i]['id']);
|
|---|
| 899 | }
|
|---|
| 900 | if (GROUP_CHECK == 'true') {
|
|---|
| 901 | for ($i=0; $i < $this->count_groups; $i++) {
|
|---|
| 902 | $line .= $this->encode('p_groupAcc.'.$this->Groups[$i]['id']);
|
|---|
| 903 | }
|
|---|
| 904 | }
|
|---|
| 905 |
|
|---|
| 906 | $headings = array('p_tax',
|
|---|
| 907 | 'p_status',
|
|---|
| 908 | 'p_weight',
|
|---|
| 909 | 'p_ean',
|
|---|
| 910 | 'p_man',
|
|---|
| 911 | 'p_disc',
|
|---|
| 912 | 'p_opttpl',
|
|---|
| 913 | 'p_vpe',
|
|---|
| 914 | 'p_vpe_status',
|
|---|
| 915 | 'p_vpe_value');
|
|---|
| 916 | foreach($headings as $heading) {
|
|---|
| 917 | $line .= $this->encode($heading);
|
|---|
| 918 | }
|
|---|
| 919 |
|
|---|
| 920 | // product images
|
|---|
| 921 | for ($i = 1; $i < MO_PICS + 1; $i ++) {
|
|---|
| 922 | $line .= $this->encode('p_image.'.$i);
|
|---|
| 923 | }
|
|---|
| 924 |
|
|---|
| 925 | $line .= $this->encode('p_image');
|
|---|
| 926 |
|
|---|
| 927 | // add lang fields
|
|---|
| 928 | for ($i = 0; $i < $this->sizeof_languages; $i ++) {
|
|---|
| 929 | $line .= $this->encode('p_name.'.$this->languages[$i]['code']);
|
|---|
| 930 | $line .= $this->encode('p_desc.'.$this->languages[$i]['code']);
|
|---|
| 931 | $line .= $this->encode('p_shortdesc.'.$this->languages[$i]['code']);
|
|---|
| 932 | $line .= $this->encode('p_orderdesc.'.$this->languages[$i]['code']); //added order description
|
|---|
| 933 | $line .= $this->encode('p_meta_title.'.$this->languages[$i]['code']);
|
|---|
| 934 | $line .= $this->encode('p_meta_desc.'.$this->languages[$i]['code']);
|
|---|
| 935 | $line .= $this->encode('p_meta_key.'.$this->languages[$i]['code']);
|
|---|
| 936 | $line .= $this->encode('p_keywords.'.$this->languages[$i]['code']);
|
|---|
| 937 | $line .= $this->encode('p_url.'.$this->languages[$i]['code']);
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | // add categorie fields
|
|---|
| 941 | for ($i = 0; $i < $this->catDepth; $i ++) {
|
|---|
| 942 | $line .= $this->encode('p_cat.'.$i);
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | foreach(auto_include(DIR_FS_ADMIN.'includes/extra/modules/export/file_layout/','php') as $file) require ($file);
|
|---|
| 946 |
|
|---|
| 947 | fputs($fp, $line."\n");
|
|---|
| 948 |
|
|---|
| 949 | // content
|
|---|
| 950 | $export_query = xtc_db_query('-- admin/includes/classes/import.php export
|
|---|
| 951 | SELECT *
|
|---|
| 952 | FROM '.TABLE_PRODUCTS
|
|---|
| 953 | );
|
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 | while ($export_data = xtc_db_fetch_array($export_query)) {
|
|---|
| 957 | $this->counter['prod_exp']++;
|
|---|
| 958 | $line = $this->encode('XTSOL');
|
|---|
| 959 | $line .= $this->encode($export_data['products_model']);
|
|---|
| 960 | $line .= $this->encode($export_data['products_quantity']);
|
|---|
| 961 | $line .= $this->encode($export_data['products_sort']);
|
|---|
| 962 | $line .= $this->encode($export_data['products_shippingtime']);
|
|---|
| 963 | $line .= $this->encode($export_data['product_template']);
|
|---|
| 964 | $line .= $this->encode($this->man[$export_data['manufacturers_id']]);
|
|---|
| 965 | $line .= $this->encode($export_data['products_fsk18']);
|
|---|
| 966 | $line .= $this->encode($export_data['products_price']);
|
|---|
| 967 |
|
|---|
| 968 | // group prices Qantity:Price::Quantity:Price
|
|---|
| 969 | for ($i=1; $i < $this->count_groups; $i++) {
|
|---|
| 970 | $price_query = "SELECT *
|
|---|
| 971 | FROM ".TABLE_PERSONAL_OFFERS_BY.$this->Groups[$i]['id']."
|
|---|
| 972 | WHERE products_id = '".$export_data['products_id']."'
|
|---|
| 973 | ORDER BY quantity";
|
|---|
| 974 |
|
|---|
| 975 |
|
|---|
| 976 | $price_query = xtc_db_query($price_query);
|
|---|
| 977 | $groupPrice = '';
|
|---|
| 978 | while ($price_data = xtc_db_fetch_array($price_query)) {
|
|---|
| 979 | if ($price_data['personal_offer'] > 0) {
|
|---|
| 980 | $groupPrice .= $price_data['quantity'].':'.$price_data['personal_offer'].'::';
|
|---|
| 981 | }
|
|---|
| 982 | }
|
|---|
| 983 | $groupPrice .= ':';
|
|---|
| 984 | $groupPrice = str_replace(':::', '', $groupPrice);
|
|---|
| 985 | if ($groupPrice == ':')
|
|---|
| 986 | $groupPrice = "";
|
|---|
| 987 |
|
|---|
| 988 | $line .= $this->encode($groupPrice);
|
|---|
| 989 |
|
|---|
| 990 | }
|
|---|
| 991 |
|
|---|
| 992 | // group permissions
|
|---|
| 993 | if (GROUP_CHECK == 'true') {
|
|---|
| 994 | for ($i=0; $i < $this->count_groups; $i++) {
|
|---|
| 995 | $line .= $this->encode($export_data['group_permission_'.$this->Groups[$i]['id']]);
|
|---|
| 996 | }
|
|---|
| 997 | }
|
|---|
| 998 |
|
|---|
| 999 | $line .= $this->encode($export_data['products_tax_class_id']);
|
|---|
| 1000 | $line .= $this->encode($export_data['products_status']);
|
|---|
| 1001 | $line .= $this->encode($export_data['products_weight']);
|
|---|
| 1002 | $line .= $this->encode($export_data['products_ean']);
|
|---|
| 1003 | $line .= $this->encode($export_data['products_manufacturers_model']);
|
|---|
| 1004 | $line .= $this->encode($export_data['products_discount_allowed']);
|
|---|
| 1005 | $line .= $this->encode($export_data['options_template']);
|
|---|
| 1006 | $line .= $this->encode($export_data['products_vpe']);
|
|---|
| 1007 | $line .= $this->encode($export_data['products_vpe_status']);
|
|---|
| 1008 | $line .= $this->encode($export_data['products_vpe_value']);
|
|---|
| 1009 |
|
|---|
| 1010 | if (MO_PICS > 0) {
|
|---|
| 1011 | $mo_query = "SELECT *
|
|---|
| 1012 | FROM ".TABLE_PRODUCTS_IMAGES."
|
|---|
| 1013 | WHERE products_id = '".$export_data['products_id']."'";
|
|---|
| 1014 |
|
|---|
| 1015 | $mo_query = xtc_db_query($mo_query);
|
|---|
| 1016 | $img = array ();
|
|---|
| 1017 | while ($mo_data = xtc_db_fetch_array($mo_query)) {
|
|---|
| 1018 | $img[$mo_data['image_nr']] = $mo_data['image_name'];
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | }
|
|---|
| 1022 |
|
|---|
| 1023 | // product images
|
|---|
| 1024 | for ($i = 1; $i < MO_PICS + 1; $i ++) {
|
|---|
| 1025 | if (isset ($img[$i])) {
|
|---|
| 1026 | $line .= $this->encode($img[$i]);
|
|---|
| 1027 | } else {
|
|---|
| 1028 | $line .= $this->encode('');
|
|---|
| 1029 | }
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | $line .= $this->encode($export_data['products_image']);
|
|---|
| 1033 |
|
|---|
| 1034 | for ($i = 0; $i < $this->sizeof_languages; $i ++) {
|
|---|
| 1035 | $lang_query = xtc_db_query("SELECT *
|
|---|
| 1036 | FROM ".TABLE_PRODUCTS_DESCRIPTION."
|
|---|
| 1037 | WHERE language_id = '".$this->languages[$i]['id']."'
|
|---|
| 1038 | AND products_id = '".$export_data['products_id']."'
|
|---|
| 1039 | ");
|
|---|
| 1040 |
|
|---|
| 1041 | $lang_data = xtc_db_fetch_array($lang_query);
|
|---|
| 1042 | $lang_data['products_description'] = str_replace("\n", "", $lang_data['products_description']);
|
|---|
| 1043 | $lang_data['products_short_description'] = str_replace("\n", "", $lang_data['products_short_description']);
|
|---|
| 1044 | $lang_data['products_order_description'] = str_replace("\n", "", $lang_data['products_order_description']); //added order description
|
|---|
| 1045 | $lang_data['products_description'] = str_replace("\r", "", $lang_data['products_description']);
|
|---|
| 1046 | $lang_data['products_short_description'] = str_replace("\r", "", $lang_data['products_short_description']);
|
|---|
| 1047 | $lang_data['products_order_description'] = str_replace("\r", "", $lang_data['products_order_description']); //added order description
|
|---|
| 1048 | $lang_data['products_description'] = str_replace(chr(13), "", $lang_data['products_description']);
|
|---|
| 1049 | $lang_data['products_short_description'] = str_replace(chr(13), "", $lang_data['products_short_description']);
|
|---|
| 1050 | $lang_data['products_order_description'] = str_replace(chr(13), "", $lang_data['products_order_description']); //added order description
|
|---|
| 1051 | $line .= $this->encode(stripslashes($lang_data['products_name']));
|
|---|
| 1052 | $line .= $this->encode(stripslashes($lang_data['products_description']));
|
|---|
| 1053 | $line .= $this->encode(stripslashes($lang_data['products_short_description']));
|
|---|
| 1054 | $line .= $this->encode(stripslashes($lang_data['products_order_description'])); //added order description
|
|---|
| 1055 | $line .= $this->encode(stripslashes($lang_data['products_meta_title']));
|
|---|
| 1056 | $line .= $this->encode(stripslashes($lang_data['products_meta_description']));
|
|---|
| 1057 | $line .= $this->encode(stripslashes($lang_data['products_meta_keywords']));
|
|---|
| 1058 | $line .= $this->encode(stripslashes($lang_data['products_keywords']));
|
|---|
| 1059 | $line .= $this->encode($lang_data['products_url']);
|
|---|
| 1060 | }
|
|---|
| 1061 |
|
|---|
| 1062 | $cat_query = xtc_db_query("SELECT categories_id
|
|---|
| 1063 | FROM ".TABLE_PRODUCTS_TO_CATEGORIES."
|
|---|
| 1064 | WHERE products_id = '".$export_data['products_id']."'
|
|---|
| 1065 | ");
|
|---|
| 1066 |
|
|---|
| 1067 |
|
|---|
| 1068 |
|
|---|
| 1069 | $cat_data = xtc_db_fetch_array($cat_query);
|
|---|
| 1070 | $line .= $this->buildCAT($cat_data['categories_id']);
|
|---|
| 1071 |
|
|---|
| 1072 | foreach(auto_include(DIR_FS_ADMIN.'includes/extra/modules/export/export_end/','php') as $file) require ($file);
|
|---|
| 1073 |
|
|---|
| 1074 | fputs($fp, $line."\n");
|
|---|
| 1075 | }
|
|---|
| 1076 | fclose($fp);
|
|---|
| 1077 |
|
|---|
| 1078 | return array (
|
|---|
| 1079 | 0 => $this->counter, 1 => '',
|
|---|
| 1080 | 2 => $this->calcElapsedTime($this->time_start)
|
|---|
| 1081 | );
|
|---|
| 1082 | }
|
|---|
| 1083 |
|
|---|
| 1084 | /*****************************************************************************
|
|---|
| 1085 | **
|
|---|
| 1086 | *F calcElapsedTime . . . . . . . . . . . . . . . . . . . . . calcElapsedTime
|
|---|
| 1087 | **
|
|---|
| 1088 | ** Calculate Elapsed time from 2 given Timestamps
|
|---|
| 1089 | **
|
|---|
| 1090 | ** @param int $time old timestamp
|
|---|
| 1091 | ** @return String elapsed time
|
|---|
| 1092 | *****************************************************************************/
|
|---|
| 1093 |
|
|---|
| 1094 | function calcElapsedTime($time) {
|
|---|
| 1095 |
|
|---|
| 1096 | $diff = time() - $time;
|
|---|
| 1097 | $daysDiff = 0;
|
|---|
| 1098 | $hrsDiff = 0;
|
|---|
| 1099 | $minsDiff = 0;
|
|---|
| 1100 | $secsDiff = 0;
|
|---|
| 1101 |
|
|---|
| 1102 | $sec_in_a_day = 60 * 60 * 24;
|
|---|
| 1103 | while ($diff >= $sec_in_a_day) {
|
|---|
| 1104 | $daysDiff ++;
|
|---|
| 1105 | $diff -= $sec_in_a_day;
|
|---|
| 1106 | }
|
|---|
| 1107 |
|
|---|
| 1108 | $sec_in_an_hour = 60 * 60;
|
|---|
| 1109 | while ($diff >= $sec_in_an_hour) {
|
|---|
| 1110 | $hrsDiff ++;
|
|---|
| 1111 | $diff -= $sec_in_an_hour;
|
|---|
| 1112 | }
|
|---|
| 1113 |
|
|---|
| 1114 | $sec_in_a_min = 60;
|
|---|
| 1115 | while ($diff >= $sec_in_a_min) {
|
|---|
| 1116 | $minsDiff ++;
|
|---|
| 1117 | $diff -= $sec_in_a_min;
|
|---|
| 1118 | }
|
|---|
| 1119 |
|
|---|
| 1120 | $secsDiff = $diff;
|
|---|
| 1121 |
|
|---|
| 1122 | return ('(elapsed time '.$hrsDiff.'h '.$minsDiff.'m '.$secsDiff.'s)');
|
|---|
| 1123 |
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | /*****************************************************************************
|
|---|
| 1127 | **
|
|---|
| 1128 | *F buildCAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . buildCAT
|
|---|
| 1129 | **
|
|---|
| 1130 | *****************************************************************************/
|
|---|
| 1131 |
|
|---|
| 1132 | function buildCAT($catID) {
|
|---|
| 1133 | if (!isset($this->CAT[$catID])) {
|
|---|
| 1134 | $this->CAT[$catID]=array();
|
|---|
| 1135 | $tmpID = $catID;
|
|---|
| 1136 |
|
|---|
| 1137 | while ($this->getParent($tmpID) != 0 || $tmpID != 0) {
|
|---|
| 1138 | $sql = '-- admin/includes/classes/import export buildCat
|
|---|
| 1139 | SELECT categories_name
|
|---|
| 1140 | FROM '.TABLE_CATEGORIES_DESCRIPTION.'
|
|---|
| 1141 | WHERE categories_id = '.$tmpID.' and language_id = '.$this->languages[0]['id'];
|
|---|
| 1142 |
|
|---|
| 1143 | $query = xtc_db_query($sql);
|
|---|
| 1144 | $cat_data = xtc_db_fetch_array($query);
|
|---|
| 1145 | $tmpID = $this->getParent($tmpID);
|
|---|
| 1146 | array_unshift($this->CAT[$catID], $this->encode($cat_data['categories_name']));
|
|---|
| 1147 | }
|
|---|
| 1148 |
|
|---|
| 1149 | for ($i=$this->catDepth - count($this->CAT[$catID]); $i>0; $i--) {
|
|---|
| 1150 | $this->CAT[$catID][] = $this->encode('');
|
|---|
| 1151 | }
|
|---|
| 1152 | }
|
|---|
| 1153 | return implode('', $this->CAT[$catID]);
|
|---|
| 1154 | }
|
|---|
| 1155 |
|
|---|
| 1156 | /*****************************************************************************
|
|---|
| 1157 | **
|
|---|
| 1158 | *F getTaxRates . . . . . . . . . . . . . . . . . . . . . . . . . getTaxRates
|
|---|
| 1159 | **
|
|---|
| 1160 | ** Get the tax_class_id to a given %rate
|
|---|
| 1161 | **
|
|---|
| 1162 | ** @return array
|
|---|
| 1163 | **
|
|---|
| 1164 | *****************************************************************************/
|
|---|
| 1165 |
|
|---|
| 1166 | function getTaxRates() { // must be optimazed (pre caching array)
|
|---|
| 1167 | $tax = array ();
|
|---|
| 1168 | $tax_query = xtc_db_query("SELECT tr.tax_class_id,
|
|---|
| 1169 | tr.tax_rate,
|
|---|
| 1170 | ztz.geo_zone_id
|
|---|
| 1171 | FROM ".TABLE_TAX_RATES." tr
|
|---|
| 1172 | JOIN ".TABLE_ZONES_TO_GEO_ZONES." ztz
|
|---|
| 1173 | ON tr.tax_zone_id = ztz.geo_zone_id
|
|---|
| 1174 | WHERE ztz.zone_country_id='".STORE_COUNTRY."'");
|
|---|
| 1175 | while ($tax_data = xtc_db_fetch_array($tax_query)) {
|
|---|
| 1176 |
|
|---|
| 1177 | $tax[$tax_data['tax_class_id']] = $tax_data['tax_rate'];
|
|---|
| 1178 |
|
|---|
| 1179 | }
|
|---|
| 1180 | return $tax;
|
|---|
| 1181 | }
|
|---|
| 1182 |
|
|---|
| 1183 | /*****************************************************************************
|
|---|
| 1184 | **
|
|---|
| 1185 | *F getManufacturers . . . . . . . . . . . . . . . . . . . . getManufacturers
|
|---|
| 1186 | **
|
|---|
| 1187 | ** Prefetch Manufactrers
|
|---|
| 1188 | **
|
|---|
| 1189 | ** @return array
|
|---|
| 1190 | **
|
|---|
| 1191 | *****************************************************************************/
|
|---|
| 1192 |
|
|---|
| 1193 | function getManufacturers() {
|
|---|
| 1194 | $man = array ();
|
|---|
| 1195 | $man_query = xtc_db_query("SELECT manufacturers_name,
|
|---|
| 1196 | manufacturers_id
|
|---|
| 1197 | FROM ".TABLE_MANUFACTURERS);
|
|---|
| 1198 |
|
|---|
| 1199 | while ($man_data = xtc_db_fetch_array($man_query)) {
|
|---|
| 1200 | $man[$man_data['manufacturers_id']] = $man_data['manufacturers_name'];
|
|---|
| 1201 | }
|
|---|
| 1202 | return $man;
|
|---|
| 1203 | }
|
|---|
| 1204 |
|
|---|
| 1205 | /*****************************************************************************
|
|---|
| 1206 | **
|
|---|
| 1207 | *F getParent . . . . . . . . . . . . . . . . . . . . . . . . . . . getParent
|
|---|
| 1208 | **
|
|---|
| 1209 | ** Return Parent ID for a given categories id
|
|---|
| 1210 | **
|
|---|
| 1211 | ** @return int
|
|---|
| 1212 | **
|
|---|
| 1213 | *****************************************************************************/
|
|---|
| 1214 |
|
|---|
| 1215 | function getParent($catID) {
|
|---|
| 1216 | if (isset ($this->PARENT[$catID])) {
|
|---|
| 1217 | return $this->PARENT[$catID];
|
|---|
| 1218 | } else {
|
|---|
| 1219 | $parent_query = xtc_db_query("SELECT parent_id
|
|---|
| 1220 | FROM ".TABLE_CATEGORIES."
|
|---|
| 1221 | WHERE categories_id = '".$catID."'");
|
|---|
| 1222 |
|
|---|
| 1223 | if (xtc_db_num_rows($parent_query) > 0) {
|
|---|
| 1224 | $parent_data = xtc_db_fetch_array($parent_query);
|
|---|
| 1225 | $this->PARENT[$catID] = $parent_data['parent_id'];
|
|---|
| 1226 | return $parent_data['parent_id'];
|
|---|
| 1227 | }
|
|---|
| 1228 | }
|
|---|
| 1229 | }
|
|---|
| 1230 | }
|
|---|