Jump to:

2088 Posts in 1008 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Update the quantity of every item in the cart

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, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 530 Views
  • Fraser
    Community Member
    46 Posts

    Update the quantity of every item in the cart Link to this post


    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?

  • Jedateach
    Forum Moderator
    227 Posts

    Re: Update the quantity of every item in the cart Link to this post

    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: https://github.com/burnbright/silverstripe-shop/blob/master/code/ShoppingCart.php


  • Fraser
    Community Member
    46 Posts

    Re: Update the quantity of every item in the cart Link to this post

    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.


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.