Forums / Developer / Adding multiple Items to the shop basket at once

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>

eZ debug

Timing: Jan 18 2025 14:55:37
Script start
Timing: Jan 18 2025 14:55:37
Module start 'content'
Timing: Jan 18 2025 14:55:37
Module end 'content'
Timing: Jan 18 2025 14:55:38
Script end

Main resources:

Total runtime0.2593 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 587.8438180.8125
Module start 'content' 0.00510.0055 768.6563102.0547
Module end 'content' 0.01060.2486 870.7109530.1250
Script end 0.2592  1,400.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00381.4601200.0002
Check MTime0.00140.5504200.0001
Mysql Total
Database connection0.00070.281210.0007
Mysqli_queries0.206279.54371410.0015
Looping result0.00160.61611390.0000
Template Total0.248195.710.2481
Template load0.00100.375610.0010
Template processing0.247195.305110.2471
Override
Cache load0.00060.243410.0006
Sytem overhead
Fetch class attribute can translate value0.00090.344810.0009
XML
Image XML parsing0.00030.111410.0003
General
dbfile0.00823.1635200.0004
String conversion0.00000.001630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

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

Time used to render debug report: 0.0002 secs