Projekt

Allgemein

Profil

GX-Bug #42058 » ProductPropertiesStructSupplier.inc.php

/system/classes/properties/ - Till Tepelmann, 05.05.2015 18:42

 
1
<?php
2
/* --------------------------------------------------------------
3
   ProductPropertiesStructSupplier.inc.php 2015-01-13 gm
4
   Gambio GmbH
5
   http://www.gambio.de
6
   Copyright (c) 2014 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
class ProductPropertiesStructSupplier
13
{
14
    protected $v_combis_array = array();
15
    protected $v_properties_array = array();
16
    protected $v_max_get_values = 1000;
17
    
18
    public function __construct() {}
19
  
20
    public function get_all_combis($p_products_id, $p_language_id, $p_combis_values_type = 'no', $p_offset = 0, $p_limit = 300)
21
    {
22
        $t_use_limit = true;
23
        
24
        $c_products_id = (int)$p_products_id;
25
        if(empty($c_products_id)) trigger_error('get_all_combis(): typeof($p_products_id) != integer', E_USER_ERROR);
26

    
27
        $c_language_id = (int)$p_language_id;
28
        if(empty($c_language_id)) trigger_error('get_all_combis(): typeof($p_language_id) != integer', E_USER_ERROR);
29

    
30
        $c_offset = (int)$p_offset;
31

    
32
        $c_limit = (int)$p_limit;
33
        if(empty($c_limit)) $t_use_limit = false;
34

    
35
        // allowed values: full, ids, no
36
        $c_combis_values_type = (string)$p_combis_values_type;
37
        if($c_combis_values_type != 'full' && 
38
           $c_combis_values_type != 'ids')
39
        {
40
            $c_combis_values_type = 'no';
41
        }
42
        
43
        // reset combis_array
44
        $this->v_combis_array = array();
45
        
46
        // get products_tax_class_id
47
        $coo_product = MainFactory::create_object('GMDataObject', array('products', array('products_id' => $c_products_id)));
48
        $t_products_tax_class_id = $coo_product->get_data_value('products_tax_class_id');
49
        
50
        $coo_xtc_price = new xtcPrice(DEFAULT_CURRENCY,$_SESSION['customers_status']['customers_status_id']);
51
        
52
        $t_sql = '
53
            SELECT
54
                products_properties_combis_id,
55
                sort_order,
56
                combi_model,
57
                combi_quantity,
58
                combi_ean,
59
                combi_weight,
60
                combi_price_type,
61
                combi_price,
62
                combi_image,
63
                combi_shipping_status_id,
64
                products_vpe_id,
65
                vpe_value
66
            FROM
67
                products_properties_combis
68
            WHERE
69
                products_id = "'.$c_products_id.'"
70
            ORDER BY
71
                sort_order
72
        ';
73
       
74
        if($t_use_limit)
75
        {
76
            $t_sql .= '
77
                LIMIT '.$c_offset.', '.$c_limit;
78
        }
79
        
80
        $t_result = xtc_db_query($t_sql);
81

    
82
        while($t_row = xtc_db_fetch_array($t_result))
83
        {
84
			$t_row['combi_quantity'] = (double)$t_row['combi_quantity'];
85
			
86
            if(PRICE_IS_BRUTTO == 'true')
87
            {
88
                $t_row['combi_price'] = $coo_xtc_price->xtcAddTax($t_row['combi_price'], $coo_xtc_price->TAX[$t_products_tax_class_id]);
89
            }
90
            $this->v_combis_array[$t_row['products_properties_combis_id']] = $t_row;
91
            $this->v_combis_array[$t_row['products_properties_combis_id']]['combi_price_formatted'] = $coo_xtc_price->xtcFormat($t_row['combi_price'], true);
92
			}
93
        
94
        if(count($this->v_combis_array) > 0){
95
            $this->get_combis_values($c_language_id);
96
        }
97
        
98
        return $this->v_combis_array;
99
    }
100
    
101
    public function get_combis($p_products_id, $p_combis_id, $p_language_id, $p_combis_values_type = 'no')
102
    {
103
        $c_products_id = (int)$p_products_id;
104
        if(empty($c_products_id)) trigger_error('get_combis(): typeof($p_products_id) != integer', E_USER_ERROR);
105
		
106
        $c_combis_id = (int)$p_combis_id;
107
        if(empty($c_combis_id)) trigger_error('get_combis(): typeof($p_combis_id) != integer', E_USER_ERROR);
108

    
109
        $c_language_id = (int)$p_language_id;
110
        if(empty($c_language_id)) trigger_error('get_combis(): typeof($p_language_id) != integer', E_USER_ERROR);
111
        
112
        // allowed values: full, ids, no
113
        $c_combis_values_type = (string)$p_combis_values_type;
114
        if($c_combis_values_type != 'full' && 
115
           $c_combis_values_type != 'ids')
116
        {
117
            $c_combis_values_type = 'no';
118
        }
119
        
120
        // reset combis_array
121
        $this->v_combis_array = array();
122
        
123
        // get products_tax_class_id
124
        $coo_product = MainFactory::create_object('GMDataObject', array('products', array('products_id' => $c_products_id)));
125
        $t_products_tax_class_id = $coo_product->get_data_value('products_tax_class_id');
126
        
127
        $coo_xtc_price = new xtcPrice(DEFAULT_CURRENCY,$_SESSION['customers_status']['customers_status_id']);
128
        
129
        $t_sql = '
130
            SELECT
131
                products_properties_combis_id,
132
                sort_order,
133
                combi_model,
134
                combi_quantity,
135
                combi_ean,
136
                combi_weight,
137
                combi_price_type,
138
                combi_price,
139
                combi_image,
140
                combi_shipping_status_id,
141
                products_vpe_id,
142
                vpe_value
143
            FROM
144
                products_properties_combis
145
            WHERE
146
                products_properties_combis_id = "'.$c_combis_id.'"
147
        ';
148
        
149
        $t_result = xtc_db_query($t_sql);
150
        
151
        while($t_row = xtc_db_fetch_array($t_result))
152
        {
153
            $this->v_combis_array[$t_row['products_properties_combis_id']] = $t_row;
154
            if(PRICE_IS_BRUTTO == 'true')
155
            {
156
                $t_combi_price_total = $coo_xtc_price->xtcAddTax($t_row['combi_price'], $coo_xtc_price->TAX[$t_products_tax_class_id]);
157
            }
158
            else
159
			{
160
                $t_combi_price_total = $t_row['combi_price'];
161
			}
162
            $this->v_combis_array[$t_row['products_properties_combis_id']]['combi_price_total'] = $t_combi_price_total;
163
            $this->v_combis_array[$t_row['products_properties_combis_id']]['combi_price_formatted'] = $coo_xtc_price->xtcFormat($t_combi_price_total, true);
164
        }
165
        
166
        if(count($this->v_combis_array) > 0){
167
            $this->get_combis_values($c_language_id);
168
        }
169
        
170
        return $this->v_combis_array[$c_combis_id];
171
    }
172
    
173
    protected function get_combis_values($p_language_id)
174
    {
175
        $c_language_id = (int)$p_language_id;
176
        if(empty($c_language_id)) trigger_error('get_combis_values(): typeof($p_language_id) != integer', E_USER_ERROR);
177
        
178
        $t_array_length = count($this->v_combis_array);
179
        
180
        for($i = 1, $total = ceil($t_array_length / $this->v_max_get_values); $i <= $total; $i++)
181
        {
182
            if($i * $this->v_max_get_values > $t_array_length)
183
            {
184
                $t_limit = $t_array_length - (($i - 1) * $this->v_max_get_values);
185
            }
186
            else
187
            {
188
                $t_limit = $this->v_max_get_values;
189
            }
190
            $t_tmp_array = array_slice($this->v_combis_array, ($i - 1) * $this->v_max_get_values, $t_limit, true);
191
            
192
            $t_sql = '
193
                SELECT 
194
                    products_properties_combis_id,
195
                    properties_values_id,
196
                    properties_name,        
197
                    properties_admin_name,        
198
                    values_name     
199
                FROM 
200
                    products_properties_index
201
                WHERE
202
                    products_properties_combis_id IN ('.implode(',', array_keys($t_tmp_array)).') AND
203
                    language_id = "'.$c_language_id.'"
204
                ORDER BY
205
                    properties_sort_order,
206
                    properties_id,
207
                    value_sort_order,
208
                    properties_values_id
209
            ';
210

    
211
            $t_result = xtc_db_query($t_sql);
212

    
213
            # init properties_values and group in properties
214
            while($t_row = xtc_db_fetch_array($t_result))
215
            {
216
                $this->v_combis_array[$t_row['products_properties_combis_id']]['combis_values'][$t_row['properties_values_id']] = $t_row;
217
            }
218
        }
219
    }
220
    
221
    public function get_all_properties()
222
    {
223
        // reset properties array
224
        $this->v_properties_array = array();
225
        
226
        $t_sql = '
227
            SELECT
228
                properties_id,
229
                sort_order
230
            FROM 
231
                properties
232
            ORDER BY
233
                sort_order,
234
                properties_id
235
        ';
236
        $t_result = xtc_db_query($t_sql);
237

    
238
        # init properties_names
239
        while($t_row = xtc_db_fetch_array($t_result))
240
        {
241
            $this->v_properties_array[$t_row['properties_id']] = $t_row;
242
        }
243
        
244
        if(count($this->v_properties_array) > 0){
245
            $this->get_properties_names();
246
            $this->get_properties_values();
247
        }
248
        
249
        return $this->v_properties_array;
250
    }
251
    
252
    public function get_all_properties_by_products_id($p_products_id)
253
    {
254
        $c_products_id = (int)$p_products_id;
255
        if(empty($c_products_id)) trigger_error('get_all_properties_by_products_id(): typeof($p_products_id) != integer', E_USER_ERROR);
256
        
257
        // reset properties array
258
        $this->v_properties_array = array();
259

    
260
        $t_sql = '
261
            SELECT
262
                properties_id,
263
                properties_sort_order
264
            FROM 
265
                products_properties_index
266
            WHERE
267
                products_id = "'.$c_products_id.'"
268
            GROUP BY 
269
                properties_id
270
            ORDER BY
271
                properties_sort_order,
272
                properties_id
273
        ';
274
        $t_result = xtc_db_query($t_sql);
275

    
276
        # init properties_names
277
        while($t_row = xtc_db_fetch_array($t_result))
278
        {
279
            $this->v_properties_array[$t_row['properties_id']] = $t_row;
280
        }
281
        
282
        if(count($this->v_properties_array) > 0){
283
            $this->get_properties_names();
284
            $this->get_properties_values($c_products_id);
285
        }  
286
        
287
        return $this->v_properties_array;
288
    }
289
    
290
    public function get_properties($p_properties_id)
291
    {
292
        $c_properties_id = (int)$p_properties_id;
293
        if(empty($c_properties_id)) trigger_error('get_properties(): typeof($p_properties_id) != integer', E_USER_ERROR);
294
        
295
        // reset properties array
296
        $this->v_properties_array = array();
297
        
298
        $t_sql = '
299
        SELECT
300
            p.properties_id AS properties_id,
301
            p.sort_order AS sort_order
302
        FROM 
303
            properties AS p
304
            LEFT JOIN properties_description AS pd USING (properties_id)
305
        WHERE
306
            properties_id = "'.$c_properties_id.'"
307
        GROUP BY
308
            p.properties_id
309
        ';
310
        $t_result = xtc_db_query($t_sql);
311

    
312
        # init properties_names
313
        while($t_row = xtc_db_fetch_array($t_result))
314
        {
315
            $this->v_properties_array[$t_row['properties_id']] = $t_row;
316
        }
317
        
318
        if(count($this->v_properties_array) > 0){
319
            $this->get_properties_names();
320
            $this->get_properties_values();
321
        } 
322
        
323
        return $this->v_properties_array[$c_properties_id];
324
    }
325
    
326
    public function get_properties_values($p_products_id = 0)
327
    {
328
		$t_products_tax_class_id = 0;
329
		
330
		$c_products_id = (int)$p_products_id;
331
		if(!empty($c_products_id) && $_SESSION['customers_status']['customers_status_show_price_tax'] == 0)
332
		{
333
			// get products_tax_class_id
334
			$coo_product = MainFactory::create_object('GMDataObject', array('products', array('products_id' => $c_products_id)));
335
			$t_products_tax_class_id = $coo_product->get_data_value('products_tax_class_id');
336
		}
337
		
338
        $t_properties_values_ids_array = array();
339
//        print_r($_SESSION);
340
        $coo_xtc_price = new xtcPrice($_SESSION['currency'], $_SESSION['customers_status']['customers_status_id']);
341
        
342
        $t_sql = '
343
            SELECT 
344
                properties_values_id,
345
                properties_id,
346
                sort_order,
347
                value_model,
348
                value_price
349
            FROM 
350
                properties_values
351
            WHERE
352
                properties_id IN ('.implode(',', array_keys($this->v_properties_array)).')
353
            ORDER BY
354
                sort_order,
355
                properties_values_id
356
        ';
357
        $t_result = xtc_db_query($t_sql);
358

    
359
        # init properties_values and group in properties
360
        while($t_row = xtc_db_fetch_array($t_result))
361
        {
362
            $this->v_properties_array[$t_row['properties_id']]['properties_values'][$t_row['properties_values_id']] = $t_row;     
363
			$t_value_price = '';
364
			if((double)$t_row['value_price'] != 0)
365
			{
366
				$t_value_price = (double)$t_row['value_price'];
367
				$t_value_price = $coo_xtc_price->xtcCalculateCurr($t_value_price);
368
				$t_discount = $coo_xtc_price->xtcCheckDiscount($p_products_id);
369
				if(!empty($t_discount) && $_SESSION['customers_status']['customers_status_discount_attributes'] == 1)
370
				{
371
					$t_value_price = $coo_xtc_price->xtcFormatSpecialDiscount($p_products_id, $t_discount, $t_value_price, false);
372
				}
373
				if($_SESSION['customers_status']['customers_status_show_price_tax'] == 0)
374
				{
375
					$t_value_price = $coo_xtc_price->xtcRemoveTax($t_value_price, $coo_xtc_price->TAX[$t_products_tax_class_id]);
376
				}
377
				$t_value_price = $coo_xtc_price->xtcFormat($t_value_price, true);
378
			}
379
            $this->v_properties_array[$t_row['properties_id']]['properties_values'][$t_row['properties_values_id']]['value_price_formatted'] = trim($t_value_price);
380
            $t_properties_values_ids_array[$t_row['properties_values_id']] = $t_row['properties_id'];
381
        }
382
        
383
        if(count($t_properties_values_ids_array) > 0)
384
        {
385
            $this->get_properties_values_names($t_properties_values_ids_array);        
386
        }        
387
    }
388
    
389
    public function get_properties_values_by_properties_values_id($p_properties_values_id)
390
    {
391
        $c_properties_values_id = (int)$p_properties_values_id;
392
        if(empty($c_properties_values_id)) trigger_error('get_properties_values_by_properties_values_id(): typeof($p_properties_values_id) != integer', E_USER_ERROR);
393
        
394
        $t_properties_values_ids_array = array();
395
        
396
        //reset properties array
397
        $this->v_properties_array = array();
398
        
399
        $coo_xtc_price = new xtcPrice(DEFAULT_CURRENCY,$_SESSION['customers_status']['customers_status_id']);
400
        
401
        $t_sql = '
402
            SELECT 
403
                properties_values_id,
404
                properties_id,
405
                sort_order,
406
                value_model,
407
                value_price
408
            FROM 
409
                properties_values
410
            WHERE
411
                properties_values_id = '.$c_properties_values_id.'
412
        ';
413
        $t_result = xtc_db_query($t_sql);
414

    
415
        # init properties_values and group in properties
416
        while($t_row = xtc_db_fetch_array($t_result))
417
        {
418
            $t_properties_id = $t_row['properties_id'];
419
            $t_properties_values_id = $t_row['properties_values_id'];
420
            $this->v_properties_array[$t_properties_id]['properties_values'][$t_properties_values_id] = $t_row;          
421
            $this->v_properties_array[$t_properties_id]['properties_values'][$t_properties_values_id]['value_price_formatted'] = trim($coo_xtc_price->xtcFormat((double)$t_row['value_price'], true));
422
            $t_properties_values_ids_array[$t_properties_values_id] = $t_properties_id;
423
        }
424
        
425
        if(count($t_properties_values_ids_array) > 0)
426
        {
427
            $this->get_properties_values_names($t_properties_values_ids_array);   
428
            return $this->v_properties_array[$t_properties_id]['properties_values'][$t_properties_values_id];
429
        }
430
        else
431
        {
432
            return array();
433
        }
434
    }
435
    
436
    protected function get_properties_names()
437
    {        
438
        $t_sql = '
439
            SELECT
440
                properties_id,
441
                language_id,
442
                properties_name,
443
                properties_admin_name
444
            FROM
445
                properties_description AS pd
446
                LEFT JOIN languages AS lang ON (pd.language_id = lang.languages_id) 
447
            WHERE
448
                properties_id IN ('.implode(',', array_keys($this->v_properties_array)).')       
449
            ORDER BY
450
                lang.sort_order
451
        ';
452
        $t_result = xtc_db_query($t_sql);
453
		
454
		$languages_query = xtc_db_query("select languages_id, name, code, image, directory, status from ".TABLE_LANGUAGES." order by sort_order");
455
		while($languages = xtc_db_fetch_array($languages_query)) 
456
		{
457
			$t_languages_array[$languages['languages_id']] = array ('id' => $languages['languages_id'], 'name' => $languages['name'], 'code' => $languages['code'], 'image' => $languages['image'], 'directory' => $languages['directory'], 'status' => $languages['status']);
458
		}
459
        
460
        while($t_row = xtc_db_fetch_array($t_result))
461
        {
462
            $this->v_properties_array[$t_row['properties_id']]['properties_names'][$t_row['language_id']] = $t_languages_array[$t_row['language_id']];
463
            $this->v_properties_array[$t_row['properties_id']]['properties_names'][$t_row['language_id']]['properties_name'] = $t_row['properties_name'];
464
            $this->v_properties_array[$t_row['properties_id']]['properties_names'][$t_row['language_id']]['properties_admin_name'] = $t_row['properties_admin_name'];
465
        }        
466
    }
467
    
468
    protected function get_properties_values_names($p_properties_values_ids_array)
469
    {       
470
        $t_sql = '
471
            SELECT
472
                properties_values_id,
473
                language_id,
474
                values_name
475
            FROM
476
                properties_values_description AS pvd
477
                LEFT JOIN languages AS lang ON (pvd.language_id = lang.languages_id) 
478
            WHERE
479
                properties_values_id IN ('.implode(',', array_keys($p_properties_values_ids_array)).')         
480
            ORDER BY
481
                sort_order
482
        ';
483
        $t_result = xtc_db_query($t_sql);
484
        
485
        $languages_query = xtc_db_query("select languages_id, name, code, image, directory, status from ".TABLE_LANGUAGES." order by sort_order");
486
		while($languages = xtc_db_fetch_array($languages_query)) 
487
		{
488
			$t_languages_array[$languages['languages_id']] = array ('id' => $languages['languages_id'], 'name' => $languages['name'], 'code' => $languages['code'], 'image' => $languages['image'], 'directory' => $languages['directory'], 'status' => $languages['status']);
489
		}
490
        
491
        while($t_row = xtc_db_fetch_array($t_result))
492
        {
493
            $this->v_properties_array[$p_properties_values_ids_array[$t_row['properties_values_id']]]['properties_values'][$t_row['properties_values_id']]['values_names'][$t_row['language_id']] = $t_languages_array[$t_row['language_id']];
494
            $this->v_properties_array[$p_properties_values_ids_array[$t_row['properties_values_id']]]['properties_values'][$t_row['properties_values_id']]['values_names'][$t_row['language_id']]['values_name'] = $t_row['values_name'];
495
        }        
496
    }
497
}
    (1-1/1)