• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Cart Example

#16
[eluser]Flemming[/eluser]
Really handy tutorial, thanks Joe!

Some may prefer it if the quantity in the cart is increased when someone adds an item to their cart and that exact same item is already in the cart. I extended the cart class and changed the _insert() method like this:

Code:
// Now that we have our unique "row ID", we'll add our cart items to the master array

        // check if a identical item already exists, if so, increment its quantity
        if(array_key_exists($rowid, $this->contents()))
        {
            $this->_cart_contents[$rowid]['qty'] += $items['qty'];
            
        } else {
            // let's unset this first, just to make sure our index contains only the data from this submission
            unset($this->_cart_contents[$rowid]);

            // Create a new index with our new row ID
            $this->_cart_contents[$rowid]['rowid'] = $rowid;

            // And add the new items to the cart array
            foreach ($items as $key => $val)
            {
                $this->_cart_contents[$rowid][$key] = $val;
            }
        }


Messages In This Thread
Basic Cart Example - by El Forum - 09-12-2009, 04:25 PM
Basic Cart Example - by El Forum - 09-12-2009, 04:26 PM
Basic Cart Example - by El Forum - 09-13-2009, 08:11 AM
Basic Cart Example - by El Forum - 09-13-2009, 08:31 AM
Basic Cart Example - by El Forum - 09-13-2009, 12:58 PM
Basic Cart Example - by El Forum - 09-30-2009, 09:00 PM
Basic Cart Example - by El Forum - 09-30-2009, 10:06 PM
Basic Cart Example - by El Forum - 10-01-2009, 07:22 AM
Basic Cart Example - by El Forum - 10-01-2009, 09:38 PM
Basic Cart Example - by El Forum - 10-07-2009, 10:58 AM
Basic Cart Example - by El Forum - 10-24-2009, 07:56 PM
Basic Cart Example - by El Forum - 10-24-2009, 10:07 PM
Basic Cart Example - by El Forum - 10-25-2009, 10:28 AM
Basic Cart Example - by El Forum - 10-25-2009, 12:55 PM
Basic Cart Example - by El Forum - 11-02-2009, 02:21 AM
Basic Cart Example - by El Forum - 11-04-2009, 04:19 AM
Basic Cart Example - by El Forum - 12-08-2009, 04:05 AM
Basic Cart Example - by El Forum - 12-09-2009, 01:19 PM
Basic Cart Example - by El Forum - 12-10-2009, 12:03 PM
Basic Cart Example - by El Forum - 12-10-2009, 12:14 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.