简体   繁体   中英

How to get all products in cart in virtuemart?

im a newbie of Joomla and Virtuemart. i want to get/show all products in cart (product id, product image, product quantity) and i insert some code in index.php in template folder like this:

foreach( $this->cart->products as $pkey =>$prow ) {
...                     
}

but it make a error on line foreach, anyone can help me i use Joomla 2.5 and Virtuemart 2

thanks

If you are trying to include the above code directly in the index.php It will definitely error. Bcoz the this pointer referenced here is Cart helper. That is unknown in the index.php.

If you want to insert some cart features in the index.php best method is to use the module. You can find some modules similar to the mod_cartinfo (This modules will return the cart item details.) in public_html/modules/mod_cartinfo

you can find the module main file loads some php files that are required for the VM cart details.

if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
 if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
    if(!class_exists('VirtueMartCart')) require(JPATH_VM_SITE.DS.'helpers'.DS.'cart.php');
    $cart = VirtueMartCart::getCart(false);

Then use $cart istead of this->cart.

don't try to include this code portion in your index.php.It will load every time. Use module concept for achieving this. try this

Hope this will help you..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM