Observer.php
3.58 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
<?php
/**
* @package anc_text
* @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_Text_Model_Observer {
private $itemarray = array();
public function saveTextOrderLink(array $param_values) {
// D::s('saveTextOrderLink',5,1);
$order = $param_values->getOrder();
$customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
$ListQuoteItemsByQuoteId = Mage::helper('anc_lib/quoteitem')->getListQuoteItemsByQuoteId($order->getQuoteId());
foreach ($ListQuoteItemsByQuoteId as $ListQuoteItem) {
// D::ulli('foreach',5,1);
$ItemProductOptions = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionType($ListQuoteItem['item_id'], 'anctext_type');
if (is_array($ItemProductOptions) && !empty($ItemProductOptions)) {
// D::ulli('if',5,1);
foreach ($ItemProductOptions as $option_id => $nctext_id) {
// D::ulli('if foreach'. $nctext_id,5,1);
/**
* Kopiere das Text- Item damit Der Benutzer es bearbeiten kann und das Oreginalitem nicht mehr verändert wird
*/
if (!array_search($nctext_id, $this->itemarray)) {
try {
D::s($this->itemarray,'$this->itemarray',5,1);
$this->itemarray[] = $nctext_id;
$model = Mage::getModel('anc_text/nctext');
$textitem = $model->load($nctext_id)->getData();
unset($textitem['entity_id']);
unset($textitem['ordered']);
unset($textitem['admin_user_id']);
$textitem['customer_id']= $customerId;
// $textitem['comment'] = $textitem['comment'] . ' Kopie von ' . $textitem['entity_id'] . ' ItemId: ' . $textitem['used_byitem_id'];
$model->setData($textitem);
$model->save();
} catch (Exception $e) {
// D::show($e->getMessage());
}
}
Mage::helper('anc_lib/sql')->updateOneCell(
'anc_text/nctext', 'ordered', '1', array(
'entity_id' => $nctext_id,
)
);
$nctext_quoteitemoption_id = (int) Mage::helper('anc_lib/sql')->selectFetchOne(
'entity_id', 'anc_text/nctext_quoteitemoption', array(
'customer_id' => $order->getCustomerId(),
'nctext_id' => $nctext_id,
'order_id' => $order->getId(),
'quote_item_id' => $ListQuoteItem['item_id'],
'ordertime' => $order->getCreatedAt()
)
);
if (!$nctext_quoteitemoption_id) {
// $nctext_quoteitemoption = Mage::getModel('anc_text/nctext_quoteitemoption');
$nctext_quoteitemoption = Mage::helper('anc_text/ncmodel')->getBlancoNcTextQuoteitemoption();
$nctext_quoteitemoption->setCustomerId($order->getCustomerId());
$nctext_quoteitemoption->setNctextId($nctext_id);
$nctext_quoteitemoption->setOrderId($order->getId());
$nctext_quoteitemoption->setQuoteItemId($ListQuoteItem['item_id']);
$nctext_quoteitemoption->setOrdertime($order->getCreatedAt());
$nctext_quoteitemoption->save();
}
}
}
}
}
}