News:

Looking for documentation? Take a look on our wiki

Main Menu

Extracting data from the CART session

Started by hayleyv, November 06, 2012, 10:35:16 AM

Previous topic - Next topic

hayleyv

I wish to extract the product_names from the cart session.   I can dump the session with print_r(unserialize($_SESSION['__vm']['vmcart']));.

How to I loop through the cart session and extract each product_name?  Thanks.

bytelord

#1
Hello,

Never tested but should be like the following. I take it as example from cart module which you can examine it more if you wish (mod_virtuemart_cart.php and default.php template file)

if(!class_exists('VirtueMartCart')) require(JPATH_VM_SITE.DS.'helpers'.DS.'cart.php');
$cart = VirtueMartCart::getCart(false);
$data = $cart->prepareAjaxData();
$show_price = (bool)$params->get( 'show_price', 1 ); // Display the Product Price?

<?php foreach ($data->products as $product)
    {
  <div class="prices" style="float: right;"><?php echo  $product['prices'?>
</div>
<span class="quantity"><?php echo  $product['quantity'?></span>&nbsp;x&nbsp;<span class="product_name"><?php echo  $product['product_name'?></span>
<?php if ( !empty($product['product_attributes']) ) { ?>
<div class="product_attributes"><?php echo $product['product_attributes'?></div>
<?php }
       }
?>

<?php if ($data->totalProduct and $show_price) echo  $data->billTotal?>
<?php if ($data->totalProduct and $show_price) echo  $data->cart_show?>


Hopefully gives you some ideas.

Also you could examine the cart template file default_pricelist.php to see how the data is extracted from the cart, but also should examine the cart/view.html.php

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!