Quoteitem.php
31.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<?php
/**
* @package anc_lib
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Lib_Helper_Quoteitem extends Mage_Core_Helper_Abstract {
/**
* clone das Product Item und gebe neue Item Id zurück
* (fnc geht rekursiv alle Unterprodukte durch)
*
* @attention Es werden keine serilisierten Zellen überprüft, ob hier alte ID's noch versteckt sind)
* (Ausnahme: anc_current_item_id,anc_current_parent_item_id)
*
* Achtung: es existiert ein observer <anclib_quoteitem_cloneproductitem/> um in externen tabellen die item ids zu aktualisieren
*
* @param int $param_itemId
* @param int $param_setNewParentId - setze die parent_item_id neu (für rekursion)
* @param type $param_quote - nehme einen anderen quote, als aktuellen
* @return int
*/
public function cloneProductItem($param_itemId, $param_setNewParentId = null, $param_quote = null, $param_addToDescriptionText='') {
if (is_null($param_quote)) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
} else {
$quote = $param_quote;
}
$item = Mage::getModel('sales/quote_item')->load($param_itemId);
$item_clone = clone $item;
$item_clone->setQuote($quote);
$clonemessage = '###cloned:### clone from ' . $param_itemId.' '.$param_addToDescriptionText;
if (!$item_clone->getDescription()) {
$item_clone->setDescription($clonemessage);
} else {
$item_clone->setDescription($item_clone->getDescription().$clonemessage);
}
$item_clone->save();
if (!is_null($param_setNewParentId)) {
Mage::helper('anc_lib/sql')->updateOneCell(
'sales/quote_item', 'parent_item_id', $param_setNewParentId, array('item_id' => $item_clone->getItemId())
);
}
$sub_item_Ids = Mage::helper('anc_lib/sql')->selectFetchCol('item_id', 'sales/quote_item', array('parent_item_id' => $param_itemId));
if (is_array($sub_item_Ids) && !empty($sub_item_Ids)) {
foreach ($sub_item_Ids as $sub_item_Id) {
$this->cloneProductItem($sub_item_Id, $item_clone->getItemId(), null, ' original_parent_item_id('.$param_itemId.')');
}
}
$this->copyProductItemOptionsTo($param_itemId, $item_clone->getItemId(), $param_setNewParentId);
{
$dispatchEventParam = array(
'original_item_id' => $param_itemId,
'clone_item_id' => $item_clone->getItemId(),
'clone_item_data' => $item_clone->getData(),
);
if($param_setNewParentId) {
$dispatchEventParam['clone_parent_item_id'] = $param_setNewParentId;
}
Mage::dispatchEvent('anclib_quoteitem_cloneproductitem', $dispatchEventParam);
}
return $item_clone->getItemId();
}
/**
* dupliziere stumpf alle sales/quote_item_option Eintraege
* in denen 'item_id' => $param_itemId und setze 'item_id' = $param_newItemId neu
*
*
*
* @param int $param_itemId
* @param int $param_newItemId
*/
private function copyProductItemOptionsTo($param_itemId, $param_newItemId, $param_newParent_item_id=null) {
if ($param_itemId && $param_newItemId) {
$item_option_rows = Mage::helper('anc_lib/sql')->selectFetchAll('sales/quote_item_option', array('item_id' => $param_itemId));
foreach ($item_option_rows as $row) {
unset($row['option_id']);
$row['item_id'] = $param_newItemId;
if($row['code'] === 'info_buyRequest') {
$unserialize = unserialize($row['value']);
// D::show(array($row, $unserialize), '$param_itemId('.$param_itemId.') $param_newItemId:'.$param_newItemId);
if(array_key_exists('anc_current_item_id', $unserialize) && $unserialize['anc_current_item_id']) {
$unserialize['anc_current_item_id'] = $param_newItemId;
}
if(array_key_exists('id', $unserialize) && $unserialize['id']) {
$unserialize['id'] = $param_newItemId;
}
if(array_key_exists('anc_current_parent_item_id', $unserialize) && $unserialize['anc_current_parent_item_id']) {
if(!is_null($param_newParent_item_id)) {
$unserialize['anc_current_parent_item_id'] = $param_newParent_item_id;
}
}
// D::show($unserialize, '$param_itemId('.$param_itemId.') $param_newItemId:'.$param_newItemId);
$row['value'] = serialize($unserialize);
}
Mage::helper('anc_lib/sql')->insertValuesIntoTable('sales/quote_item_option', $row);
}
}
}
/**
* Hilfsfunktion .. zeigt Unter Items die in der Datenbank verknuepft sind
*
* @param type $param_quoteid
* @param string $param_text - text der mit ausgegeben wird
*/
public function showSubItemIds($param_quoteid, $param_text = null) {
$subitems = Mage::helper('anc_lib/sql')->selectFetchCol(
'item_id', 'sales/quote_item', array('quote_id' => (int) $param_quoteid)
);
if (is_null($param_text)) {
$param_text = '$subitems from ' . $param_quoteid;
}
// D::show($subitems, $param_text);
}
/**
* Funktion vergleicht zwei items anhand der item_option code=bundle_selection_attributes und code=selection_id
*
* @param type $param_first_item_option_rows - derzeit muessen es die item_option reihen sein
* @param type $param_second_item_option_rows - @todo alternativ zu item_option_rows auch nur item id und sie werden beide nach geladen
* @return boolean
*/
public function compareTwoItems(array $param_first_item_option_rows, array $param_second_item_option_rows) {
if (!is_array($param_first_item_option_rows) && is_numeric($param_first_item_option_rows)) {
D::show($param_first_item_option_rows, 'lade item aus datenbank !!!! noch nicht unterstuetzt', 1);
$first_item_option_rows = array();
} else {
$first_item_option_rows = $param_first_item_option_rows;
}
if (!is_array($param_second_item_option_rows) && is_numeric($param_second_item_option_rows)) {
D::show($param_second_item_option_rows, 'lade item aus datenbank !!!! noch nicht unterstuetzt', 1);
$second_item_option_rows = array();
} else {
$second_item_option_rows = $param_second_item_option_rows;
}
$equal = false;
foreach ($first_item_option_rows as $first_item_option_row) {
// $first_equal = true;
if ($first_item_option_row['code'] == 'bundle_selection_attributes' || $first_item_option_row['code'] == 'selection_id'
) {
foreach ($second_item_option_rows as $second_item_option_row) {
if ($first_item_option_row['code'] == $second_item_option_row['code']) {
// D::compareFe($first_item_option_row, $second_item_option_row, '$first_item_option_row, $second_item_option_row');
if ($first_item_option_row['product_id'] == $second_item_option_row['product_id']) {
// D::ulli('equal product_id: '.$first_item_option_row['product_id']);
if ($first_item_option_row['code'] == $second_item_option_row['code']) {
$equal = true;
// $equal++;
// D::ulli('equal product_id: $equal('.$equal.') '.$first_item_option_row['code']);
} else {
$equal = false;
// D::ulli('break if('.$first_item_option_row['code'].' == '.$second_item_option_row['code'].') {' );
break 2;
}
} else {
$equal = false;
// D::ulli('break if('.$first_item_option_row['product_id'].' == '.$second_item_option_row['product_id'].') {' );
break 2;
}
}
}
}
}
// D::ulli('return '.$equal);
return $equal;
}
private $Cache = array();
public function getItem($param_itemId) {
if (!array_key_exists($param_itemId, $this->Cache) || is_object($this->Cache[$param_itemId])) {
$this->Cache[$param_itemId] = Mage::getModel("sales/quote_item");
$this->Cache[$param_itemId]->load($param_itemId);
}
return $this->Cache[$param_itemId];
}
private $ItemProducts = array();
/**
* gibt das (im Zweifel gecachte) Produkt des item wieder
*
* @param type $param_itemId
* @return type
*/
public function getItemProduct($param_itemId) {
if(!array_key_exists($param_itemId, $this->ItemProducts)) {
$quote_item_Data = $this->getItem($param_itemId)->getData();
$this->ItemProducts[$param_itemId] = Mage::getModel("catalog/product");
$this->ItemProducts[$param_itemId]->load($quote_item_Data['product_id']);
// $this->ItemProducts[$param_itemId]->loadWithOptions($quote_item_Data['product_id']);
//$this->ItemProducts[$param_itemId]->prepareCustomOptions();
//$current_product = Mage::registry('current_product');
}
return $this->ItemProducts[$param_itemId];
}
private $ItemProductBlancoSvgFiles = array();
/**
* gibt ein array der svg dateien zurück die als solche im Backend unter Bilder makiert wurden
*
* @param type $param_itemId
* @return array
*/
public function getItemProductBlancoSvgFiles ($param_itemId) {
if(!array_key_exists($param_itemId, $this->ItemProductBlancoSvgFiles)) {
$quote_item_product = $this->getItemProduct($param_itemId);
$product_data = $quote_item_product->getData();
$images= $product_data['media_gallery']['images'];
$max = $quote_item_product->getAncprintpages();
for($i=0; $i<$max ;$i++) {
$fncname = Mage::helper('anc_lib/data')->getAncsvgpageFunctionName($quote_item_product->getId(), $i);
foreach($images as $j => &$image) {
if($images[$j]['file'] == $quote_item_product->$fncname()) {
$this->ItemProductBlancoSvgFiles[$param_itemId][$i] = $images[$j];
unset($images[$j]);
}
}
}
}
return $this->ItemProductBlancoSvgFiles[$param_itemId];
}
public function getItemProductLoadedForOptionBySubProductId($param_quote_item_id) {
$quote_item_product = $this->getItemProduct($param_quote_item_id);
$info_buyRequest = Mage::helper('anc_lib/sql')->selectFetchOne(
'value', 'sales/quote_item_option', array(
'item_id' => $param_quote_item_id,
'product_id' => $quote_item_product->getId(),
'code' => 'info_buyRequest',
)
);
$buyRequest = new Varien_Object(unserialize($info_buyRequest));
/**
* achtung folgender aufruf kann zu problemen führen bei dateiuploads
* und zwar in den tiefen von @see Mage_Catalog_Model_Product_Type_Abstract::prepareForCartAdvanced
* konkret @see Mage_Catalog_Model_Product_Type_Abstract::processFileQueue
*/
Mage::helper('catalog/product')->prepareProductOptions($quote_item_product, $buyRequest);
return $quote_item_product;
}
/**
* fnc gibt die im Frontend eingestellten individuellen optionen zurück für $param_quote_item_id
* Achtung: direkter zugriff (nur für Eingabetyp: Text, Datei, Datum)
*
* Alternativen siehe auch
* @see getItemProductOptionByOptionTypeValueSku
* @see getItemProductOptionByOptionSku
* @see getItemProductOptionByOptionId
* @see getItemProductOptionIdByOptionSku
*
* @param type $param_quote_item_id
* @param type $param_product_option_sku sql: catalog_product_option.sku
* @return type
*/
public function getItemProductOptionByOptionSku($param_quote_item_id, $param_product_option_sku) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
if (is_object($quote_item_product)) {
$catalog_product_option_id = (int) Mage::helper('anc_lib/sql')->selectFetchOne(
'option_id', 'catalog/product_option', array('sku' => $param_product_option_sku, 'product_id' => $quote_item_product->getId())
);
if ($catalog_product_option_id !== null && $catalog_product_option_id !== false) {
$code = 'options/' . $catalog_product_option_id;
$info = $quote_item_product->getPreconfiguredValues()->getData($code);
return $info;
}
}
return false;
}
/**
* setzt eine einfache option (direkter zugriff analog zu @see getItemProductOptionByOptionSku )
* @attention heikle opertation wie alle fnc hier, weil magento weg umgangen wird und die item option direkt geupdatet wird
* ohne umständliche magento kopiere item routine
*
* (@see http://magento.stackexchange.com/questions/4074/how-to-update-product-custom-options-on-cart-page)
*
* @since 20140910
*
* @param type $param_quote_item_id
* @param type $param_product_option_sku
* @param type $param_value
* @return boolean
*/
public function setItemProductOptionByOptionSku($param_quote_item_id, $param_product_option_sku, $param_value) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
$quote_item = $this->getItem($param_quote_item_id);
if (is_object($quote_item_product)) {
$catalog_product_option_id = (int) Mage::helper('anc_lib/sql')->selectFetchOne(
'option_id',
'catalog/product_option',
array('sku' => $param_product_option_sku, 'product_id' => $quote_item_product->getId())
);
if ($catalog_product_option_id !== null && $catalog_product_option_id !== false) {
$item_option_rows = Mage::helper('anc_lib/sql')->selectFetchAll('sales/quote_item_option', array('item_id' => $param_quote_item_id));
foreach ($item_option_rows as $row) {
$update_value =false;
if(strtolower($row['code']) == 'info_buyrequest') {
$unserialized = unserialize($row['value']);
$unserialized['options'][$catalog_product_option_id] = $param_value;
$update_value = serialize($unserialized);
} else if($row['code'] == "option_".$catalog_product_option_id) {
$update_value = $param_value;
}
if($update_value) {
Mage::helper('anc_lib/sql')->updateOneCell(
'sales/quote_item_option',
'value',
$update_value,
array('option_id' => $row['option_id'])
);
}
}
return true;
}
}
return false;
}
/**
*
* @param type $param_quote_item_id
* @param type $param_product_option_sku
* @return boolean
*
* /**
* fnc gibt die im Frontend eingestellten individuelle optionsId (Int) zurück für $param_quote_item_id
* Achtung: direkter zugriff (nur für Eingabetyp: Text, Datei, Datum)
*
* Alternativen siehe auch
* @see getItemProductOptionByOptionTypeValueSku
* @see getItemProductOptionByOptionSku
* @see getItemProductOptionByOptionId
* @getItemProductOptionIdByOptionSku
*
*/
public function getItemProductOptionIdByOptionSku($param_quote_item_id, $param_product_option_sku) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
if (is_object($quote_item_product)) {
$catalog_product_option_id = (int) Mage::helper('anc_lib/sql')->selectFetchOne(
'option_id', 'catalog/product_option', array('sku' => $param_product_option_sku, 'product_id' => $quote_item_product->getId())
);
if ($catalog_product_option_id !== null && $catalog_product_option_id !== false) {
return $catalog_product_option_id;
}
}
return false;
}
/**
*
*
* @param type $param_quote_item_id
* @param type $param_product_option_type
* @return false | array(catalog_product_option_id => value)
*/
public function getItemProductOptionByOptionType($param_quote_item_id, $param_product_option_type) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
if (is_object($quote_item_product)) {
$catalog_product_option_ids = Mage::helper('anc_lib/sql')->selectFetchCol(
'option_id', 'catalog/product_option', array('type' => $param_product_option_type, 'product_id' => $quote_item_product->getId())
);
if(is_array($catalog_product_option_ids) && !empty($catalog_product_option_ids)) {
// D::fe($catalog_product_option_ids, '$catalog_product_option_ids');
$info = array();
foreach($catalog_product_option_ids as $catalog_product_option_id) {
if ($catalog_product_option_id !== null && $catalog_product_option_id !== false) {
$code = 'options/' . (int)$catalog_product_option_id;
$value = $quote_item_product->getPreconfiguredValues()->getData($code);
if($value) {
$info[(int)$catalog_product_option_id] = $value;
}
// $info[$code] = $quote_item_product->getPreconfiguredValues()->getData($code);
// return $info;
}
}
} else {
return false;
}
}
return $info;
}
/**
* fnc gibt die im Frontend eingestellten individuellen optionen zurück für $param_quote_item_id
* Achtung: indirekter Zugriff
* 1. diese funktion ist für Eingabetyp: Auswählen; also dropdown, radiobuttons, checkbox, mehrfach auswahl
* 2. es kann mehrfache Ergebnisse geben, da die sku in mehreren auswahl feldern vorhanden sein kann
*
* Alternativen siehe auch
* @see getItemProductOptionByOptionTypeValueSku
* @see getItemProductOptionByOptionSku
* @see getItemProductOptionByOptionId
* @see getItemProductOptionIdByOptionSku
*
* @param type $param_quote_item_id
* @param type $param_product_option_type_sku sql: catalog_product_option_type_value.sku
* @return array|FALSE
*/
public function getItemProductOptionByOptionTypeValueSku($param_quote_item_id, $param_product_option_type_sku) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
if (is_object($quote_item_product)) {
$PreconfiguredValues = $quote_item_product->getPreconfiguredValues();
$Options = $PreconfiguredValues->getOptions();
if (!empty($Options)) {
$return = array();
foreach ($Options as $option_id => $values) {
$option_type_id = Mage::helper('anc_lib/sql')->selectFetchOne(
'option_type_id', 'catalog_product_option_type_value', array(
'option_id' => $option_id,
'sku' => $param_product_option_type_sku,
)
);
if (is_array($values) && array_search($option_type_id, $values) !== false) {
$return[] = array(
'option_type_id' => $option_type_id,
'option_id' => $option_id,
'sku' => $param_product_option_type_sku,
);
} else if ($option_type_id == $values) {
$return[] = array(
'option_type_id' => $option_type_id,
'option_id' => $option_id,
'sku' => $param_product_option_type_sku,
);
}
}
if (empty($return)) {
return false;
} else {
return $return;
}
} else {
return false;
}
}
}
/**
*
* Alternativen siehe auch
* @see getItemProductOptionByOptionTypeValueSku
* @see getItemProductOptionByOptionSku
* @see getItemProductOptionByOptionId
* @see getItemProductOptionIdByOptionSku
*
* @param type $param_quote_item_id
* @param type $param_product_option_id = sql: catalog_product_option.option_id
* @return type
*/
public function getItemProductOptionByOptionId($param_quote_item_id, $param_product_option_id) {
$quote_item_product = $this->getItemProductLoadedForOptionBySubProductId($param_quote_item_id);
if (is_object($quote_item_product)) {
$code = 'options/' . $param_product_option_id;
$info = $quote_item_product->getPreconfiguredValues()->getData($code);
return $info;
}
}
public function getLastQuoteItem(Mage_Sales_Model_Quote $quote) {
// Mage_Sales_Model_Quote
$quote = Mage::getSingleton('checkout/session')->getQuote();
//D::s($quote, '$quote',5,1,1) ;
$collection_lastItemId = Mage::getModel('sales/quote_item')->getCollection();
$sql = $collection_lastItemId->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('max(item_id) as last_item_id')
->where("quote_id = " . $quote->getEntityId());
//D::li(get_class($quote).' ++ '.$quote. ' $sql:'.$sql,1,1) ;
$lastItemId = $collection_lastItemId->getData();
$parent_item_id = Mage::helper('anc_lib/sql')->selectFetchOne(
'parent_item_id', 'sales/quote_item', array('item_id' => $lastItemId[0]['last_item_id'])
);
if ($parent_item_id) {
D::li('$maxItemId: ' . $lastItemId[0]['last_item_id'] . ' -->> ' . $parent_item_id, 1);
return $parent_item_id;
} else {
return $lastItemId[0]['last_item_id'];
}
}
public function getPriceWithTax(Mage_Sales_Model_Quote_Item $param_item) {
$_incl = $param_item->getPriceInclTax();
return $_incl;
}
public function getPreparedPriceForDisplayWithTax(Mage_Sales_Model_Quote_Item $param_item, $param_praefix = '', $param_showNotFree = false) {
$_incl = $this->getPriceWithTax($param_item);
if (round($_incl, 2) || (!$param_showNotFree)) {
// return '<div class="anc-price">'.$param_praefix.round($_incl, 2).' €</div>';
return $this->getPriceView($_incl, $param_praefix);
}
}
public function getPriceView($param_price = 0, $param_praefix = '') {
return '<div class="anc-price">' . $param_praefix . sprintf("%.2f",round($param_price, 2)) . ' €</div>';
}
public function getListQuoteItemsByQuoteId($param_quote_id) {
$ary_quoteItems = Mage::helper('anc_lib/sql')->selectFetchAll(
'sales_flat_quote_item', array('quote_id' => (int) $param_quote_id)
);
return $ary_quoteItems;
}
public function getQuoteIdByQuoteItem($param_quote_item_id) {
$quote_id = Mage::helper('anc_lib/sql')->selectFetchCol(
'quote_id', 'sales_flat_quote_item', array('item_id' => (int) $param_quote_item_id)
);
return $quote_id['0'];
}
/**
* @snPerformance ... alte fnc ist weiter unten - kannst du wenn nicht mehr benötigt löschen getAllQuoteOpionsSelected_old
*
* @todo -- irgendwann wenn wir mal aufräumen, muss diese fnc hier raus, weil sie ancprintconfigproduct abhängig ist
*
* @param type $p_quote_id
* @return type
*/
private $ItemQuote = array();
public function getAllQuoteOpionsSelected_old20140303($p_quote_id) {
$StartTime = time();
$ary_productswithOptions = Mage::helper('anc_printconfigproduct/constant')->get('searchSPProductsforCustomOptions');
$ary_caloptionskus = array();
$ary_caloptionskus[0] = Mage::helper('anc_printconfigproduct/constant')->get('ancSPCalendarCustomOptions');
$ary_caloptionskus[1] = Mage::helper('anc_printconfigproduct/constant')->get('ancSPQrcodeCustomOptions');
$subproductarray = Mage::helper('anc_lib/quoteitem')->getListQuoteItemsByQuoteId($p_quote_id);
// D::s($subproductarray,'$lllll',5,1);
$ary_allOptions = array();
if(empty($this->ItemQuote)){
foreach ($subproductarray as $k => $v) {
foreach ($ary_productswithOptions as $productkey => $prouctvalue) {
if (strpos($v['sku'], $prouctvalue) !== FALSE && $v['parent_item_id'] != 0) {
$ary_allOptions[$productkey][$v['product_id']]['item_id']=$v['item_id'];
$ary_allOptions[$productkey]['item_id']=$v['item_id'];
for ($i = 0; $i < 2; $i++) {
foreach($ary_caloptionskus[$i] as $fnc => $ary_caloptionskus_values) {
foreach ($ary_caloptionskus_values as $calk => $calv) {
if($fnc==='getItemProductOptionByOptionSku') {
$value = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($v['item_id'], $calv);
if($calv === 'anc_calendar_start_month'){
if($value){
// D::ulli('+++anc_printconfigproduct '.$value);
Mage::helper('anc_printconfigproduct/xml')->setStartMonth($value);
}
}
if($calv === 'anc_calendar_start_year'){
if($value){
// D::ulli('+++anc_printconfigproduct '.$value);
Mage::helper('anc_printconfigproduct/xml')->setStartYear($value);
}
}
} else if($fnc==='getItemProductOptionByOptionTypeValueSku') {
$ary_val = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionTypeValueSku($v['item_id'], $calv);
$value = $ary_val[0];
}
if ($value) {
$ary_allOptions[$calk] = $value;
}
}
}
}
}
}
}
}else{
$ary_allOptions =$this->ItemQuote;
}
$zeit = getdate(time() - $StartTime);
D::ulli($zeit["minutes"].'m'.$zeit["seconds"].'s: getAllQuoteOpionsSelected# '.$p_quote_id);
return $ary_allOptions;
}
private $AllQuoteOpionsSelected = array();
public function getAllQuoteOpionsSelected($p_quote_id) {
if(!array_key_exists($p_quote_id, $this->AllQuoteOpionsSelected)) {
$StartTime = time();
$ary_productswithOptions = Mage::helper('anc_printconfigproduct/constant')->get('searchSPProductsforCustomOptions');
$ary_caloptionskus = array();
$ary_caloptionskus[0] = Mage::helper('anc_printconfigproduct/constant')->get('ancSPCalendarCustomOptions');
$ary_caloptionskus[1] = Mage::helper('anc_printconfigproduct/constant')->get('ancSPQrcodeCustomOptions');
$subproductarray = Mage::helper('anc_lib/quoteitem')->getListQuoteItemsByQuoteId($p_quote_id);
$ary_allOptions = array();
foreach ($subproductarray as $k => $v) {
foreach ($ary_productswithOptions as $productkey => $prouctvalue) {
if (strpos($v['sku'], $prouctvalue) !== FALSE && $v['parent_item_id'] != 0) {
$ary_allOptions[$productkey][$v['product_id']]['item_id']=$v['item_id'];
$ary_allOptions[$productkey]['item_id']=$v['item_id'];
for ($i = 0; $i < 2; $i++) {
foreach($ary_caloptionskus[$i] as $fnc => $ary_caloptionskus_values) {
foreach ($ary_caloptionskus_values as $calk => $calv) {
if($fnc==='getItemProductOptionByOptionSku') {
$value = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($v['item_id'], $calv);
if($calv === 'anc_calendar_start_month'){
if($value){
// D::ulli('+++anc_printconfigproduct '.$value);
Mage::helper('anc_printconfigproduct/xml')->setStartMonth($value);
}
}
if($calv === 'anc_calendar_start_year'){
if($value){
// D::ulli('+++anc_printconfigproduct '.$value);
Mage::helper('anc_printconfigproduct/xml')->setStartYear($value);
}
}
} else if($fnc==='getItemProductOptionByOptionTypeValueSku') {
$ary_val = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionTypeValueSku($v['item_id'], $calv);
$value = $ary_val[0];
}
if ($value) {
$ary_allOptions[$calk] = $value;
}
}
}
}
}
}
}
$this->AllQuoteOpionsSelected[$p_quote_id] = $ary_allOptions;
$zeit = getdate(time() - $StartTime);
D::ulli($zeit["minutes"].'m'.$zeit["seconds"].'s: getAllQuoteOpionsSelected# '.$p_quote_id);
}
return $this->AllQuoteOpionsSelected[$p_quote_id];
}
/**
* nicht fertig ... und es ist die frage ob diese funktion irgendwann mal fertig wird @since 20140816
*
* das setzen einer individuellen Option (custom option)
* siehe setItemProductOptionByOptionSku
*/
// public function setCustomerOptionOnItem() {
//$ItemInfos = Mage::helper('anc_lib/data')->getCheckoutCartItemInfos();
//
//
//$Mage_Sales_Model_Quote_Item_Option = Mage::getModel('sales/quote_item_option');
//
//D::show($Mage_Sales_Model_Quote_Item_Option, '$Mage_Sales_Model_Quote_Item_Option',1,1);
////$ItemInfos['item']->addOption($Mage_Sales_Model_Quote_Item_Option);
// }
/**
*
* @param type $param_product_id
* @return type
*/
public function getProductOptionCollection($param_product_id) {
$options = Mage::getModel('catalog/product_option')
->getCollection()
->addTitleToResult(Mage::app()->getStore()->getId())
->addPriceToResult(Mage::app()->getStore()->getId())
->addProductToFilter($param_product_id)
->addValuesToResult();
return $options;
}
}
?>