Projekt

Allgemein

Profil

GX-Bug #22509 » google_shopping.php

Till Tepelmann, 14.02.2014 12:51

 
1
<?php
2
/* --------------------------------------------------------------
3
   google_shopping.php 2013-07-31 gm
4
   Gambio GmbH
5
   http://www.gambio.de
6
   Copyright (c) 2013 Gambio GmbH
7
   Released under the GNU General Public License
8
   --------------------------------------------------------------
9
*/
10

    
11
require_once(DIR_FS_CATALOG . 'inc/xtc_get_countries.inc.php');
12

    
13
class Google_Shopping
14
{
15
	var $v_partnerlink;
16
	var $v_export_type;
17
	var $v_module_name;
18
	var $v_module_homepage;
19
	var $v_module_format;
20
	var $v_module_export_filename;
21
	var $v_filename;
22
	var $v_keyname;
23
	var $v_linkname;
24
	var $v_delimiter;
25
	var	$v_enclosure;
26

    
27
	var $v_field_filename;
28
	var $v_field_customers_groups;
29
	var $v_field_currency;
30
	var $v_field_shipping_costs;
31
	var $v_field_shipping_costs_free;
32
	var $v_field_attributes;
33
	var $v_field_campaign;
34
	var $v_field_export;
35
	var $v_field_additional_fields_array = array();
36
	var $v_shipping_country_id;
37

    
38
	var $v_category_file_path;
39
	var	$v_shipping_availability_array = array();
40
	var	$v_availability_array = array();
41
	var $v_allowed_units_array = array();
42
	var $v_allowed_unit_values_array = array();
43
	var $v_allowed_variants_array = array();
44
	var $v_use_variants = true;
45
	
46
	var $v_coo_additional_fields_controller;
47

    
48
	function Google_Shopping()
49
	{
50
		$this->save_config();
51
		$this->load_availabilities();
52
		$this->load_shipping_country();
53
		$this->formSettings();
54
		
55
		$this->v_allowed_units_array = array('mg', 'g', 'kg', 'ml', 'cl', 'l', 'cm', 'm', 'm2', 'cbm');
56
		$this->v_allowed_unit_values_array = array(1, 10, 100, 75, 50, 1000);
57
		
58
		$t_installed = gm_get_conf('GM_GOOGLE_SHOPPING_STATUS', 'ASSOC', true);
59
		
60
		if($t_installed === '1')
61
		{
62
			$this->v_coo_additional_fields_controller = MainFactory::create_object('AdditionalFieldControl');
63
			$this->load_additional_field_conf();
64
			$this->load_variants_fields_conf();			
65
		}		
66
	}
67

    
68
	function formSettings()
69
	{
70
		$this->v_partnerlink='';
71
		$this->v_export_type='comparison';
72
		$this->v_module_name='Google Shopping';
73
		$this->v_module_homepage='www.google.de/prdhp';
74
		$this->v_module_format='txt';
75
		$this->v_module_export_filename='google_shopping.txt';
76
		$this->v_filename='google_shopping.php';
77
		$this->v_keyname='GOOGLE_SHOPPING';
78
		$this->v_linkname='google_shopping';
79
		$this->v_delimiter="\t";
80
		$this->v_enclosure='';
81

    
82
		$this->v_field_filename=true;
83
		$this->v_field_customers_groups=true;
84
		$this->v_field_currency=true;
85
		$this->v_field_shipping_costs=true;
86
		$this->v_field_shipping_costs_free=true;
87
		$this->v_field_attributes=true;
88
		$this->v_field_campaign=true;
89
		$this->v_field_export=true;
90
		
91
		$this->v_category_file_path = 'http://www.google.com/basepages/producttype/taxonomy.de-DE.txt';
92
	}
93

    
94
	function formAddOn()
95
	{
96
		foreach(xtc_get_countriesList('', true, true) as $t_country)
97
		{
98
			$t_country_array[] = array('id' => $t_country['countries_id'], 'text' => $t_country['countries_name'] . ': ' . $t_country['countries_iso_code_2']);
99
		}
100
		
101
		$t_addOns = '<tr style="vertical-align:top; background-color:#d6e6f3;">
102
				   <td class="dataTableContent_gm"><strong>Google Kategorie URL</strong></td>
103
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('categorie_file_path', gm_get_conf('GM_GOOGLE_SHOPPING_CATEGORY_FILE_PATH', 'ASSOC', true), 'style="width: 450px;"')
104
				   .'<br />Geben Sie hier den Pfad zur Taxonomy Datei f&uuml;r die Google Produkt-Kategorien an.';
105

    
106
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
107
				   <td class="dataTableContent_gm"><strong>fehlende MPN generieren</strong></td>
108
				   <td class="dataTableContent_gm">'.xtc_draw_radio_field('auto_mpn', '0', ((int)gm_get_conf('GM_GOOGLE_SHOPPING_AUTO_MPN', 'ASSOC', true)) ? false : true).'nein'
109
				   .'<br />'.xtc_draw_radio_field('auto_mpn', '1', ((int)gm_get_conf('GM_GOOGLE_SHOPPING_AUTO_MPN', 'ASSOC', true)) ? true : false).'ja'
110
					.'<br />Sollen fehlende MPN automatisch aus der Artikelnummer oder, falls nicht vorhanden, per Zufall generiert und gespeichert werden?<br /><br />'
111
					.'<input type="checkbox" name="mpn_attribute_model" value="1"' . ((gm_get_conf('GM_GOOGLE_SHOPPING_MPN_ATTRIBUTE_MODEL') == '1') ? ' checked="checked"' : '') . ' /> Attributartikel-MPN nicht aus Artikelnummer und Attribut-Artikelnummer, sondern nur aus Attribut-Artikelnummer generieren.';
112

    
113
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
114
				   <td class="dataTableContent_gm"><strong>fehlende Marken generieren</strong></td>
115
				   <td class="dataTableContent_gm">'.xtc_draw_radio_field('auto_brand', '0', ((int)gm_get_conf('GM_GOOGLE_SHOPPING_AUTO_BRAND', 'ASSOC', true)) ? false : true).'nein'
116
				   .'<br />'.xtc_draw_radio_field('auto_brand', '1', ((int)gm_get_conf('GM_GOOGLE_SHOPPING_AUTO_BRAND', 'ASSOC', true)) ? true : false).'ja'
117
					.'<br />Sollen fehlende Marken aus dem Herstellernamen generiert und gespeichert werden?';
118

    
119
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
120
				   <td class="dataTableContent_gm"><strong>Versandland</strong></td>
121
				   <td class="dataTableContent_gm">' . xtc_draw_pull_down_menu('shipping_country', $t_country_array, $this->v_shipping_country_id)
122
					.'<br /> Versandland ausw&auml;hlen';
123

    
124
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
125
				   <td class="dataTableContent_gm"><strong>Farbe-Bezeichnungen</strong></td>
126
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('GM_GOOGLE_SHOPPING_COLOR', gm_get_conf('GM_GOOGLE_SHOPPING_COLOR', 'ASSOC', true), 'style="width: 450px;"')
127
				   .'<br />Kommagetrennte Bezeichnungen f&uuml;r Farbe.';
128
		
129
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
130
				   <td class="dataTableContent_gm"><strong>Gr&ouml;&szlig;e-Bezeichnungen</strong></td>
131
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('GM_GOOGLE_SHOPPING_SIZE', gm_get_conf('GM_GOOGLE_SHOPPING_SIZE', 'ASSOC', true), 'style="width: 450px;"')
132
				   .'<br />Kommagetrennte Bezeichnungen f&uuml;r Gr&ouml;&szlig;e.';
133
		
134
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
135
				   <td class="dataTableContent_gm"><strong>Material-Bezeichnungen</strong></td>
136
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('GM_GOOGLE_SHOPPING_MATERIAL', gm_get_conf('GM_GOOGLE_SHOPPING_MATERIAL', 'ASSOC', true), 'style="width: 450px;"')
137
				   .'<br />Kommagetrennte Bezeichnungen f&uuml;r Material.';
138
		
139
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
140
				   <td class="dataTableContent_gm"><strong>Muster-Bezeichnungen</strong></td>
141
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('GM_GOOGLE_SHOPPING_PATTERN', gm_get_conf('GM_GOOGLE_SHOPPING_PATTERN', 'ASSOC', true), 'style="width: 450px;"')
142
				   .'<br />Kommagetrennte Bezeichnungen f&uuml;r Muster.';
143
				
144
		$t_addOns .= '<tr style="vertical-align:top; background-color:#d6e6f3;">
145
				   <td class="dataTableContent_gm"><strong>Zusatzfelder</strong></td>
146
				   <td class="dataTableContent_gm">'.xtc_draw_input_field('additional_fields', gm_get_conf('GM_GOOGLE_SHOPPING_ADDITIONAL_FIELDS', 'ASSOC', true), 'style="width: 800px;"')
147
				   .'<br />Kommagetrennte Liste der Zusatzfelder, die beim Export ber?cksichtigt werden sollen.';
148
		
149
		// return addon setup
150
		return($t_addOns);
151
	}
152
	
153
	function load_availabilities()
154
	{
155
		$t_availability_sql = "SELECT
156
									s.shipping_status_id,
157
									a.google_export_availability_id,
158
									a.availability
159
								FROM
160
									shipping_status_to_google_availability s,
161
									google_export_availability a
162
								WHERE s.google_export_availability_id = a.google_export_availability_id";
163
		$t_availability_result = xtc_db_query($t_availability_sql);
164
		while($t_availability_result_array = xtc_db_fetch_array($t_availability_result))
165
		{
166
			$this->v_shipping_availability_array[$t_availability_result_array['shipping_status_id']] = array('ID' => $t_availability_result_array['google_export_availability_id'],
167
																									'NAME' => $t_availability_result_array['availability']);
168
		}
169

    
170
		$t_availability_sql = "SELECT
171
									google_export_availability_id,
172
									availability
173
								FROM google_export_availability";
174
		$t_availability_result = xtc_db_query($t_availability_sql);
175
		while($t_availability_result_array = xtc_db_fetch_array($t_availability_result))
176
		{
177
			$this->v_availability_array[$t_availability_result_array['google_export_availability_id']] = $t_availability_result_array['availability'];
178
		}
179
	}
180
	
181
	function load_shipping_country()
182
	{
183
		$this->v_shipping_country_id = gm_get_conf('GM_GOOGLE_SHOPPING_SHIPPING_COUNTRY', 'ASSOC', true) ? gm_get_conf('GM_GOOGLE_SHOPPING_SHIPPING_COUNTRY', 'ASSOC', true) : STORE_COUNTRY;
184
	}
185

    
186
	function save_config()
187
	{
188
		if(isset($_POST['shipping_country']))
189
		{
190
			gm_set_conf('GM_GOOGLE_SHOPPING_SHIPPING_COUNTRY', (int)$_POST['shipping_country']);
191
		}
192
		
193
		if(isset($_POST['additional_fields']))
194
		{
195
			gm_set_conf('GM_GOOGLE_SHOPPING_ADDITIONAL_FIELDS', xtc_db_input($_POST['additional_fields']));
196
		}
197
		
198
		if(isset($_POST['GM_GOOGLE_SHOPPING_COLOR']))
199
		{
200
			gm_set_conf('GM_GOOGLE_SHOPPING_COLOR', trim($_POST['GM_GOOGLE_SHOPPING_COLOR']));
201
			gm_set_conf('GM_GOOGLE_SHOPPING_SIZE', trim($_POST['GM_GOOGLE_SHOPPING_SIZE']));
202
			gm_set_conf('GM_GOOGLE_SHOPPING_MATERIAL', trim($_POST['GM_GOOGLE_SHOPPING_MATERIAL']));
203
			gm_set_conf('GM_GOOGLE_SHOPPING_PATTERN', trim($_POST['GM_GOOGLE_SHOPPING_PATTERN']));
204
		}
205
		
206
		if(isset($_POST['auto_mpn']) && isset($_POST['auto_brand']))
207
		{
208
			gm_set_conf('GM_GOOGLE_SHOPPING_AUTO_MPN', (int)$_POST['auto_mpn']);
209
			gm_set_conf('GM_GOOGLE_SHOPPING_AUTO_BRAND', (int)$_POST['auto_brand']);
210

    
211
			if(isset($_POST['mpn_attribute_model']) && $_POST['mpn_attribute_model'] == '1')
212
			{
213
				gm_set_conf('GM_GOOGLE_SHOPPING_MPN_ATTRIBUTE_MODEL', 1);
214
			}
215
			else
216
			{
217
				gm_set_conf('GM_GOOGLE_SHOPPING_MPN_ATTRIBUTE_MODEL', 0);
218
			}
219

    
220
			if((int)$_POST['auto_mpn'] == 1)
221
			{
222
				xtc_db_query("INSERT INTO products_item_codes (products_id)
223
								SELECT
224
									p.products_id AS products_id
225
								FROM
226
									products AS p LEFT JOIN products_item_codes AS pic USING (products_id)
227
								WHERE
228
									google_export_condition IS NULL");
229

    
230
				xtc_db_query("UPDATE
231
									products AS p,
232
									products_item_codes AS pic
233
								SET
234
									code_mpn = products_model
235
								WHERE
236
									pic.products_id = p.products_id AND
237
									(pic.code_mpn = '' OR pic.code_mpn IS NULL)");
238

    
239
				xtc_db_query("UPDATE
240
									products_item_codes AS pic
241
								SET
242
									code_mpn = UPPER(LEFT(CAST(MD5(pic.products_id) AS CHAR), 5))
243
								WHERE
244
									pic.code_mpn = '' OR
245
									pic.code_mpn IS NULL");
246

    
247
			}
248

    
249
			if((int)$_POST['auto_brand'] == 1)
250
			{
251
				xtc_db_query("INSERT INTO products_item_codes (products_id)
252
								SELECT
253
									p.products_id AS products_id
254
								FROM
255
									products AS p LEFT JOIN products_item_codes AS pic USING (products_id)
256
								WHERE
257
									google_export_condition IS NULL");
258

    
259
				xtc_db_query("UPDATE
260
									products AS p,
261
									products_item_codes AS pic,
262
									manufacturers AS m
263
								SET
264
									pic.brand_name = m.manufacturers_name
265
								WHERE
266
									p.products_id = pic.products_id AND
267
									p.manufacturers_id = m.manufacturers_id AND
268
									(pic.brand_name = '' OR pic.brand_name IS NULL)");
269
			}
270

    
271
			return true;
272
		}
273
		
274
		return false;
275
	}
276

    
277
	function formatResults($p_products_array)
278
	{
279
		// ignore vouchers
280
		if(strpos($p_products_array['products_model'], 'GIFT_') === 0)
281
		{
282
			return false;
283
		}
284
		
285
		$c_products_id = (int)$p_products_array['products_id'];
286
		if(isset($p_products_array['products_id_copy']))
287
		{
288
			$c_products_id = (int)$p_products_array['products_id_copy'];
289
		}
290
		
291
		$t_google_categories_array = array();
292

    
293
		$t_google_sql = "SELECT google_category
294
							FROM products_google_categories
295
							WHERE products_id = '" . $c_products_id . "'";
296
		$t_google_result = xtc_db_query($t_google_sql);
297
		while($t_google_result_array = xtc_db_fetch_array($t_google_result))
298
		{
299
			$t_google_categories_array[] = $t_google_result_array['google_category'];
300
		}
301

    
302
		$p_products_array['google_category'] = '';
303
		if(!empty($t_google_categories_array))
304
		{
305
			$p_products_array['google_category'] = implode('","', $t_google_categories_array);
306
		}
307

    
308
		$p_products_array['products_price'] = number_format((double)$p_products_array['products_price'], 2, ',', '') . ' ' . gm_get_conf('GM_GOOGLE_SHOPPING_CURRENCY', 'ASSOC', true);
309
		
310
//		 special_price_period
311
		if( (isset($p_products_array['specials_id']) && !empty($p_products_array['specials_id']) ) &&  ( isset( $p_products_array['special_status']) && $p_products_array['special_status'] == 1) )
312
		{
313
			$t_start_timestamp = $p_products_array['specials_date_added'];
314
			if(isset($p_products_array['specials_last_modified']) && !empty($p_products_array['specials_last_modified']))
315
			{
316
				$t_start_timestamp = $p_products_array['specials_last_modified'];
317
			}
318
			
319
			$t_end_timestamp = $p_products_array['expires_date'];
320
			if(empty($p_products_array['expires_date']))
321
			{
322
				$t_end_timestamp = strtotime('+1 year', $t_start_timestamp);
323
			}
324
			
325
			$p_products_array['expires_date'] = date('c', $t_start_timestamp) . '/' . date('c', $t_end_timestamp);
326
		}
327
		else
328
		{
329
			$p_products_array['expires_date'] = '';
330
		}
331
		 
332
		// FSK18
333
		$p_products_array['products_fsk18'] = $p_products_array['products_fsk18'] == 1 ? 'TRUE ' : 'FALSE';
334
		
335
		// shipping_costs
336
		if(trim($_POST['shipping_costs']) != '')
337
		{
338
			$t_country_result = xtc_db_query('SELECT countries_iso_code_2 FROM ' . TABLE_COUNTRIES . ' WHERE countries_id = ' . $this->v_shipping_country_id);
339
			$t_row = xtc_db_fetch_array($t_country_result);
340
			$t_country_iso = $t_row['countries_iso_code_2'];
341
			$p_products_array['products_shipping_costs'] = $t_country_iso . ':::' . number_format((double)$p_products_array['products_shipping_costs'], 2, '.', '') . ' ' . gm_get_conf('GM_GOOGLE_SHOPPING_CURRENCY', 'ASSOC', true);
342
		}
343
		else
344
		{
345
			$p_products_array['products_shipping_costs'] = number_format((double)$p_products_array['products_shipping_costs'], 2, '.', '');
346
		}
347
		
348
		$p_products_array['products_description'] = trim(no_html($p_products_array['products_description']));
349
		if(!empty($p_products_array['products_description']) && strlen($p_products_array['products_description']) > 1500)
350
		{
351
			$desc = $p_products_array['products_description'];
352
			$length = strpos($desc, " ", 1500);
353
			if($length !== false)
354
			{
355
				$p_products_array['products_description'] = substr($p_products_array['products_description'], 0, $length) . '[...]';
356
			}
357
		}
358

    
359
		$t_images_array = array();
360
		// 1-9 additional images
361
		for($i = 2; $i <= (int)MO_PICS+1 && $i < 11; $i++)
362
		{
363
			if(isset($p_products_array['products_image_' . $i]) && !empty($p_products_array['products_image_' . $i]))
364
			{
365
				$t_images_array[] = $p_products_array['products_image_' . $i];
366
			}
367
		}
368
		$p_products_array['products_images'] = implode(',', $t_images_array);
369

    
370
		$p_products_array['google_export_gtin'] = '';
371
		if(!empty($p_products_array['products_ean']))
372
		{
373
			$p_products_array['google_export_gtin'] = trim($p_products_array['products_ean']);
374
		}
375
		elseif(!empty($p_products_array['code_isbn']))
376
		{
377
			$p_products_array['google_export_gtin'] = trim($p_products_array['code_isbn']);
378
		}
379
		elseif(!empty($p_products_array['code_upc']))
380
		{
381
			$p_products_array['google_export_gtin'] = trim($p_products_array['code_upc']);
382
		}
383
		elseif(!empty($p_products_array['code_jan']))
384
		{
385
			$p_products_array['google_export_gtin'] = trim($p_products_array['code_jan']);
386
		}
387

    
388
		if(empty($p_products_array['google_export_condition']))
389
		{
390
			$p_products_array['google_export_condition'] = 'neu';
391
		}
392

    
393
		if(isset($p_products_array['products_attributes_id']) && isset($p_products_array['products_id_copy']))
394
		{
395
			$p_products_array['products_id'] = $p_products_array['products_id_copy'] . 'a' . $p_products_array['products_attributes_id'];
396
		}
397

    
398
		if(empty($p_products_array['google_export_availability_id']) 
399
				&& !empty($p_products_array['shipping_status_id'])
400
				&& isset($this->v_shipping_availability_array[(int)$p_products_array['shipping_status_id']]))
401
		{
402
			$p_products_array['google_export_availability_id'] = $this->v_shipping_availability_array[(int)$p_products_array['shipping_status_id']]['ID'];
403
			$p_products_array['google_export_availability'] = $this->v_shipping_availability_array[(int)$p_products_array['shipping_status_id']]['NAME'];
404
		}
405
		elseif(!empty($p_products_array['google_export_availability_id']) && isset($this->v_availability_array[(int)$p_products_array['google_export_availability_id']]))
406
		{
407
			$p_products_array['google_export_availability'] = $this->v_availability_array[(int)$p_products_array['google_export_availability_id']];
408
		}
409
		
410
		if (!empty($p_products_array['identifier_exists']) && !empty($p_products_array['google_export_gtin']))
411
		{
412
			$p_products_array['identifier_exists'] = 'TRUE';
413
		}
414
		else
415
		{
416
			$p_products_array['identifier_exists'] = 'FALSE';
417
		}
418

    
419
		if(!empty($p_products_array['code_mpn']) && isset($p_products_array['products_attributes_id']))
420
		{
421
			if(!empty($p_products_array['attributes_model']))
422
			{
423
				if(gm_get_conf('GM_GOOGLE_SHOPPING_MPN_ATTRIBUTE_MODEL', 'ASSOC', true) == '1')
424
				{
425
					$p_products_array['code_mpn'] = $p_products_array['attributes_model'];
426
				}
427
				else
428
				{
429
					$p_products_array['code_mpn'] .= $p_products_array['attributes_model'];
430
				}
431
			}
432
			else
433
			{
434
				$p_products_array['code_mpn'] .= '-' . $p_products_array['products_attributes_id'];
435
			}
436
		}
437
		elseif(isset($p_products_array['products_attributes_id']) && !empty($p_products_array['attributes_model']) && gm_get_conf('GM_GOOGLE_SHOPPING_MPN_ATTRIBUTE_MODEL', 'ASSOC', true) == '1')
438
		{
439
			$p_products_array['code_mpn'] = $p_products_array['attributes_model'];
440
		}
441
		
442
		$p_products_array['products_name'] = str_replace("\t", ' ', $p_products_array['products_name']);
443
		$p_products_array['products_description'] = str_replace("\t", ' ', $p_products_array['products_description']);
444
		$p_products_array['products_weight'] = (double)$p_products_array['products_weight'] . ' kg';
445
		
446
		
447
		$p_products_array['expiration_date'] = str_replace('0000-00-00', '', $p_products_array['expiration_date']);
448
		
449
		
450
		// addtional fields
451
		$this->set_additional_field_data($p_products_array);
452

    
453
		$this->set_vpe_data($p_products_array);		
454
		
455
		if(!empty($p_products_array['specials_id']))
456
		{
457
			$p_products_array['specials_new_products_price'] = $p_products_array['products_price'];
458
		}		
459
		
460
		if(isset($p_products_array['retail_price']))
461
		{
462
			$p_products_array['products_price'] = number_format((double)$p_products_array['retail_price'], 2, ',', '') . ' ' . gm_get_conf('GM_GOOGLE_SHOPPING_CURRENCY', 'ASSOC', true);;
463
		}
464
		
465
		$this->set_variants_data($p_products_array);
466
		
467
		return $p_products_array;
468
	}
469

    
470
	function exportScheme()
471
	{
472
		$t_csv_fields_array=array();
473
		$t_csv_fields_array['products_id'] = 'ID';
474
		$t_csv_fields_array['products_name'] = 'Titel';
475
		$t_csv_fields_array['products_description'] = 'Beschreibung';
476
		$t_csv_fields_array['google_category'] = 'Google Produktkategorie';
477
		$t_csv_fields_array['products_categories'] = 'Produkttyp';
478
		$t_csv_fields_array['products_link'] = 'Link';
479
		$t_csv_fields_array['products_image_1'] = 'Bildlink';
480
		$t_csv_fields_array['products_images'] = html_entity_decode_wrapper('Zus&auml;tzlicher Bildlink');
481
		$t_csv_fields_array['google_export_condition'] = 'Zustand';
482
		$t_csv_fields_array['google_export_availability'] = html_entity_decode_wrapper('Verf&uuml;gbarkeit');
483
		$t_csv_fields_array['products_price'] = 'Preis';
484
		$t_csv_fields_array['specials_new_products_price'] = 'Sonderangebotspreis';
485
		$t_csv_fields_array['expires_date'] = 'Sonderangebotszeitraum';
486
		$t_csv_fields_array['brand_name'] = 'Marke';
487
		$t_csv_fields_array['google_export_gtin'] = 'GTIN';
488
		$t_csv_fields_array['code_mpn']= 'MPN';
489
		$t_csv_fields_array['identifier_exists']= 'Kennzeichnung existiert';
490
		$t_csv_fields_array['gender']= 'Geschlecht';
491
		$t_csv_fields_array['age_group']= 'Altersgruppe';
492
		$t_csv_fields_array['products_shipping_costs']= 'Versand';
493
		$t_csv_fields_array['products_weight']= 'Versandgewicht';
494
		$t_csv_fields_array['products_fsk18']= 'Erwachsene';
495
		$t_csv_fields_array['unit_price_measure']= html_entity_decode_wrapper('Grundpreis Ma&szlig;');
496
		$t_csv_fields_array['unit_pricing_base_measure']= html_entity_decode_wrapper('Grundpreis Einheitsma&szlig;');
497
		$t_csv_fields_array['expiration_date']= 'Verfallsdatum';
498
		
499
		$t_csv_fields_array['Farbe']= 'Farbe'; 
500
		$t_csv_fields_array[html_entity_decode_wrapper('Gr&ouml;&szlig;e')]= html_entity_decode_wrapper('Gr&ouml;&szlig;e'); 
501
		$t_csv_fields_array['Material']= 'Material'; 
502
		$t_csv_fields_array['Muster']= 'Muster';
503
		$t_csv_fields_array['item_group_id']= 'Produktgruppe';
504
		
505
		// additional fields
506
		$t_additional_fields = $this->v_coo_additional_fields_controller->get_field_names_by_item_type('product');
507
		if(is_array($t_additional_fields) && count($t_additional_fields))
508
		{
509
			foreach($t_additional_fields as $t_coo_additional_field)
510
			{
511
				$t_field_name_array = $t_coo_additional_field->get_name_array();
512
				$t_field_name = $t_field_name_array[$_SESSION['languages_id']];
513
				if($this->is_field_selected($t_field_name))
514
					$t_csv_fields_array[$t_field_name] = $t_field_name;
515
			}
516
		}
517
		
518
		return($t_csv_fields_array);
519
	}
520
	
521
	// $p_variant_array = array('name' => 'Farbe', 'value' => 'rot')
522
	function get_variant_name($p_property_name)
523
	{
524
		$t_color = trim(gm_get_conf('GM_GOOGLE_SHOPPING_COLOR', 'ASSOC', true));
525
		$t_size = trim(gm_get_conf('GM_GOOGLE_SHOPPING_SIZE', 'ASSOC', true));
526
		$t_material = trim(gm_get_conf('GM_GOOGLE_SHOPPING_MATERIAL', 'ASSOC', true));
527
		$t_pattern = trim(gm_get_conf('GM_GOOGLE_SHOPPING_PATTERN', 'ASSOC', true));
528
		$t_variants_array = array();
529
		
530
		$t_variants_array['Farbe'] = array($t_color);
531
		if(strpos($t_color, ',') !== false)
532
		{
533
			$t_variants_array['Farbe'] = preg_split('/\s*,\s*/', $t_color);
534
		}
535
		
536
		$t_variants_array[html_entity_decode_wrapper('Gr&ouml;&szlig;e')] = array($t_size);
537
		if(strpos($t_size, ',') !== false)
538
		{
539
			$t_variants_array[html_entity_decode_wrapper('Gr&ouml;&szlig;e')] = preg_split('/\s*,\s*/', $t_size);
540
		}
541
		
542
		$t_variants_array['Material'] = array($t_material);
543
		if(strpos($t_material, ',') !== false)
544
		{
545
			$t_variants_array['Material'] = preg_split('/\s*,\s*/', $t_material);
546
		}
547
		
548
		$t_variants_array['Muster'] = array($t_pattern);
549
		if(strpos($t_pattern, ',') !== false)
550
		{
551
			$t_variants_array['Muster'] = preg_split('/\s*,\s*/', $t_pattern);
552
		}
553
		
554
		foreach($t_variants_array AS $t_variant_name => $t_values_array)
555
		{
556
			foreach($t_values_array AS $t_alternative_name)
557
			{
558
				if($p_property_name == $t_alternative_name)
559
				{
560
					return $t_variant_name;
561
				}
562
			}
563
		}
564
		
565
		return false;
566
	}
567
	
568
	function load_additional_field_conf()
569
	{
570
		$t_additional_fields = gm_get_conf('GM_GOOGLE_SHOPPING_ADDITIONAL_FIELDS', 'ASSOC', true);
571
		if($t_additional_fields === null || $t_additional_fields === false)
572
		{
573
			gm_set_conf('GM_GOOGLE_SHOPPING_ADDITIONAL_FIELDS', 'Farbe,Gr??e,Material,Muster,Adwords Gruppierung,Adwords Label,Adwords Weiterleitung,Energieeffizienzklasse,Ausgeschlossenes Ziel');
574
			$this->load_additional_field_conf();
575
		}
576
			
577
		if(strpos($t_additional_fields, ',') !== false)
578
		{
579
			$t_additional_fields = explode(',', $t_additional_fields);
580
			if(is_array($t_additional_fields))
581
			{
582
				foreach($t_additional_fields as $t_additional_field)
583
				{
584
					$this->v_field_additional_fields_array[] = trim($t_additional_field);
585
				}
586
			}
587
		}
588
		elseif(!empty($t_additional_fields))
589
		{
590
			$this->v_field_additional_fields_array[] = trim($t_additional_fields);
591
		}
592
	}
593
	
594
	function is_field_selected($p_additional_field_name)
595
	{
596
		if(in_array($p_additional_field_name, $this->v_field_additional_fields_array))
597
			return true;
598
			
599
		return false;
600
	}
601
	
602
	function set_additional_field_data(&$p_products_array)
603
	{
604
		if(!isset($p_products_array['products_id'])) return false;
605
		
606
		$c_products_id = $p_products_array['products_id'];
607
		
608
		$t_additional_fields = $this->v_coo_additional_fields_controller->get_fields_by_item_id_and_item_type($c_products_id, 'product');
609
		if(is_array($t_additional_fields) && count($t_additional_fields))
610
		{
611
			foreach($t_additional_fields as $t_coo_additional_field)
612
			{
613
				$t_field_name_array = $t_coo_additional_field->get_name_array();
614
				$t_field_name = $t_field_name_array[$_SESSION['languages_id']];
615
				if($this->is_field_selected($t_field_name))
616
				{
617
					$t_field_value = '';
618
					$t_coo_field_value_array = $t_coo_additional_field->get_field_value_array();
619
					foreach($t_coo_field_value_array as $t_coo_field_value)
620
					{
621
						$t_field_values_array = $t_coo_field_value->get_value_array();
622
						$t_field_value = '';
623
						if(count($t_field_values_array) != 0)
624
						{
625
							if($t_coo_additional_field->is_multilingual())
626
							{
627
								$t_field_value = $t_field_values_array[$_SESSION['languages_id']];
628
							}
629
							else
630
							{
631
								$t_field_value = $t_field_values_array[0];
632
							}
633
						}
634
					}
635
					$p_products_array[$t_field_name] = $t_field_value;
636
				}
637
			}
638
		}
639
	}
640
	
641
	function set_vpe_data(&$p_products_array)
642
	{
643
		if($p_products_array['products_vpe_name'] != '')
644
		{
645
			$t_vpe_name = trim($p_products_array['products_vpe_name']);
646
			preg_match('/([0-9]*)(.+)/', $t_vpe_name, $t_matches_array);
647
			
648
			$t_unit_value = (double)$t_matches_array[1];
649
			if(empty($t_unit_value))
650
			{
651
				$t_unit_value = 1;
652
			}
653
			$t_unit_name = trim($t_matches_array[2]);
654
			
655
			$p_products_array['unit_pricing_base_measure'] = '';
656
			$p_products_array['unit_price_measure'] = '';
657
			
658
			if(in_array($t_unit_name, $this->v_allowed_units_array) && in_array($t_unit_value, $this->v_allowed_unit_values_array))
659
			{
660
				$t_continue = true;
661
				
662
				switch($t_unit_value)
663
				{
664
					case 50:
665
					case 1000:
666
						if($t_unit_name != 'kg')
667
						{
668
							$t_continue = false;
669
						}
670
						break;
671
					case 75:
672
						if($t_unit_name != 'cl')
673
						{
674
							$t_continue = false;
675
						}
676
				}			
677
				
678
				if($t_continue === true)
679
				{
680
					$p_products_array['unit_pricing_base_measure'] = $t_unit_value . ' ' . $t_unit_name;
681

    
682
					$t_unit_price_measure_value = (string)((double)$p_products_array['vpe_multiplier'] * $t_unit_value);
683
					$t_unit_price_measure_value = str_replace('.', ',', $t_unit_price_measure_value);
684
					$p_products_array['unit_price_measure'] = $t_unit_price_measure_value . ' ' . $t_unit_name;
685
				}
686
			}		
687
		}
688
	}
689
	
690
	function set_variants_data(&$p_products_array)
691
	{
692
		$t_products_name_suffix_array = array();
693
						
694
		if((isset($p_products_array['properties']) && !empty($p_products_array['properties'])) || (isset($p_products_array['options']) && !empty($p_products_array['options'])))
695
		{
696
			$p_products_array['item_group_id'] = $p_products_array['products_id_copy'];
697
		}
698
		
699
		if(isset($p_products_array['properties']) && is_array($p_products_array['properties']))
700
		{
701
			foreach($p_products_array['properties'] AS $t_property_array)
702
			{
703
				$t_variant_name = $this->get_variant_name($t_property_array['properties_name']);
704
				
705
				if($t_variant_name !== false)
706
				{
707
					$p_products_array[$t_variant_name] = $t_property_array['values_name'];
708
				}
709
				else
710
				{
711
					$p_products_array['item_group_id'] .= 'P' . $t_property_array['properties_id'] . 'P' . $t_property_array['properties_values_id'];
712
					
713
					$t_products_name_suffix_array[] = $t_property_array['properties_name'] . ': ' . $t_property_array['values_name'];
714
				}
715
			}
716
		}
717
		
718
		if(isset($p_products_array['options']['names']) && is_array($p_products_array['options']['names']) && !empty($p_products_array['options']['names']))
719
		{
720
			foreach($p_products_array['options']['names'] AS $t_key => $t_names_array)
721
			{
722
				$t_variant_name = $this->get_variant_name($t_names_array['option_name']);
723

    
724
				if($t_variant_name !== false)
725
				{
726
					$p_products_array[$t_variant_name] = $t_names_array['value_name'];
727
				}
728
				else
729
				{
730
					$p_products_array['item_group_id'] .= 'A' . str_replace('_', 'A', $t_key);
731
					
732
					$t_products_name_suffix_array[] = $t_names_array['option_name'] . ': ' . $t_names_array['value_name'];
733
				}
734
			}
735
		}
736
		
737
		if(!empty($t_products_name_suffix_array))
738
		{
739
			$p_products_array['products_name'] .= ' (' . implode(', ', $t_products_name_suffix_array) . ')';
740
		}
741
	}
742
	
743
	function load_variants_fields_conf()
744
	{
745
		$t_color = gm_get_conf('GM_GOOGLE_SHOPPING_COLOR', 'ASSOC', true);
746
		if($t_color === null || $t_color === false)
747
		{
748
			gm_set_conf('GM_GOOGLE_SHOPPING_COLOR', 'Farbe');			
749
		}
750

    
751
		$t_size = gm_get_conf('GM_GOOGLE_SHOPPING_SIZE', 'ASSOC', true);
752
		if($t_size === null || $t_size === false)
753
		{
754
			gm_set_conf('GM_GOOGLE_SHOPPING_SIZE', html_entity_decode_wrapper('Gr&ouml;&szlig;e'));			
755
		}
756

    
757
		$t_material = gm_get_conf('GM_GOOGLE_SHOPPING_MATERIAL', 'ASSOC', true);
758
		if($t_material === null || $t_material === false)
759
		{
760
			gm_set_conf('GM_GOOGLE_SHOPPING_MATERIAL', 'Material');			
761
		}
762

    
763
		$t_pattern = gm_get_conf('GM_GOOGLE_SHOPPING_PATTERN', 'ASSOC', true);
764
		if($t_pattern === null || $t_pattern === false)
765
		{
766
			gm_set_conf('GM_GOOGLE_SHOPPING_PATTERN', 'Muster');			
767
		}
768
	}
769
}
    (1-1/1)