Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

getting shopping cart unit total


Jason Jacobs

Recommended Posts

Hi all. I'm using TEP v2.1 preview release, and I am trying to figure out how many units I have in my shopping cart. One of the cart functions is get_quantity(), but that only returns the number of items. For example, if I had 2 cds and one book, it would return 2 (cd and book) instead of 3. I want it to return 3.

 

I am writing a shopping cart method that is supposed to get the list of products in the cart and then add up the # of each product. There are existing methods for getting the products ids and getting the total # of a product given the id. I have the following:

 

function get_quantity_total() {

  $list = explode(",", $this->get_product_id_list());

  $tot = 0;

  foreach ($list as $value) {

      $tot += $this->get_quantity($value);

  }//end for

  return $tot;

}

 

I get a correct list of product IDs, but it's only giving me back the quantity of the first one it checks. For kicks, I tried using two lines with hard coded IDs in them:

$tot += $this->get_quantity('25');

$tot += $this->get_quantity('38');

and this returned the correct number. When I echo out the ID and the value of get_quantity() for each ID, I get the correct ID values, but the first is the only one with the correct quantity. The second, and any thereafter, return 0.

 

What is wrong with my code that makes it not give me the subsequent quantities? Do I need to reset a pointer or something? I've been struggling with this for days, and I'm at my wit's end. Any help would be appreciated. Thanks a bunch.

 

-j

Link to comment
Share on other sites

I couldn't find an edit button, but I think I need to clarify something. When I hardcoded the ID values in I got the right quantity for the whole cart. It's when I used the variable in the foreach that it returns only the value of the first item and then zeros.

 

-j

Link to comment
Share on other sites

I hate to be a bother, but I've been working on this still, and am at a complete loss. If anyone has *any* idea, even if you're not positive, I'll take it.

 

I know people don't like post bumping, but with 2 pages of new posts every day, it's very easy to loose a post without bumping. Thanks for your patience.

 

-j

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...