Skip to content

Commit fcc84b5

Browse files
committed
#1 resolving of eav attribute codes to names
1 parent 1da5ca9 commit fcc84b5

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

  • app/code/community/Firegento/AdminLogger

app/code/community/Firegento/AdminLogger/Block/Adminhtml/History/Grid.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public function showNewContent($newContent, Firegento_AdminLogger_Model_History
180180
}
181181
foreach ($showContent as $key => $value ) {
182182
if (array_key_exists($key, $newContent)) {
183-
$cell .= $this->formatCellContent($key, $newContent[$key]);
183+
$attributeName = Mage::helper('firegento_adminlogger')->getAttributeNameByTypeAndCode($row->getObjectType(), $key);
184+
$cell .= $this->formatCellContent($attributeName, $newContent[$key]);
184185
}
185186
}
186187
}
@@ -189,14 +190,20 @@ public function showNewContent($newContent, Firegento_AdminLogger_Model_History
189190
}
190191

191192

192-
public function showOldContent($oldContent) {
193+
/**
194+
* @param string $oldContent
195+
* @param Firegento_AdminLogger_Model_History $row
196+
* @return string
197+
*/
198+
public function showOldContent($oldContent, Firegento_AdminLogger_Model_History $row) {
193199
$cell = '';
194200
$oldContent = $this->decodeContent($oldContent);
195201

196202
if (is_array($oldContent)) {
197203
if (count($oldContent) > 0) {
198204
foreach ($oldContent as $key => $value ) {
199-
$cell .= $this->formatCellContent($key, $value);
205+
$attributeName = Mage::helper('firegento_adminlogger')->getAttributeNameByTypeAndCode($row->getObjectType(), $key);
206+
$cell .= $this->formatCellContent($attributeName, $value);
200207
}
201208
} else {
202209
return $this->__('not available');

app/code/community/Firegento/AdminLogger/Helper/Data.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,47 @@ class Firegento_AdminLogger_Helper_Data extends Mage_Core_Helper_Abstract
99
const ACTION_INSERT = 1;
1010
const ACTION_UPDATE = 2;
1111
const ACTION_DELETE = 3;
12+
13+
/**
14+
* returns attribute type by provided class name
15+
*
16+
* @param string $className
17+
* @return string|bool
18+
*/
19+
protected function getAttributeTypeByClassName($className){
20+
/** @var Mage_Eav_Model_Resource_Entity_Type_Collection $typesCollection */
21+
$typesCollection = Mage::getModel('eav/entity_type')->getCollection();
22+
foreach ($typesCollection->getItems() as $type){
23+
/** @var Mage_Eav_Model_Entity_Type $type */
24+
if ($type->getEntityModel() && Mage::getModel($type->getEntityModel()) instanceof $className){
25+
return $type->getEntityTypeCode();
26+
}
27+
}
28+
29+
return false;
30+
}
31+
32+
/**
33+
* returns attribute name by provided class name and attribute code
34+
*
35+
* @param string $className
36+
* @param string $attributeCode
37+
* @return string
38+
*/
39+
public function getAttributeNameByTypeAndCode($className, $attributeCode) {
40+
41+
$attributeName = $attributeCode;
42+
43+
$type = $this->getAttributeTypeByClassName($className);
44+
if ($type) {
45+
/** @var Mage_Eav_Model_Entity_Attribute $attribute */
46+
$attribute = Mage::getModel('eav/entity_attribute')->loadByCode($type, $attributeCode);
47+
if ($attribute->getFrontendLabel()){
48+
$attributeName = $attribute->getFrontendLabel();
49+
}
50+
}
51+
52+
return $attributeName;
53+
}
54+
1255
}

0 commit comments

Comments
 (0)