2

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

user1912285
  • 112
  • 1
  • 7

1 Answers1

1

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..

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • thank you, i will try but how can view product id from cart in index.php directly because i modified many code in this :( – user1912285 Dec 18 '12 at 13:24
  • simply call $prow->virtuemart_product_id . just print the product array like echo "
    ";print_r($this->cart->products);You will get all the info related to the product
    – Jobin Dec 18 '12 at 13:30
  • oops, my site dont have mod_cartinfoasdf – user1912285 Dec 18 '12 at 13:42
  • oh, thanks a lot, i didnt find code get product_id in my site (i only found product image, product quantity...), i will try ur code. – user1912285 Dec 18 '12 at 13:48
  • great!, im successful get all product, thank you a lot for your help – user1912285 Dec 19 '12 at 01:06
  • oops, it only success in the first time i access page, and then the page is crash, i cant access administrator page too, it says error on line: image-> displayMediaThumb('style="height: 36px; width: 100%"',false); ?> – user1912285 Dec 19 '12 at 01:12
  • when i come to view cart page and return to homepage, the error is appear again, im mad with this problem – user1912285 Dec 19 '12 at 01:28