Zum Inhalt springen

Commerce - Sortierung der Artikel Attribute fehlerhaft?

Erstellt am 3. Januar 2008 · 2 Antworten · letzte Antwort am 3. Juli 2008

Tags: Frage

osch249 ·

Hi,

ich habe ein Problem mit der angezeigten Sortierung der Artikel Attribute innerhalb von Commerce.

Beschreibung:

Im Backend habe ich jede Menge Produkte und Attribute erstellt.

Unter dem Reiter "Attribute auswählen" füge ich den Attributen jede Menge Objekte hinzu (Zeile "Produkt").

Soweit alles klar.

Aber schon auf dem Reiter "Attribute editieren" erhalte ich eine andere Sortierung der Attribute und erst recht in der Darstellung im Frontend.

Frage: Wo und wie kann ich die Sortierung der Darstellung der Attribute eines Produktes im Frontend steuern?

Ist das eher ein Bug oder ein Feature? 🙂

'Hoffe dass ich mein Problem klar genug beschrieben habe.

osch249 ·

Hi,

habe inzwischen selber herausgefunden, dass offenbar in der Tabelle "tx_commerce_products_attributes_mm" die Sortierungen für die Produkt-Attribute gespeichert werden.

Klappt soweit auch ganz gut, allerdings nicht für die Multiple-Select-Attribute, da ist das Feld "sorting" auf 0 gesetzt (deshalb wohl auch die fehlerhafte Anzeige).

Bei weiterer Recherche bin ich in der Datei "class.tx_commerce_dmhooks.php" innerhalb der Funktion "saveProductRelations" auf folgenden Code (Zeile 611) gestoßen:

// update all articles of this product

if (isset($fieldArray['attributesedit'])) {
if (!$ctList) $ctList = $this->belib->getAllCorrelationTypes();

$ffData = t3lib_div::xml2array($fieldArray['attributesedit']);
if (is_array($ffData['data']['sDEF']['lDEF'])) {

// get articles if they are not already there
if (!$articles) $articles = $this->belib->getArticlesOfProduct($pUid);

// update this product
$articleRelations = array();
$counter = 0;

foreach ($ffData['data']['sDEF']['lDEF'] as $ffDataItemKey => $ffDataItem) {
$counter++;
$attributeKey = $this->belib->getUidFromKey($ffDataItemKey, $keyData);
$attributeData = $this->belib->getAttributeData($attributeKey, 'has_valuelist,multiple');

// check if the attribute has more than one value, if that is true, we have to create a relation for each value
if ($attributeData['multiple'] == 1) {
// if we have a multiple valuelist we need to handle the attributes a little bit different
// first we delete all existing attributes

$GLOBALS['TYPO3_DB']->exec_DELETEquery(
'tx_commerce_products_attributes_mm', 'uid_local=' .$pUid .' AND uid_foreign=' .$attributeKey);

// now explode the data
$attributeValues = explode(',', $ffDataItem['vDEF']);
$attributeCount = count($attributeValues);

foreach ($attributeValues as $attributeValue) {
// The first time an attribute value is selected, TYPO3 returns them INCLUDING an empty value!
// This would cause an unnecessary entry in the database, so we have to filter this here.
if ($attributeCount > 1 && empty($attributeValue)) continue;

$updateData = $this->belib->getUpdateData($attributeData, $attributeValue, $pUid);
							$GLOBALS['TYPO3_DB']->exec_INSERTquery(
 'tx_commerce_products_attributes_mm',
 array_merge(
  array (
  'uid_local' => $pUid,
  'uid_foreign' => $attributeKey,
  'uid_correlationtype' => 4,
  ),
 $updateData[0]
 )
);
}
} else {
// update a simple valuelist and normal attributes as usual
$updateArrays = $this->belib->getUpdateData($attributeData, $ffDataItem['vDEF'], $pUid);
						$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
 'tx_commerce_products_attributes_mm',
 'uid_local=' .$pUid .' AND uid_foreign=' .$attributeKey,
 $updateArrays[0]
);
}

Könnte es sein, dass innerhalb der "exec_INSERTquery" das Einfügen der Sortierung fehlt?

Unterhalb finde ich nämlich diesen Code (Zeile 670):

// update articles
if (is_array($articles) && count($articles) > 0) {
foreach ($articles as $article)	{
if ($attributeData['multiple'] == 1) {
// if we have a multiple valuelist we need to handle the attributes a little bit different
// first we delete all existing attributes
								$GLOBALS['TYPO3_DB']->exec_DELETEquery(
'tx_commerce_articles_article_attributes_mm', 'uid_local=' .$article['uid'] .' AND uid_foreign=' .$attributeKey);

// now explode the data
$attributeValues = explode(',', $ffDataItem['vDEF']);
$attributeCount = 0;
foreach ($attributeValues as $attributeValue) {
if (empty($attributeValue)) continue;
$attributeCount++;

$updateData = $this->belib->getUpdateData($attributeData, $attributeValue, $pUid);

$GLOBALS['TYPO3_DB']->exec_INSERTquery(
'tx_commerce_articles_article_attributes_mm',
array_merge(
array (
 'uid_local' => $article['uid'],
 'uid_foreign' => $attributeKey,
 'uid_product' => $pUid,
 'sorting' => $counter
),
$updateData[1]
)
);
}

Kann mir jemand hier weiterhelfen?

Update: Eine Ergänzung/Präzisierung noch zum Verhalten: Lege ich die Liste der Attribute zum ersten Mal an, ist die Sortierung sowohl auf dem Reiter "Attribute editieren" als auch in der Datenbank korrekt. Erst wenn man erneut speichert, werden die Werte für die Multi-Select-Attribute mit "0" überschrieben...

osch249 ·

Wie von mir seinerzeit vermutet, lag es daran, dass innerhalb des obigen "exec_INSERTquery" das Einfügen der Sortierung fehlte (interne Zeile 46).

Die Speicherung erfolgt nach dieser Ergänzung einwandfrei.

Komisch das niemand sonst dieses Problem hatte, in der SVN-Version ist es nämlich auch noch so (fehlerhaft) implementiert.