Welcome Guest, Not a member yet? Register   Sign In
How to get Shipping Weight Total from the codeigniter cart class (its in the cart items array)
#1

[eluser]dwhite7508[/eluser]
Hey guys,
I have a question about the cart class in codeigniter. This is probably more of an array question, but here it is...

I have my products in the codeigniter cart class and i've made a key and value for "weight". It works fine and when I do a print_r on $this->cart->contents() it shows the weight of each item just fine.

What i'm not sure of how to do (and i know this is probably simple) is loop through the cart contents and add up the total weight from each product array in the contents array.

Any ideas?
#2

[eluser]dwhite7508[/eluser]
Nevermind, some more thinking on the subject has brought me to a useable solution. I'm posting the answer for anyone looking for the same solution. If you add a "weight" row to your products table and you're using codeigniter's built in cart class, this is how you can get a "total weight" from the products in the cart...

Code:
$totalWeight = 0;
foreach($this->cart->contents() as $item)
{
   $totalWeight += $item['weight'];
}




Theme © iAndrew 2016 - Forum software by © MyBB