Jump to content

Accessing values in the $basket array


RetroRocker

Recommended Posts

Hi

While working within cart.inc.php I have been trying to access the values within the $basket array for all the items a customer may have in their shopping basket. Using print_r() or a var_dump() gives a breadown of the array but not the actual values held. I am specifically after any item's product ID and its quantity ordered. As I need it for all items, I will need to incorporate it into a 'foreach' construct but I'm having no success. Once I have extracted this data, I'm going to display it in a new window using another script (I dont have any problem with that, it's just that you might be wondering why looking at all this information in view basket isn't already enough :on2long:

I would genuinely appreciate some ideas, info on how to access this data.

thanks RR

Link to comment
Share on other sites

First, instantiate a cart object. It makes it a whole lot easier. The contents have been serialized. Look at the cart.php file in the class folder. There, you can get an idea of what class methods to call to get what you need. The part of the basket you're interested in is 'conts' which contains everything in the cart but before it has been sold (that would be 'invArray').

The part about 'conts' is that any options are saved with the product info. The file cart.inc.php has what you need. Start looking at around line 354.

I've attached a PDF of a Visio diagram I've been putting together.

In the 'conts' box, you will see that there are two items in the cart: the first is productID 39 with a quantity of 1, and the second is productID 31 with options 136 and 65 with a quantity of 1.

Visio_Cart.pdf

Link to comment
Share on other sites

Hi

Thanks again to that 'bsmither' guy for a fantastically helpful reply, it is genuinely appreciated. Exactly the information needed to point me in the right direction :D . The 'cart flowchart' is great ! The only thing I didn't do was instantiate a new $cart object. I found that to simply assign a couple of session vars. within the 'foreach', starting around line 350 of cart.inc.php works very well for me. Something along the lines of ...

		$quantity_requested = $cart->cartArray['conts'][$key]["quantity"];

$_SESSION['product_' . $i] = $product[0]['productCode'] . '||' . $quantity_requested;

$_SESSION['product_lines'] = $i;

... was fine for me because it picks up the quantity, product code and the number of product lines ordered (which was all the information I actually needed) in to session vars. for as many product lines as needed.

all the best

RR

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...