Wenn man Varianten mit vielen Attributen vergleicht, die nur in einigen wenigen Punkten von den Parentartikeln abweichen, ist die Vergleichsliste ziemlich leer… (Siehe Grafik im Anhang.)
Es werden zwar alle möglichen Attribute in der Liste aufgeführt, bei den Artikeln werden aber dann nur die Artikelattribute angezeigt, die Information der Parentartikel aber nicht…
[QUOTE=Hebsacker;82107]Du meinst, dass die Attribute des Parentartikels quasi nicht an die Vergleichsliste vererbt werden?
In der Variante sind sie aber vorhanden (vererbt)?[/QUOTE]Ja, so ist es…
Ich denke, das Problem ist, dass wirklich nur die Artikelattribute verwendet werden.
Wenn ich “Vaterartikel” vergleiche, dann sind dessen “Artikelattribute” natürlich vorhanden.
Beim Vergleich von Artikeln, die von einem Vaterartikel abgeleitet sind, werden nur deren direkt zugeordnete "Artikelattribute"verwendet.
Ich habe das jetzt erweitert, so dass auch in diesem Fall die Attribute des “Vaterartikels” mit in den Vergleich aufgenommen werden…
Und sortiert werden die Attribute jetzt auch alphabetisch…
Die gleiche Liste wie im Bild des ersten Posts sieht dann so aus wie im Anhang…
So gefällt mir das jetzt wesentlich besser.
Und da ich gerade dabei war, habe ich noch ein paar andere Verbesserungen eingebaut:
[ul]
[li]Das Hinzufügen und Entfernen von Artikeln zur Vergleichsliste erfolgt jetzt per AJAX, d.h. man kann dann in der Artikelliste schön weiterarbeiten (Artikel hinzufügen oder entfernen), ohne erst mal wieder neu positionieren zu müssen.[/li][li]Im erweiterten “Mein Konto” Menü kann man jetzt [B]alle(!) [/B]Artikel in der aktuellen Artikelliste auf einmal in die Vergleichsliste aufnehmen.[/li][li]Im erweiterten “Mein Konto” Menü kann man jetzt [B]alle(!) [/B]Artikel in der Vergleichsliste auf einmal entfernen.[/li][/ul]
[QUOTE=Hebsacker;82114]Schick! Mündet das in ein Modul?[/QUOTE]
Die Aufbereitung der Attributliste habe ich als Modul implementiert.
Die anderen Funktionen verteilen sich über mehrere Template-Dateien und Module, und basiert auf unserer Template-Struktur.
Das ist mir jetzt zu schwierig :D.
Folgenden Code in “[B]modules/powertemplate/pt_compare/pt_compare.php[/B]” speichern:
In der Moduldefinition “[B]compare=>powertemplate/pt_compare/pt_compare[/B]” eintragen.
<?php
/**
* This file is part of OXID eShop Community Edition.
*
* OXID eShop Community Edition 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.
*
* OXID eShop Community Edition 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 OXID eShop Community Edition. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.oxid-esales.com
* @package views
* @copyright (C) OXID eSales AG 2003-2011
* @version OXID eShop CE
* @version SVN: $Id: compare.php 29553 2010-08-27 14:48:10Z sarunas $
*
* @copyright (C) Avenger, [email protected]
* Allow inclusion of parent articles' attributes and alphabetically sorting attributes by name
*/
class pt_compare extends pt_compare_parent
{
public function getAttributeList($bLoadParentAttributes=true, $bSortByName=true)
{
if ($this->_oAttributeList===null)
{
$aArtAttributes=false;
if ($oArtList = $this->getCompArtList())
{
$oAttributeList = oxNew( 'oxattributelist' );
$aArticleIds=array_keys($oArtList);
$aArtAttributes= $oAttributeList->loadAttributesByIds($aArticleIds);
if ($bLoadParentAttributes)
{
//Load also parent's attributes (if any)
$aParentArtKeys=$aParent2ArticleIds=array();
//Get oxids of parents of articles in list and map parent ids to articles ids
foreach ($oArtList as $key=>$oArticle)
{
$sParentId=$oArticle->oxarticles__oxparentid->value;
if ($sParentId)
{
$aParent2ArticleIds[$sParentId]=$oArticle->oxarticles__oxid->value;
$aParentArtKeys[]=$sParentId;
}
}
if (count($aParentArtKeys))
{
//Build mapping structure for attribute ids to attribute names
$aAttributesKey2Title=array();
foreach ($aArtAttributes as $sKey => $oAttribute)
{
$sTitle=trim($oAttribute->title);
$aAttributesKey2Title[$sKey]=$sTitle;
}
//Load all parent articles attributes
$aParentArtAttributes= $oAttributeList->loadAttributesByIds( $aParentArtKeys );
//Merge both lists (article attributes and parent attributes)
foreach ( $aParentArtAttributes as $sParentKey => $oParentAttribute )
{
$sParentTitle=trim($oParentAttribute->title);
//Find parent title in article attributes title
$sAttrKey=array_search($sParentTitle,$aAttributesKey2Title);
if (!$sAttrKey)
{
$sAttrKey = $sParentKey;
$oAttribute = new stdClass();
$oAttribute->title = $sParentTitle;
$oAttribute->aprod = array();
$aArtAttributes[$sAttrKey] = $oAttribute;
$aAttributesKey2Title[$sAttrKey] = $sParentTitle;
}
$aProd=$oParentAttribute->aProd;
if (count($aProd))
{
foreach ($aProd as $sParentKey => $oValue)
{
//Get id of article which has this parent article as parent
$sKey=$aParent2ArticleIds[$sParentKey];
if ($sKey)
{
$aArtAttributesEntry=$aArtAttributes[$sAttrKey]->aProd;
if (is_array($aArtAttributesEntry) && !in_array($sKey,$aArtAttributesEntry))
{
$aArtAttributes[$sAttrKey]->aProd[$sKey]=$oValue;
}
}
}
}
}
}
}
}
if ($bSortByName)
{
if (count($aArtAttributes))
{
//Sort attributes by attribute's name
if (!is_array($aAttributesKey2Title))
{
//Build data for sorting, if not already available
$aAttributesKey2Title=array();
foreach ( $aArtAttributes as $sKey => $aAttribute )
{
$sTitle=$aAttribute->title;
$aAttributesKey2Title[$sKey]=$sTitle;
}
}
asort($aAttributesKey2Title);
$this->_oAttributeList=array();
foreach ($aAttributesKey2Title as $key=>$value)
{
$this->_oAttributeList[]=$aArtAttributes[$key];
}
}
}
else
{
$this->_oAttributeList=$aArtAttributes;
}
}
if ($bLoadParentAttributes)
{
//Clean up attributes list from empty attributes
foreach ($this->_oAttributeList as $sAttrKey => $oAttribute)
{
if (count($oAttribute->aProd)==0)
{
//No articles allocated to attribute, so remove attribute from list
unset($this->_oAttributeList[$sAttrKey]);
}
}
}
return $this->_oAttributeList;
}
}
[QUOTE=avenger;82151]Folgenden Code in “[B]modules/powertemplate/pt_compare/pt_compare.php[/B]” speichern:
In der Moduldefinition “[B]compare=>powertemplate/pt_compare/pt_compare[/B]” eintragen.[/QUOTE]Ich habe das noch mal überarbeitet, weil die erste Version nicht berücksichtigt hat, dass in der Artikelliste ja durchaus mehrere Artikel vom selben Vater erben können…
<?php
/**
* This file is part of OXID eShop Community Edition.
*
* OXID eShop Community Edition 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.
*
* OXID eShop Community Edition 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 OXID eShop Community Edition. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.oxid-esales.com
* @package views
* @copyright (C) OXID eSales AG 2003-2011
* @version OXID eShop CE
* @version SVN: $Id: compare.php 29553 2010-08-27 14:48:10Z sarunas $
*
* @copyright (C) Avenger, [email protected]
* Allow inclusion of parent articles' attributes and alphabetically sorting attributes by name
*/
class pt_compare extends pt_compare_parent
{
public function getAttributeList($bLoadParentAttributes=true, $bSortByName=true)
{
if ($this->_oAttributeList===null)
{
$aArtAttributes=false;
if ($oArtList = $this->getCompArtList())
{
$oAttributeList = oxNew('oxattributelist');
$aArticleIds=array_keys($oArtList);
$aArtAttributes= $oAttributeList->loadAttributesByIds($aArticleIds);
if ($bLoadParentAttributes)
{
//Load also parent's attributes (if any)
$aParentArtKeys=$aParent2ArticleIds=array();
//Get oxids of parents of articles in list and map parent ids to articles ids
foreach ($oArtList as $key=>$oArticle)
{
$sParentId=$oArticle->oxarticles__oxparentid->value;
if ($sParentId)
{
//Wee need to make sure, that multiple articles inheriting from the same parent are properly handled!
//So we have to store an array of article numbers.
if (isset($aParent2ArticleIds[$sParentId]))
{
debugbreak();
}
else
{
$aParent2ArticleIds[$sParentId]=array();
}
$aParent2ArticleIds[$sParentId][]=$oArticle->oxarticles__oxid->value;
$aParentArtKeys[]=$sParentId;
}
}
if (count($aParentArtKeys))
{
//Build mapping structure for attribute ids to attribute names
$aAttributesKey2Title=array();
foreach ($aArtAttributes as $sKey => $oAttribute)
{
$sTitle=trim($oAttribute->title);
$aAttributesKey2Title[$sKey]=$sTitle;
}
//Load all parent articles attributes
$aParentArtAttributes= $oAttributeList->loadAttributesByIds($aParentArtKeys);
//Merge both lists (article attributes and parent attributes)
foreach ($aParentArtAttributes as $sParentKey => $oParentAttribute)
{
$sParentTitle=trim($oParentAttribute->title);
//Find parent title in article attributes title
$sAttrKey=array_search($sParentTitle,$aAttributesKey2Title);
if (!$sAttrKey)
{
$sAttrKey = $sParentKey;
$oAttribute = new stdClass();
$oAttribute->title = $sParentTitle;
$oAttribute->aprod = array();
$aArtAttributes[$sAttrKey] = $oAttribute;
$aAttributesKey2Title[$sAttrKey] = $sParentTitle;
}
$aProd=$oParentAttribute->aProd;
if (count($aProd))
{
foreach ($aProd as $sParentKey => $oValue)
{
//Get id of article(s) which has(have) this parent article as parent
$sArticleKeys=$aParent2ArticleIds[$sParentKey];
if (count($sArticleKeys)>0)
{
foreach ($sArticleKeys as $sArticleKey)
{
$aArtAttributesEntry=$aArtAttributes[$sAttrKey]->aProd;
if (is_array($aArtAttributesEntry) && !in_array($sArticleKey,$aArtAttributesEntry))
{
$aArtAttributes[$sAttrKey]->aProd[$sArticleKey]=$oValue;
}
}
}
}
}
}
}
}
}
if ($bSortByName)
{
if (count($aArtAttributes))
{
//Sort attributes by attribute's name
if (!is_array($aAttributesKey2Title))
{
//Build data for sorting, if not already available
$aAttributesKey2Title=array();
foreach ($aArtAttributes as $sKey => $aAttribute)
{
$sTitle=$aAttribute->title;
$aAttributesKey2Title[$sKey]=$sTitle;
}
}
asort($aAttributesKey2Title);
$this->_oAttributeList=array();
foreach ($aAttributesKey2Title as $sAttributeKey=>$oValue)
{
$this->_oAttributeList[]=$aArtAttributes[$sAttributeKey];
}
}
}
else
{
$this->_oAttributeList=$aArtAttributes;
}
}
if ($bLoadParentAttributes)
{
//Clean up attributes list from empty attributes
foreach ($this->_oAttributeList as $sAttrKey => $oAttribute)
{
if (count($oAttribute->aProd)==0)
{
//No articles allocated to attribute, so remove attribute from list
unset($this->_oAttributeList[$sAttrKey]);
}
}
}
return $this->_oAttributeList;
}
}