# Attributbilder

**URL:** <https://forum.oxid-esales.com/t/attributbilder/44845>\
**Category:** Deutsches Forum\
**Tags:** feature-anfragen\
**Created:** [July 26, 2010, 12:10pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845 "2010-07-26T12:10:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 26, 2010, 12:10pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/1 "2010-07-26T12:10:59Z")

</div>

Hi zusammen,

wäre es nicht sinnvoll für die Attribute auch Bilder zu ermöglichen,  
die man dann zum Beispiel auch bei den Varianten als Auswahl verwenden könnte?

So müsste man nicht umständlich dort reines HTML reinpacken um zum Beispiel  
Qualitätszeichen anzuzeigen oder ob zum Beispiel ein Modeprodukt waschbar ist.

Außerdem wäre es auch sinnvoll, wenn man dann beim Zuordnen  
der Attribute zum Beispiel mit Haken auswählen könnte:

Anstatt Dropdownbox Attributbilder anzeigen oder sowas ähnliches.

Viele Grüße vom Chris

---

<div class="post-metadata">

**Author:** ![marco.steinhaeuser](https://forum.oxid-esales.com/user_avatar/forum.oxid-esales.com/marco.steinhaeuser/32/1832_2.png) [@marco.steinhaeuser](https://forum.oxid-esales.com/u/marco.steinhaeuser)\
**Post date:** [July 28, 2010, 3:21pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/2 "2010-07-28T15:21:20Z")

</div>

Hallo Chris,

versteh ich nicht: Du bist Dir sicher, dass Du Attributen Bilder geben willst? Wie soll das gehen? Bei Attributen reden wir doch von “Spezifikationen” der Artikel wie hier dargestellt:  
[http://demoshop.oxid-esales.com/community-edition/Geschenke/Wohnen/Uhren/Wanduhr-SPIDER.html](http://demoshop.oxid-esales.com/community-edition/Geschenke/Wohnen/Uhren/Wanduhr-SPIDER.html)

Gruß

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 29, 2010, 1:28pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/3 "2010-07-29T13:28:15Z")

</div>

Hi Marco,

die Rede ist genau von diesen Spezifikationen oder bleiben wir bei Attribute.  
Nehmen wir zum Beispiel das Attribut “Besondere Eigenschaften”, da wäre  
es dann ganz sinnvoll, wenn man anstatt Lycra oder meinetwegen “waschbar”,  
die entsprechenden Qualitätszeichen oder Waschzeichen als Bild einsetzen könnte.

Also kann es doch Sinn machen, Attributen Bilder zuzuweisen.

Viele Grüße vom Chris

---

<div class="post-metadata">

**Author:** ![roland76](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@roland76](https://forum.oxid-esales.com/u/roland76)\
**Post date:** [July 29, 2010, 3:23pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/4 "2010-07-29T15:23:09Z")

</div>

Teilweise würde ich eine solche Funktion ebenfalls sinnvoll finden. Quick & Dirty lösen könntest du dies, in dem du bei der Ausgabe der Spezifikationen die AttributID oder den Attributtitel überprüfst und falls dieser einen bestimmten Wert hast, gibst du eben nicht den Titel aus, sondern ein Bild. Kannst du im Template mit ein bisschen Smarty machen.  
Der andere Weg führt wohl über [oxid.uservoice.com](http://oxid.uservoice.com) oder über ein Modul, um das entsprechende Bild im Adminbereich hinterlegen zu können.

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 29, 2010, 6:58pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/5 "2010-07-29T18:58:23Z")

</div>

Mann kann auch ein JSON-Object als Wert reinschreiben…  
… und anschließend im Template wieder encodieren.

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 30, 2010, 11:40am UTC](https://forum.oxid-esales.com/t/attributbilder/44845/6 "2010-07-30T11:40:43Z")

</div>

Hi Markus,

das mit dem JSON Objekt hört sich super an. Hast Du mir vielleicht heir ein konkretes  
Beispiel, wie ich das so umsetzen könnte?

Ich bräuchte quasi Pflegehinweise mit Bildern. Eventuell  
erledige ich das wirklich über Smarty… Was ist den sauberer, bzw. schöner?

Vielen Dank und allerbeste Grüße vom Chris

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 30, 2010, 12:51pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/7 "2010-07-30T12:51:53Z")

</div>

Bitte Rückmelden, wenn es funktioniert.

./modules/json4details.php

```php

<?
class json4details extends json4details_parent{
	/**
	* change json-informations to stdObject for details template
	* sets (if exist) field with vector=value as std-oxid otherwise, the first value of json object
	* @author markus.bauer
	* @param void
	* @return array attributes
	*/
	public function getAttributes(){
		if ( $this->_aAttributes === null ) {
			// all attributes this article has
			$aArtAttributes = $this->getProduct()->getAttributes();
			//making a new array for backward compatibility
			$this->_aAttributes = array();
			if ( count( $aArtAttributes ) ) {
				foreach ( $aArtAttributes as $sKey => $oAttribute ) {
					$this->_aAttributes[$sKey] = new stdClass();
					$this->_aAttributes[$sKey]->title = $oAttribute->oxattribute__oxtitle->value;
					$oJson=json_decode(html_entity_decode($oAttribute->oxattribute__oxvalue->value));
					if(is_object($oJson)&&!$this->isAdmin()){
						if(isset($oJson->value)){//setDefault
							$this->_aAttributes[$sKey]->value=$oJson->value;
						}else{
							$this->_aAttributes[$sKey]->value=current($oJson);
						}
						$this->_aAttributes[$sKey]->json=$oJson;
					}else{//oxid default
						$this->_aAttributes[$sKey]->value = $oAttribute->oxattribute__oxvalue->value;
					}
				}
			}
		}
		return $this->_aAttributes;
	}
}

```

admin-\>grundeinstellungen-\>system-\>module

```auto

details => json4details

```

Beispiel für Attribut-Wert:

```auto

{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"}

```

(Testweise) details.tpl  
suchen:

```auto

<td id="test_attrValue_[{$smarty.foreach.attribute.iteration}]">[{ $oAttr->value }]</td>

```

ersetzen:

```auto

<td id="test_attrValue_[{$smarty.foreach.attribute.iteration}]">[{ $oAttr->value }][{if $oAttr->json}]<br />[{$oAttr->json|@print_r:1}][{/if}]</td>

```

---

<div class="post-metadata">

**Author:** ![avenger](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@avenger](https://forum.oxid-esales.com/u/avenger)\
**Post date:** [July 30, 2010, 1:30pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/8 "2010-07-30T13:30:40Z")

</div>

[QUOTE=MBa;36820]Mann kann auch ein JSON-Object als Wert reinschreiben…  
… und anschließend im Template wieder encodieren.[/QUOTE]  
Kann ich da nicht einfach einen “img”-Tag einbauen, und mir das Modul sparen?

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 30, 2010, 1:40pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/9 "2010-07-30T13:40:21Z")

</div>

Klar, mit ner Menge an Konventionen.  
ZB: Eine If abfrage, wenn der Wert=‘soundso’ ist, dann dieses Bild und bei ‘sounso2’ jenes Bild usw.  
Das ganze noch mehrsprachig. Und bei jeden neuen Bild das Template anpassen.  
Oder halt diese 32-Stellige ID nehmen, die so im Template nicht zur Verfügung steht.

…oder  
Bildname ist $value.‘jpg’. Natürlich das Ganze noch nach rfc1738 umwandeln.

Geht alles, mit JSON ist es dafür flexibler und leicht erweiterbar. Man kann sogar mit relativ wenig Aufwand youtube-videos oder so einbinden.

---

<div class="post-metadata">

**Author:** ![avenger](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/a/9de0a6/32.png) [@avenger](https://forum.oxid-esales.com/u/avenger)\
**Post date:** [July 30, 2010, 1:42pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/10 "2010-07-30T13:42:27Z")

</div>

[QUOTE=MBa;36865]Klar, mit ner Menge an Konventionen.  
ZB: Eine If abfrage, wenn der Wert=‘soundso’ ist, dann dieses Bild und bei ‘sounso2’ jenes Bild usw.  
Das ganze noch mehrsprachig. Und bei jeden neuen Bild das Template anpassen.  
Oder halt diese 32-Stellige ID nehmen, die so im Template nicht zur Verfügung steht.

…oder  
Bildname ist $value.‘jpg’. Natürlich das Ganze noch nach rfc1738 umwandeln.

Geht alles, mit JSON ist es dafür flexibler und leicht erweiterbar. Man kann sogar mit relativ wenig Aufwand youtube-videos oder so einbinden.[/QUOTE]  
Ich dachte eher daran, das “img” in den Attributwert zu speichern…

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 30, 2010, 1:55pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/11 "2010-07-30T13:55:33Z")

</div>

html\_entity\_decode ist weiterhin notwendig…  
… und finde json einfacher als bei jeden Eintrag zu überlegen, wie denn nun die HTML-Struktur sein muss… ggf. braucht das img eine bestimmte CSS-Klasse usw.

Wie auch immer, es gibt immer mehrere Lösungen.  
Ich ziehe was flexibles gerne vor.

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 30, 2010, 3:21pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/12 "2010-07-30T15:21:44Z")

</div>

Hi zusammen,

das hört sich schon mal wirklich prima an, das heißt, ich kann  
dann auch mehrere Bilder einem Attributwert zuordnen:

```php

[
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"},
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"}
]

```

Noch besser wärs allerdings noch, wenn man direkt das Attribut dem Artikel  
zuweisen könnte und nicht extra jedem Attribut auch einen Wert zuweisen müsste.

So hätte man nämlich beispielsweise folgende Auswahl:

- Artikel Waschbar bis 30 Grad + Pflegeleicht
- Artikel Waschbar bis 40 Grad

Es gibt ja keine Möglichkeit direkt bei der Attributerstellung Defaultwerte  
zuzuweisen oder hab ich da was übersehen?

Vielen Dank erstmal und schon mal ein schönes Wochenende wünscht Euch,

Chris

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 30, 2010, 4:46pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/13 "2010-07-30T16:46:59Z")

</div>

Okay, hab das Modul jetzt mal getestet. Jetzt stellt sich mir noch die Frage,  
wie ich das JSON Objekt wirklich in ein Bild umwandel kann. Derzeit  
erhalte ich noch folgende Ausgabe im Frontend:

```php

<td id="test_attrValue_1">normale Beschreibung (value ist default)stdClass Object
(
    [image] => path/to/image.jpg
    [value] => normale Beschreibung (value ist default)
)
</td>

```

Vielen Dank und allerbeste Grüße vom Chris

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 30, 2010, 4:52pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/14 "2010-07-30T16:52:38Z")

</div>

```auto

<img href="[{$oAttr->json->image}]" alt="[{$oAttr->json->value}]" />

```

Pfade natürlich relativ.

Falls das nicht mit Smarty geht:

```auto

[{assign var="oJson" value=$oAttr->json}]
<img href="[{$oJson->image}]" alt="[{$oJson->value}]" />

```

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [July 30, 2010, 5:09pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/15 "2010-07-30T17:09:23Z")

</div>

Hi Marcus,

dankeschön, das erstere Beispiel hat soweit wunderbar geklappt. Nur mehrere Bilder  
auf einmal frisst er mir nicht. Die JSON Syntax ist doch:

```php

[
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"},
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"}
]  

```

Oder liege ich da gänzlich falsch? Außerdem müsste dann ja noch jedes einzelne Objekt in ner Schleife durchlaufen werden, wenn ich das richtig sehe.

Allerbeste Grüße und Dankeschön vom Chris

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [July 30, 2010, 5:58pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/16 "2010-07-30T17:58:43Z")

</div>

[QUOTE=coarsy;36876]

```php

[
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"},
{"image":"path/to/image.jpg","value":"normale Beschreibung (value ist default)"}
]

```

[/QUOTE]

Versuche es mal so:

```auto

{"image":["path/to/image.jpg","path/to/image2.jpg""]}

```

und dann ab durch die Schleife.

Edit: Deine Version geht auch mit Schleife.

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [August 1, 2010, 10:41pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/17 "2010-08-01T22:41:27Z")

</div>

Hi Markus,

vielen Dank für Deine Hilfe, aber das hat so leider auch nicht geklappt.

{“image”:[“path/to/image.jpg”,“path/to/image2.jpg”"]}

Das wird im Klartext so ausgegeben. Bräuchte das Ganze schon als Bilderfolge  
mit Alttext, da ich diesen über Javascript Bubbles ausgeben möchte.

Beste Grüße vom Chris

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [August 1, 2010, 10:47pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/18 "2010-08-01T22:47:32Z")

</div>

Dann so wie Du das schon hattest.  
[http://www.oxid-esales.com/forum/showthread.php?t=6171&page=2#post36892](http://www.oxid-esales.com/forum/showthread.php?t=6171&page=2#post36892)

Muss halt ebenfalls durch eine Schleife.

---

<div class="post-metadata">

**Author:** ![coarsy2](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/c/848f3c/32.png) [@coarsy2](https://forum.oxid-esales.com/u/coarsy2)\
**Post date:** [August 2, 2010, 10:41am UTC](https://forum.oxid-esales.com/t/attributbilder/44845/19 "2010-08-02T10:41:05Z")

</div>

Hi und guten Morgen Markus,

geht leider nicht, denn das wird dann auch nicht mehr als JSON-Objekt erkannt und  
wird somit auch im Klartext ausgegeben.

Dankeschön und beste Grüße,

Chris

---

<div class="post-metadata">

**Author:** ![MBa](https://forum.oxid-esales.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@MBa](https://forum.oxid-esales.com/u/MBa)\
**Post date:** [August 2, 2010, 4:47pm UTC](https://forum.oxid-esales.com/t/attributbilder/44845/20 "2010-08-02T16:47:39Z")

</div>

[QUOTE=coarsy;37009]Hi und guten Morgen Markus,

geht leider nicht, denn das wird dann auch nicht mehr als JSON-Objekt erkannt und  
wird somit auch im Klartext ausgegeben.

Dankeschön und beste Grüße,

Chris[/QUOTE]

[http://www.functions-online.com/json\_decode.html](http://www.functions-online.com/json_decode.html)  
sagt, dass geht.

Versuche mal anstatt

```auto

$oJson=json_decode(html_entity_decode($oAttribute->oxattribute__oxvalue->value))

```

so etwas:

```auto

$oJson=json_decode(html_entity_decode($oAttribute->oxattribute__oxvalue->value),true)

```

… smarty macht gerne Probleme mit Objekten.

[Next page](https://forum.oxid-esales.com/t/attributbilder/44845.md?page=2)
