Thursday 24 July 2008 7:10:23 am
In case this might be helpful to others, Here's another solution to add more than 1 item at once to the basket (from within a PHP module in this case): Use the traditional way to add one unit like this:
$operationResult = eZOperationHandler::execute( 'shop', 'addtobasket', array( 'basket_id' => $basket->attribute( 'id' ), 'object_id' => $contentobjectID,'option_list' => $optionList ) );
and then, add a call to adjust the quantity like this:
eZShopOperationCollection::addQuantity( $contentobjectID, $quantity-1 );
you need to add the following code to your kernel/shop/ezshopoperationcollection.php:
function addQuantity( $objectID, $quantity )
{
$object = eZContentObject::fetch( $objectID );
$basket =& eZBasket::currentBasket();
$collection =& $basket->attribute( 'productcollection' );
$collectionItems =& $collection->itemList( false );
foreach ( $collectionItems as $item )
{
/* For all items in the basket which have the same object_id: */
if ( $item['contentobject_id'] == $objectID )
{
$itemID = $item['id'];
$prodline = eZProductCollectionItem::fetch( $itemID );
$prodline->setAttribute( 'item_count', $quantity + $prodline->attribute( 'item_count' ) );
$prodline->store();
}
}
}
Of course, this would not be needed if there were a quantity parameter in the AddToBasket function... </Pascal>
|