DevKen PHP Cart Calculator Class

General purpose shopping cart calculator that accepts shipping, handling, tax and discounts on item and cart levels.

  • Language: PHP
  • Released: Jun 10, 2011
    Last Update: Oct 20, 2011

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.


Example Usage

// 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[0]['title'] = 'Product 1';    
$cart[0]['price'] = 12.99;
$cart[0]['qty'] = 3;
$cart[1]['title'] = 'Product 2';
$cart[1]['price'] = 25.50;
$cart[1]['qty'] = 9;
$cart[1]['discount'] =5.50;
$cart[1]['tax'] = 3.5;
$cart[1]['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 the totals array for viewing
print_r($totals); // cart totals
You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.


Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.

1 license From » $9.99 14 day money-back guarantee View Licenses
or Get a quote

for customization or integration services

  • Awesome class. Easy to integrate. I must give A+++
    NM Nilu Mukherjee
    3 years ago, 0 comments
    Was this helpful?
    Flag 1 of 1 people found this review helpful
  • I like the simplicity and premise of this component, however I am not able to get it working with the sister component (DevKen Cart) currently. I'm working with the developer in hopes that he can help get it working.
    EW Erik White
    2 years ago, 0 comments
    Was this helpful?
Post a comment

Or enter your name and Email
No comments have been posted yet.