Projekt

Allgemein

Profil

GX-Bug #41577 » CSVFunctionLibrary.inc.php

/system/classes/csv/ - Till Tepelmann, 09.04.2015 18:19

 
1
<?php
2
/* --------------------------------------------------------------
3
   CSVFunctionLibrary.inc.php 2015-02-19 gm
4
   Gambio GmbH
5
   http://www.gambio.de
6
   Copyright (c) 2015 Gambio GmbH
7
   Released under the GNU General Public License (Version 2)
8
   [http://www.gnu.org/licenses/gpl-2.0.html]
9
   --------------------------------------------------------------
10
*/
11

    
12
require_once(DIR_FS_CATALOG . 'admin/gm/inc/no_html.inc.php');
13
require_once(DIR_FS_INC . 'xtc_get_tax_rate.inc.php');
14

    
15
/**
16
 * Description of CSVFunctionLibrary
17
 */
18
class CSVFunctionLibrary extends BaseClass
19
{	
20
	protected $coo_currencies;
21
	protected $coo_shipping_status;
22
	protected $coo_vpe_source;
23
	protected $coo_manufacturers;
24
	protected $coo_google_export_availability;
25
	protected $coo_seo_boost = false;
26
			
27
	protected $v_language_array = array();
28
	protected $v_language_by_code_array = array();
29
	protected $v_product_ids_array = array();
30
	protected $v_image_data_array = array();
31
	protected $v_additional_field_data_array = array();
32
	protected $v_personal_offers_array = array();
33
	protected $v_product_categories_array = array();
34
	protected $v_category_parents_array = array();
35
	protected $v_category_names_array = array();
36
	protected $v_google_categories_array = array();
37
	protected $v_properties_array = array();
38
	protected $v_attributes_array = array();
39
	protected $v_additional_fields_array = array();
40
	protected $coo_xtc_price;
41
	protected $coo_scheme;
42
	protected $combi_value_names_array = array();
43
	protected $property_names_array = array();
44
	
45
	public function __construct( $p_coo_scheme, $p_properties_array = array(), $p_attributes_array = array(), $p_additional_fields_array = array() )
46
	{
47
		$this->coo_scheme = $p_coo_scheme;
48
		$this->coo_currencies = MainFactory::create_object( 'CurrenciesSource' );
49
		$this->coo_shipping_status = MainFactory::create_object( 'ProductsShippingStatusSource' );
50
		$this->coo_vpe_source = MainFactory::create_object('ProductsVPESource');
51
		$this->coo_manufacturers = MainFactory::create_object( 'ManufacturersSource' );
52
		$this->coo_google_export_availability = MainFactory::create_object( 'GoogleExportAvailabilitySource' );
53
		$this->v_properties_array = $p_properties_array;
54
		$this->v_attributes_array = $p_attributes_array;
55
		$this->v_additional_fields_array = $p_additional_fields_array;
56
		$this->_init_languages_by_code();
57
		$this->_init_property_names();
58
		
59
		if( gm_get_conf('GM_SEO_BOOST_PRODUCTS') == 'true' )
60
		{
61
			$this->coo_seo_boost = new GMSEOBoost();
62
		}
63
		
64
		$t_currency = $this->coo_currencies->get_currencies( $this->coo_scheme->v_data_array[ 'currencies_id' ] );
65
		$this->coo_xtc_price = new xtcPrice( $t_currency[ 'code' ], $this->coo_scheme->v_data_array[ 'customers_status_id' ] );
66
	}
67
	
68
	public function get_data( $p_data_array, $p_field_content, $p_default_value = '', $p_preview_content = false )
69
	{
70
		$t_field_content = $this->_get_field_content($p_data_array, $p_field_content, $p_default_value);
71
		
72
		if($p_preview_content === true)
73
		{
74
			$t_field_content = htmlentities_wrapper( $t_field_content );
75
			if(strlen_wrapper($t_field_content) > 30)
76
			{
77
				$t_field_content = '<div class="preview_content_full" style="display: none">' . $t_field_content . ' <a href="#" style="color: red" class="toogle_content_size">[weniger]</a></div></div>' . 
78
								'<div class="preview_content_sub">' . substr_wrapper($t_field_content, 0, 30) . ' <a href="#" style="color: red" class="toogle_content_size">[mehr]</a></div>';
79
			}
80
		}
81
		
82
		return $t_field_content;
83
	}
84
	
85
	protected function _get_field_content($p_data_array, $p_field_content, $p_default_field_content = '')
86
	{
87
		preg_match_all( '/{([^{]+)}/', $p_field_content, $t_matches );
88
		
89
		foreach( $t_matches[1] AS $t_variable_name_data )
90
		{
91
			$t_language_code = '';
92
			$t_index = '';
93
			$t_variable_name = $t_variable_name_data;
94
			$t_variable_key_name = $t_variable_name_data;
95
			
96
			if(strpos_wrapper(trim($t_variable_name), 'collective_field') === 0)
97
			{
98
				$t_collective_variable = explode('||', $t_variable_name);
99
				$t_collective_source_names = explode(';', $t_collective_variable[1]);
100
				$t_collective_sources = explode(';', $t_collective_variable[2]);
101
				
102
				$t_variable_name_formatted = $this->collective_field($p_data_array, $t_collective_source_names, $t_collective_sources);
103
			}
104
			else
105
			{
106
				$t_filter_name = '';
107
				if(strpos_wrapper($t_variable_name, '|') !== false)
108
				{
109
					$t_variable_array = explode('|', $t_variable_name);
110
					$t_variable_name = $t_variable_array[0];
111
					$t_variable_key_name = $t_variable_array[0];
112
					$t_filter_data_array = explode(':', $t_variable_array[1]);
113
					$t_filter_name = $t_filter_data_array[0];
114
					$filter_params_array = array();
115
					if(isset($t_filter_data_array[1]))
116
					{
117
						foreach($t_filter_data_array as $t_filter_key => $t_filter_value)
118
						{
119
							if($t_filter_key > 0)
120
							{
121
								$filter_params_array[] = $t_filter_value;
122
							}
123
						}
124
					}
125
				}
126

    
127
				if(strpos_wrapper($t_variable_name, '.') !== false)
128
				{
129
					$t_variable_array = explode('.', $t_variable_name);
130

    
131
					$t_variable_name = $t_variable_array[0];
132
					$t_language_code = $t_variable_array[1];
133
				}
134

    
135
				if(strpos_wrapper($t_variable_name, '#') !== false)
136
				{
137
					$t_variable_array = explode('#', $t_variable_name);
138
					$t_variable_name = $t_variable_array[0];
139
					$t_index = $t_variable_array[1];
140
				}
141

    
142
				if( method_exists( $this, $t_variable_name ) )
143
				{
144
					$t_language_id = empty($t_language_code) ? $this->coo_scheme->v_data_array['languages_id'] : $this->_get_language_id_by_code($t_language_code);
145
					$this->_set_language_id($t_language_id);
146
					$this->_set_language_code($t_language_code);
147

    
148
					if($t_index === '')
149
					{
150
						$t_variable_name_formatted = call_user_func( array( $this, $t_variable_name ), $p_data_array );
151
					}
152
					else
153
					{
154
						$t_variable_name_formatted = call_user_func( array( $this, $t_variable_name ), $p_data_array, $t_index );
155
					}
156

    
157
					if($t_filter_name != '' && method_exists($this, $t_filter_name))
158
					{
159
						$t_variable_name_formatted = call_user_func( array( $this, $t_filter_name ), $t_variable_name_formatted, $filter_params_array );
160
					}
161
				}
162
				else if (array_key_exists($t_variable_key_name, $p_data_array))
163
				{
164
					$t_variable_name_formatted = $p_data_array[ $t_variable_key_name ];
165

    
166
					if($t_filter_name != '' && method_exists($this, $t_filter_name))
167
					{
168
						$t_variable_name_formatted = call_user_func( array( $this, $t_filter_name ), $t_variable_name_formatted, $filter_params_array );
169
					}
170
				}
171
				else
172
				{
173
					$t_variable_name_formatted = '{' . $t_variable_name_data . '}';
174
				}
175
			}
176
			$p_field_content = str_replace( '{' . $t_variable_name_data . '}', $t_variable_name_formatted, $p_field_content );
177
			
178
			if (trim($p_field_content) == '')
179
			{
180
				$p_field_content = $this->_get_field_content( $p_data_array, $p_default_field_content );
181
			}
182
		}
183
		
184
		return $p_field_content;
185
	}
186
	
187
	protected function _init_languages_by_code()
188
	{
189
		$t_sql = '
190
				SELECT languages_id, code
191
				FROM ' . TABLE_LANGUAGES;
192
		$t_result = xtc_db_query($t_sql);
193
		
194
		while($t_row = xtc_db_fetch_array($t_result))
195
		{
196
			$this->v_language_by_code_array[$t_row['code']] = $t_row['languages_id'];
197
		}
198
	}
199
	
200
	protected function _get_additional_field_value($p_additional_field_id, $p_item_id, $p_language_id = 0)
201
	{
202
		$c_additional_field_id = (int)$p_additional_field_id;
203
		$c_item_id = (int)$p_item_id;
204
		$c_language_id = (int)$p_language_id;
205
		$t_sql = 'SELECT afvd.value '
206
				. 'FROM additional_field_values afv, additional_field_value_descriptions afvd '
207
				. 'WHERE afv.additional_field_id = "' . $c_additional_field_id . '" AND '
208
				. 'afv.item_id = "' . $c_item_id . '" AND '
209
				. 'afvd.language_id = "' . $c_language_id . '"';
210
		$t_result = xtc_db_query($t_sql);
211
		
212
		if($t_row = xtc_db_fetch_array($t_result))
213
		{
214
			return $t_row['value'];
215
		}
216
		
217
		return '';
218
	}
219
	
220
	protected function _replace_whitespaces($p_text)
221
	{
222
		$t_text = $p_text;
223

    
224
		$t_text = str_replace(chr(9), '', $t_text);
225
		$t_text = str_replace(chr(10), '', $t_text);
226
		$t_text = str_replace(chr(13), '', $t_text);
227
		
228
		return $t_text;
229
	}
230
	
231
	protected function p_id( $p_data_array )
232
	{
233
		$t_return = $p_data_array[ 'products_id' ];
234
		
235
		if( $this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0 )
236
		{
237
			// contains properties
238
			$t_return .= 'p' . $p_data_array[ 'products_properties_combis_id' ];
239
		}
240
		
241
		if( $this->coo_scheme->v_data_array[ 'export_attributes' ] == 1 && isset( $p_data_array[ 'products_attributes_id' ] ) )
242
		{
243
			// contains attributes
244
			$t_return .= 'a' . $p_data_array[ 'products_attributes_id' ];
245
		}
246
		
247
		return $t_return;
248
	}
249

    
250
	protected function p_name( $p_data_array )
251
	{
252
		$t_return = isset($p_data_array['products_name.' . $this->v_language_array['code']]) ? 
253
						$p_data_array['products_name.' . $this->v_language_array['code']] : 
254
						$p_data_array['products_name'];
255
		
256
		if($this->_use_properties($p_data_array))
257
		{
258
			// contains properties
259
			$t_properties_names_array = array();
260
			
261
			foreach($this->combi_value_names_array as $t_property_id => $t_combi_array)
262
			{
263
				$t_properties_names_array[] = $this->property_names_array[$t_property_id][$this->_get_language_id()] . ': ' . $t_combi_array[$this->_get_language_id()]['name'];
264
			}
265
			
266
			if(empty($t_properties_names_array) === false)
267
			{
268
				$t_return .= ' (';
269
				$t_return .= implode(' / ', $t_properties_names_array);
270
				$t_return .= ')';
271
			}
272
		}
273
		
274
		if( $this->coo_scheme->v_data_array[ 'export_attributes' ] == 1 && isset( $p_data_array[ 'products_attributes_id' ] ) )
275
		{
276
			// contains attributes
277
			$t_return .= ' (' . $p_data_array[ 'products_options_name' ] . ': ' . $p_data_array[ 'products_options_values_name' ] . ')';
278
		}
279
		
280
		$t_return = str_replace( "\t", ' ', $t_return );
281
		
282
		return $t_return;
283
	}
284
	
285
	protected function c_name( $p_data_array )
286
	{
287
		$t_return = '';
288
		$t_category_id = (int)$this->_get_category_id( $p_data_array );
289
		$t_category = $this->_get_category( $t_category_id );
290
		if( isset( $t_category[ 'categories_name' ] ) )
291
		{
292
			$t_return = $t_category[ 'categories_name' ];
293
		}
294
		return $t_return;
295
	}
296
	
297
	protected function c_path( $p_data_array )
298
	{
299
		$t_category_id = (int)$this->_get_category_id( $p_data_array );
300
		$t_return = $this->_build_category_path( $t_category_id );
301
		
302
		return $t_return;
303
	}
304
	
305
	protected function p_link( $p_data_array )
306
	{
307
		$t_return = '';
308
		
309
		$t_parameter_string = '';
310
		if( isset( $this->coo_scheme->v_data_array[ 'campaign_id' ] ) && !empty($this->coo_scheme->v_data_array[ 'campaign_id' ]) )
311
		{
312
			$t_parameter_string .= 'refID=' . $this->coo_scheme->v_data_array[ 'campaign_id' ] . '&';
313
		}
314
		
315
		if($this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0)
316
		{
317
			$t_parameter_string .= 'combi_id=' . $p_data_array[ 'products_properties_combis_id' ] . '&';
318
		}
319
		
320
		if( $this->coo_seo_boost == false )
321
		{
322
			$t_return = $this->_generate_link( 'product_info.php', $t_parameter_string . xtc_product_link( $p_data_array[ 'products_id' ], $p_data_array[ 'products_name' ] ) );
323
		}
324
		else
325
		{
326
			$t_return = $this->_generate_link( $this->coo_seo_boost->get_boosted_product_url( $p_data_array[ 'products_id' ], $p_data_array[ 'products_name' ] ), $t_parameter_string);			
327
		}
328
		
329
		return $t_return;
330
	}
331
	
332
	protected function _generate_link($p_page = '', $p_parameters = '')
333
	{
334
		$t_link = HTTP_SERVER . DIR_WS_CATALOG;
335
    
336
		if (xtc_not_null($p_parameters)) {
337
		  $t_link .= $p_page . '?' . $p_parameters;
338
		  $t_separator = '&';
339
		} else {
340
		  $t_link .= $p_page;
341
		  $t_separator = '?';
342
		}
343

    
344
		while ( (substr_wrapper($t_link, -1) == '&') || (substr_wrapper($t_link, -1) == '?') ) $t_link = substr_wrapper($t_link, 0, -1);
345
		
346
		return $t_link;
347
  }
348
	
349
	protected function products_description( $p_data_array )
350
	{
351
		$t_products_description = isset($p_data_array['products_description.' . $this->v_language_array['code']]) ? 
352
									$p_data_array['products_description.' . $this->v_language_array['code']] : 
353
									$p_data_array['products_description'];
354

    
355
		$t_products_description = $this->_replace_whitespaces($t_products_description);
356
		
357
		return $t_products_description;
358
	}
359

    
360
	protected function p_description( $p_data_array )
361
	{
362
		$t_return = '';
363
		$t_products_description = isset($p_data_array['products_description.' . $this->v_language_array['code']]) ? 
364
									$p_data_array['products_description.' . $this->v_language_array['code']] : 
365
									$p_data_array['products_description'];
366

    
367
		if( isset( $t_products_description ) )
368
		{
369
			$t_products_description = preg_replace('!(.*?)\[TAB:(.*?)\](.*?)!is', "$1$3", $t_products_description);
370
			$t_products_description = $this->_replace_whitespaces($t_products_description);
371
			$t_products_description = no_html($t_products_description);
372
			$t_return = $t_products_description;
373
		}
374

    
375
		return $t_return;
376
	}
377
	
378
	protected function p_short_description($p_data_array)
379
	{
380
		$t_products_short_description = isset($p_data_array['products_short_description.' . $this->v_language_array['code']]) ? 
381
											$p_data_array['products_short_description.' . $this->v_language_array['code']] : 
382
											$p_data_array['products_short_description'];
383

    
384
		$t_products_short_description = $this->_replace_whitespaces($t_products_short_description);
385
		$t_products_short_description = no_html($t_products_short_description);
386
		$t_return = $t_products_short_description;
387
		
388
		return $t_return;
389
	}
390
	
391
		
392
	protected function products_short_description( $p_data_array )
393
	{
394
		$t_return = '';
395
		
396
		$t_products_short_description = isset($p_data_array['products_short_description.' . $this->v_language_array['code']]) ? 
397
											$p_data_array['products_short_description.' . $this->v_language_array['code']] : 
398
											$p_data_array['products_short_description'];
399

    
400
		$t_return = $this->_replace_whitespaces($t_products_short_description);
401
		
402
		return $t_return;
403
	}
404
	
405
	protected function checkout_information($p_data_array)
406
	{
407
		$t_checkout_information = isset($p_data_array['checkout_information.' . $this->v_language_array['code']]) ?
408
									$p_data_array['checkout_information.' . $this->v_language_array['code']] :
409
									$p_data_array['checkout_information'];
410

    
411
		$t_checkout_information = $this->_replace_whitespaces($t_checkout_information);
412

    
413
		return $t_checkout_information;
414
	}
415
	
416
	protected function p_checkout_information($p_data_array)
417
	{
418
		$t_checkout_information = isset($p_data_array['checkout_information.' . $this->v_language_array['code']]) ?
419
									$p_data_array['checkout_information.' . $this->v_language_array['code']] :
420
									$p_data_array['checkout_information'];
421

    
422
		$t_checkout_information = $this->_replace_whitespaces($t_checkout_information);
423
		$t_checkout_information = no_html($t_checkout_information);
424

    
425
		return $t_checkout_information;
426
	}
427
	
428
	protected function p_gm_alt_text( $p_data_array, $p_index = 0 )
429
	{
430
		$t_return = '';
431
		if(empty($p_index))
432
		{
433
			$t_return = isset($p_data_array['gm_alt_text.' . $this->v_language_array['code']]) ?
434
							$p_data_array['gm_alt_text.' . $this->v_language_array['code']] :
435
							$p_data_array['gm_alt_text'];
436
		}
437
		else
438
		{
439
			$this->_build_image_data_array();
440
			if(isset($this->v_image_data_array[$p_data_array['products_id']][$p_index][$this->v_language_array['id']]['gm_alt_text']))
441
			{
442
				$t_return = $this->v_image_data_array[$p_data_array['products_id']][$p_index][$this->v_language_array['id']]['gm_alt_text'];
443
			}
444
		}
445
		
446
		return $t_return;
447
	}
448
	
449
	protected function p_additional_field($p_data_array, $p_additional_field_id)
450
	{
451
		$t_return = '';
452
		$c_additional_field_id = (int)$p_additional_field_id;
453
		
454
		$this->_build_additional_field_data_array();
455
		if(isset($this->v_additional_field_data_array[$p_data_array['products_id']][$c_additional_field_id][$this->v_language_array['id']]))
456
		{
457
			$t_return = $this->v_additional_field_data_array[$p_data_array['products_id']][$c_additional_field_id][$this->v_language_array['id']];
458
		}
459
		else if(isset($this->v_additional_field_data_array[$p_data_array['products_id']][$c_additional_field_id][0]))
460
		{
461
			$t_return = $this->v_additional_field_data_array[$p_data_array['products_id']][$c_additional_field_id][0];
462
		}
463
		
464
		return $t_return;
465
	}
466
	
467
	protected function collective_field($p_data_array, $p_source_field_names, $p_collective_sources)
468
	{
469
		$t_return = '';
470
		
471
		if(in_array('properties', $p_collective_sources))
472
		{
473
			foreach($p_source_field_names as $t_source_field_name)
474
			{
475
				if(isset($this->v_properties_array[$t_source_field_name]))
476
				{
477
					$t_return = $this->combi_value_names_array[$this->v_properties_array[$t_source_field_name]][$this->_get_language_id()]['name'];
478
					break;
479
				}
480
			}
481
		}
482
		
483
		if(empty($t_return) && in_array('attributes', $p_collective_sources))
484
		{
485
			foreach($p_source_field_names as $t_source_field_name)
486
			{
487
				if(	isset($this->v_attributes_array[$t_source_field_name]) &&
488
					isset($p_data_array['options_id']) &&
489
					empty($p_data_array['options_id']) == false &&
490
					$this->v_attributes_array[$t_source_field_name] == $p_data_array['options_id'])
491
				{
492
					$t_return = $p_data_array['products_options_values_name'];
493
					break;
494
				}
495
			}
496
		}
497
		
498
		if(empty($t_return) && in_array('additional_fields', $p_collective_sources))
499
		{
500
			foreach($p_source_field_names as $t_source_field_name)
501
			{
502
				if(isset($this->v_additional_fields_array[$t_source_field_name]))
503
				{
504
					$t_return = $p_data_array['additional_field_value_' . $this->v_additional_fields_array[$t_source_field_name]];
505
					break;
506
				}
507
			}
508
		}
509
		
510
		return $t_return;
511
	}
512
	
513
	protected function p_availability( $p_data_array )
514
	{
515
		$t_return = '0000-00-00 00:00:00';
516
		
517
		if (!empty($p_data_array['products_date_available']))
518
		{
519
			$t_return = $p_data_array['products_date_available'];
520
		}
521
		
522
		// Sprachabhaengige Konstanten erlaubt?
523
		// War im alten Export-Modul umgedreht (Ja => Nein, Nein => Ja) Nochmal klaeren!!!
524
		$t_return = $t_return >= date("Y-m-d H:i:s", time()) ? 'Nein' : 'Ja';
525
		
526
		return $t_return;
527
	}
528
	
529
	protected function products_image( $p_data_array, $p_index = 0 )
530
	{
531
		$t_return = $p_data_array[ 'products_image' ];
532
		
533
		if( isset( $p_index ) && (int)$p_index != 0 )
534
		{
535
			$this->_build_image_data_array();
536
			$t_return = '';
537
			if(isset($this->v_image_data_array[$p_data_array['products_id']][$p_index]['image_name']))
538
			{
539
				$t_return = $this->v_image_data_array[$p_data_array['products_id']][$p_index]['image_name'];
540
			}
541
		}
542
		
543
		return $t_return;
544
	}
545
	
546
	protected function p_image( $p_data_array, $p_index = 0 )
547
	{
548
		$t_return = $this->_get_image_path('popup') . $p_data_array[ 'products_image' ];
549
		
550
		if( isset( $p_index ) && (int)$p_index != 0 )
551
		{
552
			$this->_build_image_data_array();
553
			$t_return = '';
554
			if(isset($this->v_image_data_array[$p_data_array['products_id']][$p_index]['image_name']))
555
			{
556
				$t_return = $this->_get_image_path('popup') . $this->v_image_data_array[$p_data_array['products_id']][$p_index]['image_name'];
557
			}
558
		}
559
		
560
		return $t_return;
561
	}
562
	
563
	protected function p_thumb_image( $p_data_array )
564
	{
565
		$t_return = '';
566
		
567
		if( isset( $p_data_array[ 'products_image' ] ) && !empty( $p_data_array[ 'products_image' ] ) )
568
		{
569
			$t_image_dir = $this->_get_image_path('thumb');
570
			$t_return = $t_image_dir . $p_data_array[ 'products_image' ];
571
		}
572
		
573
		return $t_return;
574
	}
575
	
576
	protected function p_info_image( $p_data_array )
577
	{
578
		$t_return = '';
579
		
580
		if( isset( $p_data_array[ 'products_image' ] ) && !empty( $p_data_array[ 'products_image' ] ) )
581
		{
582
			$t_image_dir = $this->_get_image_path('info');
583
			$t_return = $t_image_dir . $p_data_array[ 'products_image' ];
584
		}
585
		
586
		return $t_return;
587
	}
588
	
589
	protected function p_popup_image( $p_data_array )
590
	{
591
		$t_return = '';
592
		
593
		if( isset( $p_data_array[ 'products_image' ] ) && !empty( $p_data_array[ 'products_image' ] ) )
594
		{
595
			$t_image_dir = $this->_get_image_path('popup');
596
			$t_return = $t_image_dir . $p_data_array[ 'products_image' ];
597
		}
598
		
599
		return $t_return;
600
	}
601
	
602
	protected function p_thumb_images( $p_data_array )
603
	{
604
		$t_image_dir = $this->_get_image_path('thumb');
605
		return $this->_get_images_for_product($t_image_dir, $p_data_array);
606
	}
607
	
608
	protected function p_info_images( $p_data_array )
609
	{
610
		$t_image_dir = $this->_get_image_path('info');
611
		return $this->_get_images_for_product($t_image_dir, $p_data_array);
612
	}
613
	
614
	protected function p_popup_images( $p_data_array )
615
	{
616
		$t_image_dir = $this->_get_image_path('popup');
617
		return $this->_get_images_for_product($t_image_dir, $p_data_array);
618
	}
619
	
620
	protected function p_price_comma( $p_data_array )
621
	{
622
		$t_return = $this->_calculate_price($p_data_array);
623
		$t_return = number_format( $t_return, 2, ',', '' );
624
		return $t_return;
625
	}
626
	
627
	protected function p_price_point( $p_data_array )
628
	{
629
		$t_return = $this->_calculate_price($p_data_array);
630
		$t_return = number_format( $t_return, 2, '.', '' );
631
		return $t_return;
632
	}
633
	
634
	protected function p_price_net_point( $p_data_array )
635
	{
636
		$t_return = $this->_calculate_price_net($p_data_array);
637
		$t_return = number_format( $t_return, 2, '.', '' );
638
		return $t_return;
639
	}
640
	
641
	protected function p_price_net_comma( $p_data_array )
642
	{
643
		$t_return = $this->_calculate_price_net($p_data_array);
644
		$t_return = number_format( $t_return, 2, ',', '' );
645
		return $t_return;
646
	}
647

    
648
	protected function p_google_special_price( $p_data_array )
649
	{
650
		$t_return = '';
651
		if( $this->coo_xtc_price->xtcCheckSpecial($p_data_array[ 'products_id' ]) )
652
		{
653
			$t_return = $this->coo_xtc_price->xtcGetPrice($p_data_array['products_id'], false, 1, $p_data_array['products_tax_class_id'], '', 0, 0, true);
654
			$t_return = number_format( $t_return, 2, ',', '' ) . " " . $this->p_currency();
655
		}
656
		return $t_return;
657
	}
658

    
659
	protected function p_google_price( $p_data_array )
660
	{
661
		$t_return = $this->_calculate_price($p_data_array, false);
662
		$t_return = number_format( $t_return, 2, ',', '' ) . " " . $this->p_currency();
663
		return $t_return;
664
	}
665
	
666
	protected function p_old_price_point( $p_data_array )
667
	{
668
		$t_return = $this->_get_old_price( $p_data_array );
669
		if( trim($t_return) != '' )
670
		{
671
			$t_return = number_format( $t_return, 2, '.', '' );
672
		}
673
		return $t_return;
674
	}
675
	
676
	protected function p_old_price_comma( $p_data_array )
677
	{
678
		$t_return = $this->_get_old_price( $p_data_array );
679
		if( trim($t_return) != '' )
680
		{
681
			$t_return = number_format( $t_return, 2, ',', '' );
682
		}
683
		return $t_return;
684
	}
685
	
686
	protected function p_old_price_point_currency( $p_data_array )
687
	{
688
		$t_return = $this->p_old_price_point( $p_data_array );
689
		if( trim($t_return) != '' )
690
		{
691
			$t_return = $this->p_currency() . " " . $t_return;
692
		}
693
		return $t_return;
694
	}
695
	
696
	protected function p_old_price_comma_currency( $p_data_array )
697
	{
698
		$t_return = $this->p_old_price_comma( $p_data_array );
699
		if( trim($t_return) != '' )
700
		{
701
			$t_return = $this->p_currency() . " " . $t_return;
702
		}
703
		return $t_return;
704
	}
705
	
706
	protected function _get_old_price( $p_data_array )
707
	{
708
		$t_return = $p_data_array['products_price'];
709
		if( $this->coo_xtc_price->xtcCheckSpecial($p_data_array[ 'products_id' ]) )
710
		{
711
			$t_return = $this->_calculate_price($p_data_array, false);
712
		}
713
		return $t_return;
714
	}
715
    
716
	protected function p_baseprice_point( $p_data_array )
717
	{
718
		$t_return = '';
719
		$t_baseprice = (double)$this->p_baseprice($p_data_array);
720
		if($t_baseprice > 0)
721
		{
722
			$t_currency = $this->coo_currencies->get_currencies($this->coo_scheme->v_data_array['currencies_id']);
723
			$t_return .= number_format($t_baseprice, 2, '.', '') . ' ' . $t_currency['code'] . ' / ' . $this->vpe_name($p_data_array);
724
		}
725
		
726
		return $t_return;
727
	}
728
	
729
	protected function p_baseprice($p_data_array)
730
	{
731
		$t_return = '';
732
		$t_vpe_value = $this->vpe_value($p_data_array);
733
		
734
		if(empty($t_vpe_value) == false)
735
		{			
736
			$t_price = $this->p_price_point($p_data_array);
737
			$t_return = $t_price / (double)$t_vpe_value;
738
		}
739
		
740
		return $t_return;
741
	}
742
	
743
	protected function p_baseprice_comma($p_data_array)
744
	{
745
		$t_return = '';
746
		$t_baseprice = (double)$this->p_baseprice($p_data_array);
747
		if($t_baseprice > 0)
748
		{
749
			$t_currency = $this->coo_currencies->get_currencies($this->coo_scheme->v_data_array['currencies_id']);
750
			$t_return = number_format($t_baseprice, 2, ',', '') . ' ' . $t_currency['code'] . ' / ' . $this->vpe_name($p_data_array);
751
		}
752
		
753
		return $t_return;
754
	}
755
	
756
	protected function _calculate_price($p_data_array, $p_include_special = true)
757
	{
758
		$t_return = 0;
759
		$t_combi_price = 0;
760
		$t_product_price = $this->coo_xtc_price->xtcGetPrice($p_data_array['products_id'], false, 1, $p_data_array['products_tax_class_id'], '', 0, 0, $p_include_special);
761
		
762
		if($this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0)
763
		{
764
			$t_combi_price = $this->coo_xtc_price->xtcGetPrice(0, false, 1, $p_data_array['products_tax_class_id'], $p_data_array['combi_price']);
765
		}
766
		
767

    
768
		if($this->coo_scheme->v_data_array['export_attributes'] == 1 && isset( $p_data_array[ 'products_attributes_id' ] ))
769
		{
770
			$t_attributes_price = $this->coo_xtc_price->xtcGetPrice(0, false, 1, $p_data_array['products_tax_class_id'], $p_data_array['options_values_price']);
771
			$t_return = $t_product_price + $t_attributes_price;
772
		}
773
		else
774
		{
775
			$t_return = $t_product_price + $t_combi_price;
776
		}
777
		
778
		return $t_return;
779
	}
780
	
781
	protected function _calculate_price_net($p_data_array)
782
	{
783
		$t_return = 0;
784
		$t_combi_price = 0;
785
		$t_product_price = $this->coo_xtc_price->xtcGetPrice($p_data_array['products_id'], false, 1, 0, '');
786
		
787
		if($this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0)
788
		{
789
			$t_combi_price = $this->coo_xtc_price->xtcGetPrice(0, false, 1, 0, $p_data_array['combi_price']);
790
		}
791
		
792
		$t_return = $t_product_price + $t_combi_price;
793
		
794
		return $t_return;
795
	}
796

    
797
	protected function become_baseprice_value($p_data_array)
798
	{
799
		$t_return = '';
800
		if(preg_match('/(\d+\s+)?(\w+)/', $this->vpe_name($p_data_array), $matches) == 1)
801
		{
802
			$t_return = 1;
803
			$t_number = trim($matches[1]);
804
			if(is_numeric($t_number))
805
			{
806
				$t_return = $t_number;
807
			}
808
		}
809
		
810
		return $t_return;
811
	}
812
	
813
	protected function become_baseprice_amount($p_data_array)
814
	{
815
		$t_return = '';
816
		$t_baseprice = (double)$this->p_baseprice($p_data_array);
817
		if( $t_baseprice > 0 )
818
		{
819
			$t_return = number_format($t_baseprice, 2, '.', '');
820
		}
821
		
822
		return $t_return;
823
	}
824
	
825
	protected function become_baseprice_unit($p_data_array)
826
	{
827
		$t_return = '';
828
		if(preg_match('/(\d+\s+)?(\w+)/', $p_data_array['products_vpe_name'], $matches) == 1)
829
		{
830
			$t_return = $matches[2];
831
		}
832
		return $t_return;
833
	}
834
    
835
    protected function p_currency()
836
    {
837
        $t_return ='';
838
        $t_currency = $this->coo_currencies->get_currencies($this->coo_scheme->v_data_array['currencies_id']);
839
        $t_return = $t_currency['code'];
840
        
841
        return $t_return;
842
    }
843
	
844
	protected function _shipping_costs( $p_data_array )
845
	{
846
		$t_shipping_costs = '';
847
		
848
		if((double)$p_data_array['nc_ultra_shipping_costs'] > 0)
849
		{
850
			$t_shipping_costs = (double)$p_data_array['nc_ultra_shipping_costs'];
851
			if(strpos_wrapper(MODULE_SHIPPING_INSTALLED, 'gambioultra') !== false)
852
			{
853
				$t_tax_rate = xtc_get_tax_rate(MODULE_SHIPPING_GAMBIOULTRA_TAX_CLASS);
854
				$t_shipping_costs = $this->coo_xtc_price->xtcAddTax($t_shipping_costs, $t_tax_rate);
855
			}
856
			else
857
			{
858
				$t_shipping_costs = $this->coo_xtc_price->xtcCalculateCurr($t_shipping_costs);
859
			}
860
		}
861
		if((double)$this->p_price_point($p_data_array) >= (double)$this->coo_scheme->v_data_array['shipping_free_minimum'])
862
		{
863
			$t_shipping_costs = 0.00;
864
		}
865
		
866
		return $t_shipping_costs;
867
	}
868
	
869
	protected function p_shipping_costs_point( $p_data_array )
870
	{
871
		$t_return = $this->_shipping_costs($p_data_array);
872
		
873
		if($t_return !== '')
874
		{
875
			$t_return = number_format((double)$t_return, 2, '.', '');
876
		}
877
		
878
		return $t_return;
879
	}
880
	
881
	protected function p_shipping_costs_comma( $p_data_array )
882
	{
883
		$t_return = $this->_shipping_costs($p_data_array);
884
		
885
		if($t_return !== '')
886
		{
887
			$t_return = number_format((double)$t_return, 2, ',', '');
888
		}
889
		
890
		return $t_return;
891
	}
892
	
893
	protected function p_weight_point( $p_data_array )
894
	{
895
		$t_return = number_format($this->_calculate_weight($p_data_array), 3, '.', '');
896
	
897
		return $t_return;
898
	}
899
	
900
	protected function p_weight_comma( $p_data_array )
901
	{
902
		$t_return = number_format($this->_calculate_weight($p_data_array), 3, ',', '');
903
		
904
		return $t_return;
905
	}
906
	
907
	protected function _calculate_weight($p_data_array)
908
	{
909
		$t_return = (double)$p_data_array['products_weight'];
910
		
911
		if($this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0)
912
		{
913
			if($p_data_array['use_properties_combis_weight'] == 0)
914
			{
915
				$t_return += (double)$p_data_array['combi_weight'];
916
			}
917
			else
918
			{
919
				$t_return = (double)$p_data_array['combi_weight'];
920
			}
921
		}
922
		
923
		return $t_return;
924
	}
925
	
926
	protected function p_special_period($p_data_array)
927
	{
928
		if( (isset($p_data_array['specials_id']) && !empty($p_data_array['specials_id']) ) &&  ( isset( $p_data_array['status']) && $p_data_array['status'] == 1) )
929
		{
930
			$t_start_timestamp = strtotime($p_data_array['specials_date_added']);
931
			
932
			if(isset($p_data_array['specials_last_modified']) && !empty($p_data_array['specials_last_modified']))
933
			{
934
				$t_start_timestamp = strtotime($p_data_array['specials_last_modified']);
935
			}
936
			
937
			$t_end_timestamp = strtotime($p_data_array['expires_date']);
938
			
939
			if(empty($p_data_array['expires_date']))
940
			{
941
				$t_end_timestamp = strtotime('+1 year', time());
942
			}
943
			
944
			$t_return = date('c', $t_start_timestamp) . '/' . date('c', $t_end_timestamp);
945
		}
946
		else
947
		{
948
			$t_return = '';
949
		}
950
		
951
		return $t_return;
952
	}
953

    
954
	/*
955
 * GOOGLE-SHOPPING FUNKTIONEN
956
 */
957
	
958
	protected function p_google_name_vpe_prefix( $p_data_array )
959
	{
960
		$t_return = '';
961
		
962
		$t_baseprice = $this->p_baseprice_comma($p_data_array);
963
		$t_name = $this->p_name($p_data_array);
964
		
965
		if($t_baseprice > 0)
966
		{
967
			$t_return = '(' . $t_baseprice . ') ';
968
		}
969
		$t_return .= $t_name;
970
		
971
		return $t_return;
972
	}
973
	
974
	protected function p_google_name_vpe_suffix( $p_data_array )
975
	{
976
		$t_return = '';
977
		
978
		$t_baseprice = $this->p_baseprice_comma($p_data_array);
979
		$t_name = $this->p_name($p_data_array);
980
		$t_return = $t_name;
981
		if($t_baseprice > 0)
982
		{
983
			$t_return .= ' (' . $t_baseprice . ')';
984
		}
985
		
986
		return $t_return;
987
	}
988
	
989
	protected function p_google_shipping_costs( $p_data_array )
990
	{
991
		$t_return = '';
992
		$t_shipping_costs = $this->p_shipping_costs_point($p_data_array);
993
		if(empty($t_shipping_costs) == false)
994
		{
995
			$t_return = ':::' . $t_shipping_costs . ' ' . $this->p_currency();
996
		}
997
		
998
		return $t_return;
999
	}
1000

    
1001
	protected function p_google_export_availability( $p_data_array )
1002
	{
1003
		$t_return = 'auf lager';
1004
		
1005
		if(isset($p_data_array['availability']))
1006
		{
1007
			$t_return = $p_data_array['availability'];
1008
		}
1009
		else
1010
		{
1011
			$t_google_export_availability = $this->coo_google_export_availability->get_google_export_availability( $p_data_array[ 'google_export_availability_id' ] );
1012
			if(!empty($t_google_export_availability[ 'availability' ]))
1013
			{
1014
				$t_return = $t_google_export_availability[ 'availability' ];
1015
			}			
1016
		}
1017
		
1018
		return $t_return;
1019
	}
1020
	
1021
	protected function p_google_export_condition( $p_data_array )
1022
	{
1023
		$t_return = 'neu';
1024
		
1025
		if( isset( $p_data_array['google_export_condition'] ) && !empty( $p_data_array['google_export_condition'] ) )
1026
		{
1027
			$t_return = $p_data_array['google_export_condition'];
1028
		}
1029
		
1030
		return $t_return;
1031
	}
1032
	
1033
	protected function p_google_category( $p_data_array )
1034
	{
1035
		if (empty($this->v_google_categories_array))
1036
		{
1037
			$t_sql = 'SELECT google_category, products_id FROM products_google_categories WHERE products_id IN (' . implode(',', $this->v_product_ids_array) . ') GROUP BY products_id';
1038
			$t_result = xtc_db_query($t_sql);
1039
			while ($t_row = xtc_db_fetch_array($t_result))
1040
			{
1041
				$this->v_google_categories_array[$t_row['products_id']] = $t_row['google_category'];
1042
			}
1043
		}
1044
		
1045
		return $this->v_google_categories_array[$p_data_array['products_id']];
1046
	}
1047
	
1048
//	EAN (in Europa), ISBN (fuer Buecher), UPC (in Nordamerika), JAN (in Japan)
1049
	protected function p_google_export_gtin( $p_data_array )
1050
	{
1051
		// init with EAN
1052
		$t_return = $this->p_ean($p_data_array);
1053
		
1054
		if(empty($t_return) && empty($p_data_array['code_isbn']) == false)
1055
		{
1056
			$t_return = trim($p_data_array['code_isbn']);
1057
		}
1058
		elseif(empty($t_return) && !empty($p_data_array['code_upc']))
1059
		{
1060
			$t_return = trim($p_data_array['code_upc']);
1061
		}
1062
		elseif(empty($t_return) && !empty($p_data_array['code_jan']))
1063
		{
1064
			$t_return = trim($p_data_array['code_jan']);
1065
		}
1066
		
1067
		return $t_return;
1068
	}
1069
	
1070
	protected function p_google_identifier_exists($p_data_array)
1071
	{
1072
		$t_return = 'FALSE';
1073
		$t_google_gtin = $this->p_google_export_gtin($p_data_array);
1074
		
1075
		if(empty($p_data_array['identifier_exists']) == false && 
1076
			empty($t_google_gtin) == false)
1077
		{
1078
			$t_return = 'TRUE';
1079
		}
1080
		
1081
		return $t_return;
1082
	}
1083
	
1084
	protected function p_google_fsk18($p_data_array)
1085
	{
1086
		$t_return = 'FALSE';
1087
		
1088
		if($p_data_array['products_fsk18'] == 1)
1089
		{
1090
			$t_return = 'TRUE';
1091
		}
1092
		
1093
		return $t_return;
1094
	}
1095
	
1096
	protected function p_google_unit_price_measure($p_data_array)
1097
	{
1098
		$t_google_unit_price_measure = '';
1099
		$t_allowed_units_array = array('mg', 'g', 'kg', 'ml', 'cl', 'l', 'cm', 'm', 'm2', 'cbm');
1100
		$t_allowed_unit_values_array = array(1, 10, 100, 75, 50, 1000);
1101
		
1102
		$t_vpe_name = $this->vpe_name($p_data_array);
1103
		$t_vpe_value = $this->vpe_value($p_data_array);
1104
		
1105
		if($t_vpe_name != '' && empty($t_vpe_value) === false)
1106
		{
1107
			$t_vpe_name = trim($t_vpe_name);
1108
			preg_match('/([0-9]*)(.+)/', $t_vpe_name, $t_matches_array);
1109
			
1110
			$t_unit_value = (double)$t_matches_array[1];
1111
			if(empty($t_unit_value))
1112
			{
1113
				$t_unit_value = 1;
1114
			}
1115
			$t_unit_name = trim($t_matches_array[2]);
1116
			
1117
			$p_products_array['unit_pricing_base_measure'] = '';
1118
			$p_products_array['unit_price_measure'] = '';
1119
			
1120
			if(in_array($t_unit_name, $t_allowed_units_array) && in_array($t_unit_value, $t_allowed_unit_values_array))
1121
			{
1122
				$t_continue = true;
1123
				
1124
				switch($t_unit_value)
1125
				{
1126
					case 50:
1127
					case 1000:
1128
						if($t_unit_name != 'kg')
1129
						{
1130
							$t_continue = false;
1131
						}
1132
						break;
1133
					case 75:
1134
						if($t_unit_name != 'cl')
1135
						{
1136
							$t_continue = false;
1137
						}
1138
				}			
1139
				
1140
				if($t_continue === true)
1141
				{
1142
					$t_unit_price_measure_value = (string)((double)$t_vpe_value * $t_unit_value);
1143
					$t_google_unit_price_measure = $t_unit_price_measure_value . ' ' . $t_unit_name;
1144
				}
1145
			}		
1146
		}
1147
		
1148
		return $t_google_unit_price_measure;
1149
	}
1150
	
1151
	protected function p_google_unit_pricing_base_measure($p_data_array)
1152
	{
1153
		$t_google_unit_pricing_base_measure = '';
1154
		$t_allowed_units_array = array('mg', 'g', 'kg', 'ml', 'cl', 'l', 'cm', 'm', 'm2', 'cbm');
1155
		$t_allowed_unit_values_array = array(1, 10, 100, 75, 50, 1000);
1156
		
1157
		$t_vpe_name = $this->vpe_name($p_data_array);
1158
		
1159
		if($t_vpe_name != '')
1160
		{
1161
			$t_vpe_name = trim($t_vpe_name);
1162
			preg_match('/([0-9]*)(.+)/', $t_vpe_name, $t_matches_array);
1163
			
1164
			$t_unit_value = (double)$t_matches_array[1];
1165
			if(empty($t_unit_value))
1166
			{
1167
				$t_unit_value = 1;
1168
			}
1169
			$t_unit_name = trim($t_matches_array[2]);
1170
			
1171
			$p_products_array['unit_pricing_base_measure'] = '';
1172
			$p_products_array['unit_price_measure'] = '';
1173
			
1174
			if(in_array($t_unit_name, $t_allowed_units_array) && in_array($t_unit_value, $t_allowed_unit_values_array))
1175
			{
1176
				$t_continue = true;
1177
				
1178
				switch($t_unit_value)
1179
				{
1180
					case 50:
1181
					case 1000:
1182
						if($t_unit_name != 'kg')
1183
						{
1184
							$t_continue = false;
1185
						}
1186
						break;
1187
					case 75:
1188
						if($t_unit_name != 'cl')
1189
						{
1190
							$t_continue = false;
1191
						}
1192
				}			
1193
				
1194
				if($t_continue === true)
1195
				{
1196
					$t_google_unit_pricing_base_measure = $t_unit_value . ' ' . $t_unit_name;
1197
				}
1198
			}		
1199
		}
1200
		
1201
		return $t_google_unit_pricing_base_measure;
1202
	}
1203
	
1204
	protected function p_google_product_group($p_data_array)
1205
	{
1206
		$t_google_product_group = $p_data_array['products_id'];
1207
		
1208
		if(isset($p_data_array['products_attributes_id']) && empty($p_data_array['products_attributes_id']) === false)
1209
		{
1210
			$t_source_names_array = array();
1211
			
1212
			foreach($this->coo_scheme->v_fields_array AS $coo_field)
1213
			{
1214
				$t_field_content = preg_replace('/\{(collective_field\|\|.*?)\}/', '$1', $coo_field->v_data_array['field_content'], 1);
1215

    
1216
				if(strpos_wrapper($t_field_content, 'collective_field') === 0)
1217
				{
1218
					$t_collective_variable = explode('||', $t_field_content);
1219
					$t_collective_source_names = explode(';', $t_collective_variable[1]);
1220
					$t_collective_sources = explode(';', $t_collective_variable[2]);
1221

    
1222
					if(in_array('attributes', $t_collective_sources))
1223
					{
1224
						$t_source_names_array = array_merge($t_source_names_array, $t_collective_source_names);
1225
					}
1226
				}
1227
			}
1228
			
1229
			if(in_array($p_data_array['products_options_name'], $t_source_names_array) === false)
1230
			{
1231
				$t_google_product_group .= 'A' . $p_data_array['products_attributes_id'];
1232
			}
1233
		}
1234
		
1235
		if(isset($p_data_array['products_properties_combis_id']) && empty($p_data_array['products_properties_combis_id']) === false)
1236
		{
1237
			$t_source_names_array = array();
1238
			
1239
			foreach($this->coo_scheme->v_fields_array AS $coo_field)
1240
			{
1241
				$t_field_content = preg_replace('/\{(collective_field\|\|.*?)\}/', '$1', $coo_field->v_data_array['field_content'], 1);
1242

    
1243
				if(strpos_wrapper($t_field_content, 'collective_field') === 0)
1244
				{
1245
					$t_collective_variable = explode('||', $t_field_content);
1246
					$t_collective_source_names = explode(';', $t_collective_variable[1]);
1247
					$t_collective_sources = explode(';', $t_collective_variable[2]);
1248

    
1249
					if(in_array('properties', $t_collective_sources))
1250
					{
1251
						$t_source_names_array = array_merge($t_source_names_array, $t_collective_source_names);
1252
					}
1253
				}
1254
			}
1255
			
1256
			foreach($this->v_properties_array as $t_property_name => $t_property_id)
1257
			{
1258
				if(in_array($t_property_name, $t_source_names_array) !== false)
1259
				{
1260
					$t_google_product_group .= 'P' . $t_property_id . 'P' . $this->combi_value_names_array[$t_property_id][$this->_get_language_id()]['id'];
1261
				}
1262
			}
1263
		}
1264
		
1265
		return $t_google_product_group;
1266
	}
1267
	
1268
/*
1269
 * DAPARTO FUNKTIONEN
1270
 */
1271
	protected function p_daparto_shippingtime( $p_data_array )
1272
	{
1273
		if($p_data_array['products_shippingdays'] <= 2)
1274
		{
1275
			$t_return = 1;
1276
		}
1277
		else if($p_data_array['products_shippingdays'] <= 5)
1278
		{
1279
			$t_return = 2;
1280
		}
1281
		else
1282
		{ // shippingdays > 5
1283
			$t_return = 3;
1284
		}
1285
		
1286
		return $t_return;
1287
	}
1288
	
1289
	protected function _get_image_path( $p_image_type )
1290
	{
1291
		$t_image_dir = HTTP_SERVER;
1292
		
1293
		if(defined("DIR_WS_CATALOG_ORIGINAL_IMAGES"))
1294
		{
1295
			switch ($p_image_type)
1296
			{
1297
				case "thumb":
1298
					$t_image_dir .= DIR_WS_CATALOG_THUMBNAIL_IMAGES;
1299
					break;
1300
				
1301
				case "popup":
1302
					$t_image_dir .= DIR_WS_CATALOG_POPUP_IMAGES;
1303
					break;
1304
				
1305
				case "info":
1306
					$t_image_dir .= DIR_WS_CATALOG_INFO_IMAGES;
1307
					break;
1308

    
1309
				default:
1310
					break;
1311
			}
1312
		}
1313
		
1314
		else
1315
		{
1316
			$t_image_dir .= DIR_WS_CATALOG;
1317
			
1318
			switch ($p_image_type)
1319
			{
1320
				case "thumb":
1321
					$t_image_dir .= DIR_WS_THUMBNAIL_IMAGES;
1322
					break;
1323
				
1324
				case "popup":
1325
					$t_image_dir .= DIR_WS_POPUP_IMAGES;
1326
					break;
1327
				
1328
				case "info":
1329
					$t_image_dir .= DIR_WS_INFO_IMAGES;
1330
					break;
1331

    
1332
				default:
1333
					break;
1334
			}
1335
		}
1336
		
1337
		return $t_image_dir;
1338
	}
1339
		
1340
	
1341
	protected function _get_images_for_product($p_image_dir, $p_data_array)
1342
	{
1343
		$t_return = '';
1344
		if( isset( $p_data_array[ 'products_image' ] ) && !empty( $p_data_array[ 'products_image' ] ) )
1345
		{
1346
			$t_return .= $p_image_dir . $p_data_array['products_image'] . ', ';
1347
		}
1348
		
1349
		$this->_build_image_data_array();
1350
		
1351
		if(isset($this->v_image_data_array[$p_data_array['products_id']]))
1352
		{
1353
			foreach($this->v_image_data_array[$p_data_array['products_id']] AS $t_image_array)
1354
			{
1355
				if(!empty($t_image_array['image_name']))
1356
				{
1357
					$t_return .= $p_image_dir . $t_image_array['image_name'] . ', ';
1358
				}
1359
			}
1360
		}
1361
		
1362
		if(!empty($t_return))
1363
		{
1364
			$t_return = substr_wrapper($t_return, 0, (strlen_wrapper($t_return) - 2 ));
1365
		}
1366
		
1367
		
1368
		return $t_return;
1369
	}
1370
	
1371
	
1372
	protected function _get_language_id_by_code($p_language_code)
1373
	{
1374
		return $this->v_language_by_code_array[$p_language_code];
1375
	}
1376
	
1377
	
1378
	protected function _set_language_code($p_language_code)
1379
	{
1380
		$this->v_language_array['code'] = (string)$p_language_code;
1381
	}
1382
	
1383
	
1384
	protected function _get_language_code()
1385
	{
1386
		$t_language_code = false;
1387
		
1388
		if(isset($this->v_language_array['code']))
1389
		{
1390
			$t_language_code = $this->v_language_array['code'];
1391
		}
1392
		
1393
		return $t_language_code;
1394
	}
1395
	
1396
	
1397
	protected function _set_language_id($p_language_id)
1398
	{
1399
		$this->v_language_array['id'] = (int)$p_language_id;
1400
	}
1401
	
1402
	
1403
	protected function _get_language_id()
1404
	{
1405
		$t_language_id = false;
1406
		
1407
		if(isset($this->v_language_array['id']))
1408
		{
1409
			$t_language_id = $this->v_language_array['id'];
1410
		}
1411
		
1412
		return $t_language_id;
1413
	}
1414
	
1415
	
1416
	protected function _get_category_id( $p_data_array )
1417
	{
1418
		if (array_key_exists($p_data_array['products_id'], $this->v_product_categories_array))
1419
		{
1420
			return $this->v_product_categories_array[$p_data_array['products_id']];
1421
		}
1422
		
1423
		$t_category_id = 0;
1424
		$t_sql = '
1425
			SELECT categories_id
1426
			FROM ' . TABLE_PRODUCTS_TO_CATEGORIES . '
1427
			WHERE products_id = "' . $p_data_array['products_id'] . '"
1428
			AND categories_id != "0"';
1429
		$t_result = xtc_db_query( $t_sql );
1430
		while( $t_row = xtc_db_fetch_array( $t_result ) )
1431
		{
1432
			$t_category_id = $t_row['categories_id'];
1433
		}
1434
		$this->v_product_categories_array[$p_data_array['products_id']] = $t_category_id;
1435
		
1436
		return $t_category_id;
1437
	}
1438
	
1439
	protected function _build_category_path( $p_category )
1440
	{
1441
		$t_categories_names_array = array();
1442
		$t_parent_categories_array = array();
1443
		$t_actual_category_id = $p_category;
1444
		
1445
		while( $t_actual_category_id != 0 && !in_array($t_actual_category_id, $t_parent_categories_array) )
1446
		{
1447
			$t_parent_categories_array[] = $t_actual_category_id;
1448
			$t_category = $this->_get_category( $t_actual_category_id );
1449
			if( $this->coo_scheme->v_data_array['type_id'] == 1 )
1450
			{
1451
				$t_category[ 'categories_name' ] .= '[' . $t_actual_category_id . ']';
1452
			}
1453
			$t_categories_names_array[] = $t_category[ 'categories_name' ];
1454
			$t_actual_category_id = $t_category[ 'parent_id' ];
1455
		}
1456
		
1457
		$t_categories_names_array = array_reverse($t_categories_names_array);
1458
		
1459
		if (trim(implode('', $t_categories_names_array)) == '[]')
1460
		{
1461
			$t_categories_names_array = array();
1462
		}
1463
			
1464
		return implode(' > ', $t_categories_names_array);
1465
	}
1466
	
1467
	protected function _get_category( $p_category_id )
1468
	{
1469
		$t_return = false;
1470
		$c_category_id = (int)$p_category_id;
1471
		
1472
		if( $c_category_id > 0 )
1473
		{
1474
			if (array_key_exists($c_category_id, $this->v_category_parents_array) && array_key_exists($c_category_id, $this->v_category_names_array) && array_key_exists($this->_get_language_id(), $this->v_category_names_array[$c_category_id]))
1475
			{
1476
				$t_return = array();
1477
				$t_return['categories_name'] = $this->v_category_names_array[$c_category_id][$this->_get_language_id()];
1478
				$t_return['parent_id'] = $this->v_category_parents_array[$c_category_id];
1479
			}
1480
			else
1481
			{
1482
				$t_sql = '
1483
					SELECT categories_name, parent_id
1484
					FROM ' . TABLE_CATEGORIES . ' AS c
1485
					LEFT JOIN ' . TABLE_CATEGORIES_DESCRIPTION . ' AS cd ON c.categories_id = cd.categories_id
1486
					WHERE c.categories_id = "' . $c_category_id . '" 
1487
					AND language_id="' . $this->_get_language_id() . '"';
1488
				$t_result = xtc_db_query( $t_sql );
1489
				$t_return = xtc_db_fetch_array($t_result);
1490
				if (!array_key_exists($c_category_id, $this->v_category_names_array))
1491
				{
1492
					$this->v_category_names_array[$c_category_id] = array();
1493
				}
1494
				$this->v_category_names_array[$c_category_id][$this->_get_language_id()] = $t_return['categories_name'];
1495
				$this->v_category_parents_array[$c_category_id] = $t_return['parent_id'];
1496
			}
1497
		}
1498
		
1499
		return $t_return;
1500
	}
1501
	
1502
	protected function p_manufacturer_name( $p_data_array )
1503
	{
1504
		$c_manufacturer_id = (int)$p_data_array['manufacturers_id'];
1505
		$t_manufacturer_name = '';
1506
		if(!empty($c_manufacturer_id))
1507
		{
1508
			$t_manufacturer = $this->coo_manufacturers->get_manufacturer( $p_data_array['manufacturers_id'] );
1509
			if(!empty($t_manufacturer))
1510
			{
1511
				$t_manufacturer_name = $t_manufacturer[ 'manufacturers_name' ];
1512
			}
1513
		}
1514
		return $t_manufacturer_name;
1515
	}
1516
	
1517
	protected function p_model( $p_data_array )
1518
	{
1519
		$t_return = trim($p_data_array[ 'products_model' ]);
1520
		
1521
		if( $this->coo_scheme->v_data_array['export_properties'] == 1 && isset( $p_data_array[ 'products_properties_combis_id' ] ) && $p_data_array[ 'products_properties_combis_id' ] > 0 )
1522
		{
1523
			// contains properties
1524
			if( APPEND_PROPERTIES_MODEL == 'true' && $t_return != '' && $p_data_array[ 'combi_model' ] != '' )
1525
			{
1526
				$t_return .= '-';
1527
			}
1528
			else if( APPEND_PROPERTIES_MODEL == 'false' )
1529
			{
1530
				$t_return = '';
1531
			}
1532
			$t_return .= $p_data_array[ 'combi_model' ];
1533
		}
1534
		
1535
		if( $this->coo_scheme->v_data_array['export_attributes'] == 1 && isset( $p_data_array['products_attributes_id'] ) )
1536
		{
1537
			// contains attributes
1538
			if( $t_return != '' && $p_data_array[ 'attributes_model' ] != '' )
1539
			{
1540
				$t_return .= '-';
1541
			}
1542
			$t_return .= $p_data_array[ 'attributes_model' ];
1543
		}
1544
		
1545
		return $t_return;
1546
	}
1547
	
1548
	protected function p_ean($p_data_array)
1549
	{
1550
		$t_return = trim($p_data_array['products_ean']);
1551
		if($this->_use_properties($p_data_array) && trim($p_data_array['combi_ean']) != '')
1552
		{
1553
			$t_return = $p_data_array['combi_ean'];
1554
		}
1555
		
1556
		return $t_return;
1557
	}
1558
	
1559
	protected function p_expiration_date($p_data_array)
1560
	{
1561
		$t_return = $p_data_array['expiration_date'];
1562
		$t_return = str_replace('0000-00-00', '', $t_return);
1563
		
1564
		return $t_return;
1565
	}
1566
	
1567
	protected function p_quantity( $p_data_array )
1568
	{
1569
		$t_return = $p_data_array[ 'products_quantity' ];
1570
		
1571
		if($this->_use_properties($p_data_array) 
1572
				&& (($p_data_array['use_properties_combis_quantity'] == 0 && STOCK_CHECK == 'true' && ATTRIBUTE_STOCK_CHECK == 'true') 
1573
				|| $p_data_array['use_properties_combis_quantity'] == 2))
1574
		{
1575
			$t_return = $p_data_array['combi_quantity'];
1576
		}
1577
		
1578
		return $t_return;
1579
	}
1580
	
1581
	protected function p_quantity_floor( $p_data_array )
1582
	{
1583
		$t_return = $this->p_quantity($p_data_array);
1584
		
1585
		if ($t_return < 0)
1586
		{
1587
			$t_return = 0;
1588
		}
1589
		else
1590
		{
1591
			$t_return = floor($t_return);
1592
		}
1593
		
1594
		return $t_return;
1595
	}
1596
	
1597
	protected function p_shipping_status_name( $p_data_array)
1598
	{
1599
		$t_return = '';
1600
		if(isset($p_data_array['shipping_status_name.' . $this->v_language_array['code']]))
1601
		{
1602
			$t_return = $p_data_array['shipping_status_name.' . $this->v_language_array['code']];
1603
		}
1604
		else
1605
		{
1606
			$t_return = $p_data_array['shipping_status_name'];
1607
			if($this->_use_properties($p_data_array) && $p_data_array['use_properties_combis_shipping_time'] == 1)
1608
			{
1609
				$t_return = $this->coo_shipping_status->get_shipping_status_name($p_data_array['combi_shipping_status_id'], $this->coo_scheme->v_data_array['languages_id']);
1610
			}
1611
		}
1612
		
1613
		return $t_return;
1614
	}
1615
	
1616
	protected function vpe_name( $p_data_array )
1617
	{
1618
		$t_vpe_name = '';
1619
		
1620
		// eigenschaften
1621
		if($this->coo_scheme->v_data_array['export_properties'] == 1 
1622
				&& isset($p_data_array[ 'products_properties_combis_id' ]) 
1623
				&& $p_data_array[ 'products_properties_combis_id' ] > 0
1624
				&& $p_data_array['combi_vpe_value'] != 0 
1625
				&& $p_data_array['combi_vpe_id'] != 0)
1626
		{
1627
			$t_vpe_name = $this->coo_vpe_source->get_products_vpe_name($p_data_array['combi_vpe_id'], $this->coo_scheme->v_data_array['languages_id']);
1628
		}
1629
		// attribute
1630
		elseif($this->coo_scheme->v_data_array['export_attributes'] == 1 
1631
				&& (int)$p_data_array['products_attributes_id'] > 0 
1632
				&& (int)$p_data_array['products_vpe_id'] > 0 
1633
				&& (double)$p_data_array['gm_vpe_value'] > 0)
1634
		{
1635
			$t_vpe_name = $this->coo_vpe_source->get_products_vpe_name($p_data_array['products_vpe_id'], $this->coo_scheme->v_data_array['languages_id']);
1636
		}
1637
		elseif($p_data_array['products_vpe_value'] != 0 && $p_data_array['products_vpe'] != 0)
1638
		{
1639
			$t_vpe_name = $this->coo_vpe_source->get_products_vpe_name($p_data_array['products_vpe'], $this->coo_scheme->v_data_array['languages_id']);
1640
		}
1641
		
1642
		return $t_vpe_name;
1643
	}
1644
	
1645
	protected function vpe_value($p_data_array)
1646
	{
1647
		$t_return = '';
1648
		
1649
		// eigenschaften
1650
		if($this->coo_scheme->v_data_array['export_properties'] == 1 
1651
				&& isset($p_data_array[ 'products_properties_combis_id' ]) 
1652
				&& $p_data_array[ 'products_properties_combis_id' ] > 0
1653
				&& $p_data_array['combi_vpe_value'] != 0 
1654
				&& $p_data_array['combi_vpe_id'] != 0)
1655
		{
1656
			$t_return = $p_data_array['combi_vpe_value'];
1657
		}
1658
		// attribute
1659
		elseif($this->coo_scheme->v_data_array['export_attributes'] == 1 
1660
				&& (int)$p_data_array['products_attributes_id'] > 0 
1661
				&& (int)$p_data_array['products_vpe_id'] > 0 
1662
				&& (double)$p_data_array['gm_vpe_value'] > 0)
1663
		{
1664
			$t_return = $p_data_array['gm_vpe_value'];
1665
		}
1666
		elseif($p_data_array['products_vpe_value'] != 0 && $p_data_array['products_vpe'] != 0)
1667
		{
1668
			$t_return = $p_data_array['products_vpe_value'];
1669
		}
1670
		
1671
		return $t_return;
1672
	}
1673

    
1674

    
1675
	protected function p_personal_offer($p_data_array, $p_customer_status_id)
1676
	{
1677
		$t_personal_offers = '';
1678
		$c_customer_status_id = (int)$p_customer_status_id;
1679
		$this->_build_personal_offers_array($p_customer_status_id);
1680
		
1681
		if(isset($this->v_personal_offers_array[$c_customer_status_id][(int)$p_data_array['products_id']]['string']))
1682
		{
1683
			$t_personal_offers = implode('::', $this->v_personal_offers_array[$c_customer_status_id][(int)$p_data_array['products_id']]['string']);
1684
		}
1685
		
1686
		return $t_personal_offers;
1687
	}
1688
	
1689
	protected function p_group_permission($p_data_array, $p_customer_status_id)
1690
	{
1691
		return isset($p_data_array['group_permission_' . $p_customer_status_id]) ? $p_data_array['group_permission_' . $p_customer_status_id] : '';
1692
	}
1693
	
1694
	protected function p_tax($p_data_array)
1695
	{
1696
		return xtc_get_tax_rate($p_data_array['products_tax_class_id']);
1697
	}
1698
	
1699
	protected function p_attribute($p_data_array)
1700
	{
1701
		$t_return = '';
1702
		
1703
		if( $this->coo_scheme->v_data_array[ 'export_attributes' ] == 1 && isset( $p_data_array[ 'products_attributes_id' ] ) )
1704
		{
1705
			$t_return .= $p_data_array[ 'products_options_name' ] . ': ' . $p_data_array[ 'products_options_values_name' ];
1706
		}
1707
		
1708
		return $t_return;
1709
	}
1710
	
1711
	public function set_product_ids_array(&$p_product_ids_array)
1712
	{
1713
		$this->v_product_ids_array = $p_product_ids_array;
1714
	}
1715
	
1716
	protected function _build_image_data_array()
1717
	{
1718
		if(empty($this->v_image_data_array))
1719
		{
1720
			$t_sql = "SELECT 
1721
							i.products_id,
1722
							a.language_id,
1723
							a.gm_alt_text,
1724
							i.image_nr,
1725
							i.image_name						
1726
						FROM 
1727
							" . TABLE_PRODUCTS_IMAGES. " i
1728
						LEFT JOIN gm_prd_img_alt AS a ON (a.image_id = i.image_id AND a.products_id IN (" . implode(',', $this->v_product_ids_array) . ") AND a.products_id = i.products_id)
1729
						WHERE 
1730
							i.products_id IN (" . implode(',', $this->v_product_ids_array) . ")";
1731
			$t_result = xtc_db_query($t_sql);
1732
			while($t_result_array = xtc_db_fetch_array($t_result))
1733
			{
1734
				$this->v_image_data_array[$t_result_array['products_id']][$t_result_array['image_nr']][$t_result_array['language_id']]['gm_alt_text'] = $t_result_array['gm_alt_text'];
1735
				$this->v_image_data_array[$t_result_array['products_id']][$t_result_array['image_nr']]['image_name'] = $t_result_array['image_name'];
1736
			}
1737
		}			
1738
	}
1739
	
1740
	protected function _build_additional_field_data_array()
1741
	{
1742
		if(empty($this->v_additional_field_data_array))
1743
		{
1744
			$t_sql = "SELECT
1745
							af.additional_field_id,
1746
							afv.item_id,
1747
							afvd.language_id,
1748
							afvd.value
1749
						FROM 
1750
							additional_fields af
1751
						LEFT JOIN
1752
							additional_field_values afv ON (afv.additional_field_id = af.additional_field_id)
1753
						LEFT JOIN
1754
							additional_field_value_descriptions afvd ON (afv.additional_field_value_id = afvd.additional_field_value_id)
1755
						WHERE
1756
							af.item_type = 'product' AND
1757
							afv.item_id IN (" . implode(',', $this->v_product_ids_array) . ")";
1758
			$t_result = xtc_db_query($t_sql);
1759
			while($t_result_array = xtc_db_fetch_array($t_result))
1760
			{
1761
				$this->v_additional_field_data_array[$t_result_array['item_id']][$t_result_array['additional_field_id']][$t_result_array['language_id']] = $t_result_array['value'];
1762
			}
1763
		}			
1764
	}
1765
	
1766
	protected function _build_personal_offers_array($p_customer_status_id)
1767
	{
1768
		$c_customer_status_id = (int)$p_customer_status_id;
1769
		
1770
		if(!isset($this->v_personal_offers_array[$c_customer_status_id]))
1771
		{
1772
			$t_sql = "SELECT 
1773
							products_id,
1774
							quantity, 
1775
							personal_offer 
1776
						FROM " . TABLE_PERSONAL_OFFERS_BY . $c_customer_status_id . " 
1777
						WHERE 
1778
							products_id IN (" . implode(',', $this->v_product_ids_array) . ") AND
1779
							personal_offer > 0
1780
						ORDER BY quantity";
1781
			$t_result = xtc_db_query($t_sql);
1782
			while($t_result_array = xtc_db_fetch_array($t_result))
1783
			{
1784
				$this->v_personal_offers_array[$c_customer_status_id][$t_result_array['products_id']]['price'][(double)$t_result_array['quantity']] = (double)$t_result_array['personal_offer'];
1785
				$this->v_personal_offers_array[$c_customer_status_id][$t_result_array['products_id']]['string'][(double)$t_result_array['quantity']] = (double)$t_result_array['quantity'] . ':' . (double)$t_result_array['personal_offer'];
1786
			}
1787
		}		
1788
	}
1789
	
1790
	protected function _use_properties($p_data_array)
1791
	{
1792
		if($this->coo_scheme->v_data_array['export_properties'] == 1 
1793
				&& isset( $p_data_array['products_properties_combis_id'] ) 
1794
				&& (int)$p_data_array['products_properties_combis_id'] > 0)
1795
		{
1796
			return true;
1797
		}
1798
		
1799
		return false;
1800
	}
1801
	
1802
	protected function _use_attributes($p_data_array)
1803
	{
1804
		if($this->coo_scheme->v_data_array['export_attributes'] == 1 
1805
				&& isset($p_data_array['products_attributes_id']) 
1806
				&& (int)$p_data_array['products_attributes_id'] > 0)
1807
		{
1808
			return true;
1809
		}
1810
		
1811
		return false;
1812
	}
1813
	
1814
	public function _get_combi_value_names($p_combi_id)
1815
	{
1816
		$c_combi_id = (int)$p_combi_id;
1817
		
1818
		if($c_combi_id === 0)
1819
		{
1820
			$this->combi_value_names_array = array();
1821
			return;
1822
		}
1823
		
1824
		$this->combi_value_names_array = array();
1825
		
1826
		$t_sql = "SELECT 
1827
						properties_id,
1828
						properties_values_id,
1829
						values_name,
1830
						language_id
1831
					FROM products_properties_index
1832
					WHERE 
1833
						products_properties_combis_id = '" . $c_combi_id . "'";
1834
		$t_result = xtc_db_query($t_sql);
1835
		while($t_result_array = xtc_db_fetch_array($t_result))
1836
		{
1837
			$this->combi_value_names_array[$t_result_array['properties_id']][$t_result_array['language_id']] = array();		
1838
			$this->combi_value_names_array[$t_result_array['properties_id']][$t_result_array['language_id']]['id'] = $t_result_array['properties_values_id'];		
1839
			$this->combi_value_names_array[$t_result_array['properties_id']][$t_result_array['language_id']]['name'] = $t_result_array['values_name'];		
1840
		}
1841
	}
1842
	
1843
	protected function property($p_data_array, $p_property_id)
1844
	{
1845
		$t_property = '';
1846
		
1847
		if(array_key_exists($p_property_id, $this->combi_value_names_array))
1848
		{
1849
			$t_property = $this->combi_value_names_array[$p_property_id][$this->_get_language_id()]['name'];
1850
		}
1851
		
1852
		return $t_property;
1853
	}
1854
	
1855
	protected function _init_property_names()
1856
	{
1857
		$t_sql = 'SELECT 
1858
						properties_id,
1859
						language_id,
1860
						properties_name
1861
					FROM properties_description';
1862
		$t_result = xtc_db_query($t_sql);
1863
		
1864
		while($t_result_array = xtc_db_fetch_array($t_result))
1865
		{
1866
			$this->property_names_array[$t_result_array['properties_id']][$t_result_array['language_id']] = $t_result_array['properties_name'];
1867
		}		
1868
	}
1869

    
1870

    
1871
	protected function truncate($p_string, array $p_params_array)
1872
	{
1873
		if(empty($p_params_array))
1874
		{
1875
			return $p_string;
1876
		}
1877
		
1878
		$t_truncated_string = $p_string;
1879
		
1880
		if($p_params_array[0] > 0 && strlen_wrapper($p_string) > $p_params_array[0])
1881
		{
1882
			$etc = isset($p_params_array[1]) ? $p_params_array[1] : '';
1883
			
1884
			if(strlen($etc) >= 2 && substr($etc, 0, 1) == '"' && substr($etc, -1) == '"')
1885
			{
1886
				$etc = substr($etc, 1, -1);
1887
			}
1888
			
1889
			$length = (int)$p_params_array[0];
1890
			$length -= min($p_params_array[0], strlen_wrapper($etc));
1891
			$t_truncated_string = preg_replace('/\s+?(\S+)?$/', '', substr_wrapper($t_truncated_string, 0, $length+1));
1892
			
1893
			return substr_wrapper($t_truncated_string, 0, $length) . $etc;
1894
		}
1895
		
1896
		return $t_truncated_string;
1897
	}
1898
}
    (1-1/1)