Like a real world shopping experience when I finish collecting all the items I want to purchase into my shopping cart I proceed to the register where they will tally the total cost of my items. The DevKen Cart Calculator Class is that piece of the puzzle, it takes a shopping cart and calculates the total costs.
The Cart Calculator Class returns an augmented shopping cart that includes handling charges, taxes, discounts, subtotals and totals for each item. It also returns the calculations for the entire cart. Returning items like tax, shipping and handling, total, subtotal and more. Check out the demo page for a complete list.
// create a Cart_Calculator object $Cart_Calculator= new Cart_Calculator(array( 'shipping' => 10.53, // overall shipping cost 'handling' => 12.50, // overall handling charge 'tax' => 6.5, // tax added to items not already taxed 'discount' => '5%', // discount added to items not already discounted 'prefix' => '$' // prefix for returned values )); // Create an example cart (3 things are required ['title'],['price'] and ['qty']) $cart['title'] = 'Product 1'; $cart['price'] = 12.99; $cart['qty'] = 3; $cart['title'] = 'Product 2'; $cart['price'] = 25.50; $cart['qty'] = 9; $cart['discount'] =5.50; $cart['tax'] = 3.5; $cart['handling'] = 2.50; // send the cart to the register for calculating list($cart,$totals) = $Cart_Calculator->getTotals($cart); // if integrating with Cart class use this format // list($cart,$totals) = $Cart_Calculator->getTotals($CartObj->getCart); // print the updated cart for viewing print_r($cart); // print the totals array for viewing print_r($totals); // cart totals