Hi,
sehr gute Arbeit.
Bin leider nicht mehr Zeitlich dazu gekommen das als Modul zu verpacken.
Aber wenn Du einmal dabei bist habe ich gleich noch 2 kleine Änderungen die ich noch gemacht hatte. Es trat ein Problem auf wenn 2 verschiedene Artikel mit Pfand in den Warenkorb gelegt wurden:
/**
* Iterates through basket contents and adds bundles to items + adds
* global basket bundles
*
* @return null
*/
protected function _addBundles()
{
$aBundles = array();
// iterating through articles and binding bundles
foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
try {
// adding discount type bundles
if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
$aBundles = $this->_getItemBundles( $oBasketItem, $aBundles );
} else {
continue;
}
// adding item type bundles
$aArtBundles = $this->_getArticleBundles( $oBasketItem );
if(!empty($oBasketItem->getArticle()->oxarticles__wapawn->value))
{
$pAId = $this->getPawnArticleId($oBasketItem->getArticle()->oxarticles__wapawn->value);
// ################### ANFANG
$oBundleItem = $this->addToBasket( $pAId, $oBasketItem->getAmount(), null, null, false, true,null,$key );
// ################### ENDE
if($oBasketItem->getLink() && $oBundleItem) {
$oBundleItem->setLink($oBasketItem->getLink());
// ################### ANFANG
$oBundleItem->setTitle($oBundleItem->getTitle() . " " . $oBasketItem->getTitle() );
// ################### ENDE
}
}
// adding bundles to basket
$this->_addBundlesToBasket( $aArtBundles );
} catch ( oxNoArticleException $oEx ) {
$this->removeItem( $key );
oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
} catch( oxArticleInputException $oEx ) {
$this->removeItem( $key );
oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
}
}
// adding global basket bundles
$aBundles = $this->_getBasketBundles( $aBundles );
// adding all bundles to basket
if ( $aBundles ) {
$this->_addBundlesToBasket( $aBundles );
}
}
Soweit ich das auf die schnelle überblicke hatte ich hier noch den Titel richtig setzen lassen und den key des “Vater Artikels” (also der Artikel zu dem der Pfand gehört) mit übergeben.
(Habe die betreffenden Zeilen mal mit dem Kommentar // ################### versehen)
Dazu passend die addToBasket Funktion die den key mit verarbeitet und den Pfand an die richtige Stelle plaziert.
/**
* Adds user item to basket. Returns oxBasketItem object if adding succeeded
*
* @param string $sProductID id of product
* @param double $dAmount product amount
* @param mixed $aSel product select lists (default null)
* @param mixed $aPersParam product persistent parameters (default null)
* @param bool $blOverride marker to accumulate passed amount or renew (default false)
* @param bool $blBundle marker if product is bundle or not (default false)
* @param mixed $sOldBasketItemId id if old basket item if to change it
* @param string $pawnParentKey key of pawn Parent
*
* @throws oxOutOfStockException oxArticleInputException, oxNoArticleException
*
* @return object
*/
public function addToBasket( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blOverride = false, $blBundle = false, $sOldBasketItemId = null, $pawnParentKey = null )
{
// enabled ?
if ( !$this->isEnabled() )
return null;
// basket exclude
if ( $this->getConfig()->getConfigParam( 'blBasketExcludeEnabled' ) ) {
if ( !$this->canAddProductToBasket( $sProductID ) ) {
$this->setCatChangeWarningState( true );
return null;
} else {
$this->setCatChangeWarningState( false );
}
}
if(!empty($pawnParentKey)) {
$sItemId = $this->getItemKey( $sProductID.$pawnParentKey, $aSel, $aPersParam, $blBundle );
} else {
$sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
}
if ( $sOldBasketItemId && ( strcmp( $sOldBasketItemId, $sItemId ) != 0 ) ) {
if ( isset( $this->_aBasketContents[$sItemId] ) ) {
// we are merging, so params will just go to the new key
unset( $this->_aBasketContents[$sOldBasketItemId] );
// do not override stock
$blOverride = false;
} else {
// value is null - means isset will fail and real values will be filled
$this->_changeBasketItemKey( $sOldBasketItemId, $sItemId );
}
}
// after some checks item must be removed from basket
$blRemoveItem = false;
// initialling exception storage
$oEx = null;
if ( isset( $this->_aBasketContents[$sItemId] ) ) {
//updating existing
try {
// setting stock check status
$this->_aBasketContents[$sItemId]->setStockCheckStatus( $this->getStockCheckMode() );
//validate amount
//possibly throws exception
$this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride, $sItemId );
} catch( oxOutOfStockException $oEx ) {
// rethrow later
}
} else {
//inserting new
$oBasketItem = oxNew( 'oxbasketitem' );
try {
$oBasketItem->setStockCheckStatus( $this->getStockCheckMode() );
$oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
} catch( oxNoArticleException $oEx ) {
// in this case that the article does not exist remove the item from the basket by setting its amount to 0
//$oBasketItem->dAmount = 0;
$blRemoveItem = true;
} catch( oxOutOfStockException $oEx ) {
// rethrow later
} catch ( oxArticleInputException $oEx ) {
// rethrow later
$blRemoveItem = true;
}
if(empty($pawnParentKey)) {
$this->_aBasketContents[$sItemId] = $oBasketItem;
} else {
$this->_aBasketContents = $this->array_insert_after($this->_aBasketContents, $pawnParentKey, Array( $sItemId => $oBasketItem));
}
}
//in case amount is 0 removing item
if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
$this->removeItem( $sItemId );
} elseif ( $blBundle ) {
//marking bundles
$this->_aBasketContents[$sItemId]->setBundle( true );
}
//calling update method
$this->onUpdate();
if ( $oEx ) {
throw $oEx;
}
// notifying that new basket item was added
if (!$blBundle) {
$this->_addedNewItem( $sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId );
}
// returning basket item object
return $this->_aBasketContents[$sItemId];
}
function array_insert_after($array, $key, $new)
{
$keys = array_keys($array);
$pos = (int) array_search($key, $keys);
return array_merge(
array_slice($array, 0, $pos+1),
$new,
array_slice($array, $pos+1)
);
}
Nun sollte auch kein Problem mehr bestehen wenn 2 Verschiedene Artikel den selben Pfand haben.
Da ich die ID des Pfand mit der ID des Vaterartikels konkatiniert habe.
Bei Fragen zu den Bugfix kannst du mich gerne per PM anschreiben oder im Thread posten. 
Danke für die Arbeit!
P.S.: Alle Änderungen/Funktionen sind in der _oxbasket.php