Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Update the quantity of every item in the cart

Go to End

3 Posts   960 Views


Community Member, 48 Posts

5 June 2012 at 10:17am


In the application I am building (relating to travel), the user adds a number of items to their basket and prior to checkout is prompted for how many guests it relates to so I need to update the number of items of everything in their cart.

Is it possible to modify:

function setquantityitem($request) {
		$quantity = $request->getVar('quantity');
		$product = $this->buyableFromURL();
		if (is_numeric($quantity) && $product) {
			$item = ShoppingCart::get_item($this->urlFilter());
			if($quantity > 0){
					if($item = self::create_order_item($product,$quantity,self::get_clean_param_array($this->getRequest()->getVars()))){
						$item->Quantity = $quantity;
					ShoppingCart::set_quantity_item($item, $quantity);
				return self::return_data("success","Item removed completely");//TODO: i18n
			return self::return_data("success","Quantity set successfully");//TODO: i18n
		return self::return_data("failure","Quantity provided is not numeric");//TODO: i18n
	static function set_quantity_item($existingitem, $quantity) {
		if ($existingitem) {
			$existingitem->Quantity = $quantity;

To update the quantity of every item in the users cart?


Forum Moderator, 238 Posts

5 June 2012 at 10:58am

Hi Fraser,

Can you specify which module you are using for ecommerce? I'm managing the shop module, which it doesn't look like you are using. I'll try to offer some advice anyway.

Certainly with some development effort, you'll be able to achieve what you're wanting to.

Personally, I would try keeping this non-standard functionality separate. I've looked inside my ShoppingCart code for my shop module, and noticed I don't have extension points to make changes when a quantity is updated for example. Introducing such functionality would allow external code like this:

class TravelOrder extends Extension{

    function afterSetQuantity($item,$buyable,$quantity,$filter){

        foreach($this->owner->Items() as $orderitem){$item->Quantity = $quantity;}


What do you think?

For your reference, here is my ShoppingCart class, without these changes:



Community Member, 48 Posts

5 June 2012 at 11:25am

Hi Jeda,

Thanks for the response.

I'm using the Ecommerce module.

I created a subclass of the Shopping Cart class and am making all my modifications in here.