Hallo,
wenn ein Produkt mehrere Ausprägungen desselben Merkmals zugewiesen hat, ist die standardmäßige Merkmal-Ausgabe, die als String in der Produkteigenschaft "$this->objProduct->_attributesAsString" vorliegt, nicht ideal, da die Merkmalsbezeichnung in diesem Fall mehrfach ausgegeben wird.
Die Produkteigenschaft "$this->objProduct->_attributes" enthält zu diesem Zweck ein Array, aus dem sich jede beliebige Ausgabe individuell erzeugen lässt.
Der Aufbau des mehrdimensionalen Arrays sieht folgendermaßen aus:
- Code: Alles auswählen
Array
(
[25] => Array
(
[0] => Array
(
[attributeID] => 25
[attributeTitle] => Farbe
[valueID] => 39
[valueTitle] => Rot
)
[1] => Array
(
[attributeID] => 25
[attributeTitle] => Farbe
[valueID] => 40
[valueTitle] => Grün
)
[2] => Array
(
[attributeID] => 25
[attributeTitle] => Farbe
[valueID] => 41
[valueTitle] => Blau
)
)
[26] => Array
(
[0] => Array
(
[attributeID] => 26
[attributeTitle] => Form
[valueID] => 42
[valueTitle] => Rund
)
[1] => Array
(
[attributeID] => 26
[attributeTitle] => Form
[valueID] => 43
[valueTitle] => Eckig
)
)
)
Übereinstimmende Merkmale liegen hier bereits gruppiert vor, sodass sich Ihr gewünschtes Ergebnis damit z. B. folgendermaßen erreichen lässt:
- Code: Alles auswählen
<?php
foreach ($this->objProduct->_attributes as $arr_attributeValues) {
?>
<div class="group">
<?php
foreach ($arr_attributeValues as $k => $arr_attributeValue) {
if ($k === 0) {
?>
<h2><?php echo $arr_attributeValue['attributeTitle']; ?></h2>
<?php
}
?>
<p><?php echo $arr_attributeValue['valueTitle']; ?></p>
<?php
}
?>
</div>
<?php
}
?>
Das Code-Beispiel erzeugt die folgende Ausgabe:
<div class="group">
<h2>Farbe</h2>
<p>Rot</p>
<p>Grün</p>
<p>Blau</p>
</div>
<div class="group">
<h2>Form</h2>
<p>Rund</p>
<p>Eckig</p>
</div>