VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: hayleyv on November 06, 2012, 10:35:16 AM

Title: Extracting data from the CART session
Post by: hayleyv on November 06, 2012, 10:35:16 AM
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.
Title: Re: Extracting data from the CART session
Post by: bytelord on November 06, 2012, 15:59:07 PM
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