Observer.php
3.41 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
<?php
/**
* @package anc_image
* @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_Image_Model_Observer {
public function saveImageOrderLink(array $param_values) {
$order = $param_values->getOrder();
$customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
$ListQuoteItemsByQuoteId = Mage::helper('anc_lib/quoteitem')->getListQuoteItemsByQuoteId($order->getQuoteId());
foreach ($ListQuoteItemsByQuoteId as $ListQuoteItem) {
$ItemProductOptions = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionType($ListQuoteItem['item_id'], 'ancimage_type');
if (is_array($ItemProductOptions) && !empty($ItemProductOptions)) {
foreach ($ItemProductOptions as $option_id => $ncimage_id) {
if (!array_search($ncimage_id, $this->itemarray)) {
try {
D::s($this->itemarray, '$this->itemarray', 5, 1);
$this->itemarray[] = $ncimage_id;
$model = Mage::getModel('anc_image/ncimage');
$imageitem = $model->load($ncimage_id)->getData();
if ($imageitem['admin_user_id'] < 1) {
unset($imageitem['entity_id']);
unset($imageitem['ordered']);
unset($imageitem['admin_user_id']);
$imageitem['customer_id'] = $customerId;
// $imageitem['comment'] = $imageitem['comment'] . ' Kopie ' . $imageitem['entity_id'] ;
$model->setData($imageitem);
$model->save();
$var_own_image = true;
}
} catch (Exception $e) {
// D::show($e->getMessage());
}
}
if ($var_own_image) {
Mage::helper('anc_lib/sql')->updateOneCell(
'anc_image/ncimage', 'ordered', '1', array(
'entity_id' => $ncimage_id,
)
);
}
$ncimage_quoteitemoption_id = (int) Mage::helper('anc_lib/sql')->selectFetchOne(
'entity_id', 'anc_image/ncimage_quoteitemoption', array(
'customer_id' => $order->getCustomerId(),
'ncimage_id' => $ncimage_id,
'order_id' => $order->getId(),
'quote_item_id' => $ListQuoteItem['item_id'],
'ordertime' => $order->getCreatedAt()
)
);
if (!$ncimage_quoteitemoption_id) {
// $ncimage_quoteitemoption = Mage::getModel('anc_image/ncimage_quoteitemoption');
$ncimage_quoteitemoption = Mage::helper('anc_image/ncmodel')->getBlancoNcImageQuoteitemoption();
$ncimage_quoteitemoption->setCustomerId($order->getCustomerId());
$ncimage_quoteitemoption->setNcimageId($ncimage_id);
$ncimage_quoteitemoption->setOrderId($order->getId());
$ncimage_quoteitemoption->setQuoteItemId($ListQuoteItem['item_id']);
$ncimage_quoteitemoption->setOrdertime($order->getCreatedAt());
$ncimage_quoteitemoption->save();
}
}
}
}
}
}