Adding multiple Items to the shop basket at once

Author Message

Brendan Pike

Monday 11 September 2006 3:58:14 pm

Is this possible in 3.8? I saw this old hack from Björn http://ez.no/community/contribs/hacks/adding_multiple_items_to_the_shop_basket_at_once but I will need product options support.

Failing that I would then look at adding options and an add to basket button to each product in line view.

Has anyone had experience in this area?

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

Piotrek Karaś

Friday 04 May 2007 3:39:10 am

Hello,

Has anyone come up with a solution yet? Is eZ publish capable of adding multiple product combinations (product and its options and amounts) to the basket in just one click? Is there a way without modifying the kernel file?

Example:
We have a t-shirt in 30 different colors. We want to display a larger form so that the client can define all the options for say 10 combinations at once and then click "add to basket".

Maybe something new in 3.9.x?

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Betsy Gamrat

Tuesday 08 May 2007 7:26:21 pm

Hi,

I did something similar with another application. I used AJAX to simulate the calls into the application.

Basically - you set up a template that has a check box or an opportunity for the site visitor to enter a quantity. After they update the quantity, you send the data to eZ - as if you are adding items to the cart. If the delete items, you remove them.

Be prepared to keep a client side version of the cart contents.

When the site visitor is done shopping, the transition to the cart is really just a 'view basket'.

Good luck.

Piotrek Karaś

Tuesday 08 May 2007 11:17:08 pm

Hello Betsy,
Thank you for the response!

The ajax solution sound reasonable and we may actually find it very useful. Just few things to clear up:

<i>...After they update the quantity, you send the data to eZ - as if you are adding items to the cart...</i>
We have noticed, that when a product is sent to the cart, it is always quantity=1 and only the cart itself has the ability to modify it. Any ways around that?

<i>Be prepared to keep a client side version of the cart contents.</i>
Can you elaborate? I don't quite catch that.

Thanks!

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Pascal Specht

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>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.