View Full Version : shopping cart remove item - compare

07-07-2007, 10:00 AM
I am using the webforcecart.com (http://webforcecart.com) shopping cart.

The items that I add to the cart can be the same item with different variables. For example, T-Shirt can come in blue, red, white. So, if buy a blue one and a red one, the cart will display them seperately (normal functionality of a shopping cart).

My problem is that when I am removing items from the cart, I am identifying them in the array by their ID... so when I remove one, it's actually removing all occurances of that ID (so both the blue and red one get removed, even though I only wanted to remove the red one). That's the basics, there are actually 6 different item options that come into play.

line1, line2, line3, line4, font_style, icon --- they are stored in an array called $iteminfo.

So, I need the cart to remove only the item where the product i tell it to remove matches those 6 options.

The current delete function is this:

function del_item($itemid){ // removes an item from cart
$ti = array();
$this->itemqtys[$itemid] = 0;
foreach($this->items as $item){
if($item != $itemid){
$ti[] = $item;
$this->items = $ti;
} //end of del_item

All the product info is being stored in these arrays:

var $total = 0;
var $itemcount = 0;
var $items = array();
var $itemprices = array();
var $itemnames = array();
var $itemqtys = array();
var $iteminfo = array();

I'm trying to extend the functionality of webforcecart (http://webforcecart.com/). I think if I can figure out how to complete the delete function to work the way I need it, I can figure out the other functions for updating the cart.

Thanks for any input or help you can provide.

01-29-2010, 12:56 PM
Hi - I am doing practically the same thing with clothes sizes, colours using the webforce class, did you find a solution in the end?

I'm half way there with it, passes an array with the colour, size to the $cart->add_item function fine, just need to work out the best way to show multiple products which come from the same product_id they just have different selected attributes such as Colour, Size etc..

Thanks in advance any help would be appreicated

01-29-2010, 01:39 PM
To be honest the class is very outdated now. You should consider creating your own class based upon the wfcart class

01-29-2010, 02:15 PM
To be honest the class is very outdated now. You should consider creating your own class based upon the wfcart class

It is an old one, I was hoping somebody else might have already done this already :-)

Oh well, looks like I will just have to do like you say and rewrite this from scratch based on the original wfcart code - wish me luck :P

Thanks anyway :-)

01-29-2010, 02:17 PM
Other than add, remove and edit methods, I don't really see what you would need tbh. I'd start the whole thing from scratch again

01-29-2010, 02:21 PM
I'm just gonna use wfCart as a guide, rather than write the 'new' cart based on that, touch wood it goes well either way it will be a new learning experience for me :D

01-29-2010, 02:21 PM
Yup. Any difficulties you can always post back :)

01-29-2010, 02:24 PM
Cheers will do! Nice Pagination Class by they way! I could see myself using that in the future soon too! :)

01-29-2010, 02:29 PM
Thanks. I don't even paginate results all that often, but when I do it takes 2 mins :)

02-16-2010, 12:07 PM
Shopping cart - all done! Your comments inspired me to rewrite it and it does the job now.. will make a mini tutorial for this at some point for others to use/learn from.

Had another look at the pagination script - looks really good! Might try to implement this into one of my personal projects :)