1999 Posts in 530 Topics by 433 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, Jedateach, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 346 Views |
-
Update the quantity of every item in the cart

5 June 2012 at 10:17am
Hi,
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){
if($item = self::create_order_item($product,$quantity,self::get_clean_param_array($this->getRequest()->getVars()))){
$item->Quantity = $quantity;
self::add_new_item($item);
}
}
else{
ShoppingCart::set_quantity_item($item, $quantity);
}
}elseif($item){
ShoppingCart::remove_all_item($item);
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;
$existingitem->write();
}
}To update the quantity of every item in the users cart?
-
Re: Update the quantity of every item in the cart

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: https://github.com/burnbright/silverstripe-shop/blob/master/code/ShoppingCart.php
regards,
Jeremy -
Re: Update the quantity of every item in the cart

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.
Cheers
| 346 Views | ||
|
Page:
1
|
Go to Top |


