Product.php
4.7 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
<?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_Product extends Mage_Core_Helper_Abstract {
private $attributsets = array() ;
/**
* gibt den attributset name zurück
*
* @param int $param_id - attribute_set_id
* @return string
*/
public function getAttributeSetName($param_id) {
if(!array_key_exists($param_id, $this->attributsets)) {
$attribute_set_name = Mage::helper('anc_lib/sql')->selectFetchOne(
'attribute_set_name',
'eav_attribute_set',
array('attribute_set_id' => $param_id)
);
$this->attributsets[$param_id] = $attribute_set_name;
}
return $this->attributsets[$param_id];
}
/**
* gibt product model zurück und speichert es intern im CACHE
*
* @param int $param_id
* @return Mage_Catalog_Model_Product
*/
public function getProduct($param_id) {
if(!array_key_exists($param_id, $this->CACHE_products)) {
$this->CACHE_products[$param_id] = Mage::getModel("catalog/product");
$this->CACHE_products[$param_id]->load($param_id);
}
return $this->CACHE_products[$param_id];
}
private $CACHE_products = array();
/**
* gibt Product sku zurück
*
* @param int $param_id
* @return string
*/
public function getProductSku($param_id) {
$product = $this->getProduct($param_id);
return $product->getData('sku');
}
/**
* fnc setzt parameter für eine vorhandene individuelle option
* sie muss mit der sku eindeutig sein, und darf nur einmal in kombination $param_product_id, $param_option_sku vorkommen
* ansonsten gibts nen fehler!!!!!
*
*
* @param int $param_product_id
* @param string $param_option_sku
* @param string $param_max_characters=null - wenn null Wert wird nicht gesetzt
* @param string $param_file_extension=null - wenn null Wert wird nicht gesetzt
* @param int $param_image_size_x=null - wenn null Wert wird nicht gesetzt
* @param int $param_image_size_y=null - wenn null Wert wird nicht gesetzt
*/
public function setIndividuelOptionWithoutOptionID($param_product_id, $param_option_sku, $param_max_characters=NULL, $param_file_extension=NULL, $param_image_size_x=NULL, $param_image_size_y=NULL) {
if($param_product_id && $param_option_sku) {
$option_id = Mage::helper('anc_lib/sql')->selectFetchCol(
'option_id',
'catalog_product_option',
array(
'product_id' => $param_product_id,
'sku' => $param_option_sku
)
);
if(is_array($option_id) && count($option_id) && $option_id[0]) {
$where = array( 'option_id' => $option_id[0]);
if(!is_null($param_max_characters)) {
Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'max_characters', $param_max_characters, $where);
}
if(!is_null($param_file_extension)) {
Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'file_extension', $param_file_extension, $where);
}
if(!is_null($param_image_size_x)) {
Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'image_size_x', $param_image_size_x, $where);
}
if(!is_null($param_image_size_y)) {
Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'image_size_y', $param_image_size_y, $where);
}
} else {
if(is_array($option_id) && empty($option_id)) {
D::li('FEHLER: keine option_id gefunden $param_product_id('.$param_product_id.'), $param_option_sku('.$param_option_sku.')');
} else {
D::fe($option_id, 'FEHLER: ermittelte option_id ist nicht eindeutig $param_product_id('.$param_product_id.'), $param_option_sku('.$param_option_sku.')');
}
return false;
}
} else {
D::li('FEHLER: es müssen $param_product_id und $param_option_sku übergeben werden ');
return false;
}
}
}