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.

eZ debug

Timing: Jan 31 2025 03:36:00
Script start
Timing: Jan 31 2025 03:36:00
Module start 'layout'
Timing: Jan 31 2025 03:36:00
Module start 'content'
Timing: Jan 31 2025 03:36:00
Module end 'content'
Timing: Jan 31 2025 03:36:00
Script end

Main resources:

Total runtime0.0247 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.2656151.2266
Module start 'layout' 0.00560.0041 739.4922220.7188
Module start 'content' 0.00970.0134 960.21091,005.9609
Module end 'content' 0.02310.0015 1,966.171937.9922
Script end 0.0246  2,004.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.0186140.0002
Check MTime0.00114.5562140.0001
Mysql Total
Database connection0.00083.087110.0008
Mysqli_queries0.002610.599830.0009
Looping result0.00000.060910.0000
Template Total0.00114.410.0011
Template load0.00083.205110.0008
Template processing0.00031.160610.0003
Override
Cache load0.00052.003910.0005
General
dbfile0.00176.916080.0002
String conversion0.00000.029040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs