VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: prokops on November 18, 2016, 08:52:09 AM

Title: $product['image'] missing in drop down cart.
Post by: prokops on November 18, 2016, 08:52:09 AM
Hi!

I used to output product images in drop down cart module of my template with <?php foreach ($data->products as $product){ .... echo $product['image'];?>.

After recent updates, I can't find product images in $data->products . Can anyone shed light on how to find the images now?

Cheers
Title: Re: $product['image'] missing in drop down cart.
Post by: Jumbo! on November 18, 2016, 09:06:38 AM
Standard VM Cart Module does not load product images. See VirtueMartCart::prepareAjaxData() function in cart helper - components/com_virtuemart/helpers/cart.php

You will first have to hack or customize this function to add images to the products. Then you will also have to customize the JavaScript so that the images can be updated over Ajax. Virtuemart.cartEffect() function in components/com_virtuemart/assets/js/vmprices.js

Ideally, I would suggest you develop your own custom module instead of hacking core codes. You can use Joomla! Ajax Interface to update the module over Ajax in your scripts. Refer - https://docs.joomla.org/Using_Joomla_Ajax_Interface

Alternatively, you can use some 3rd party module.
Title: Re: $product['image'] missing in drop down cart.
Post by: GJC Web Design on November 18, 2016, 11:32:00 AM
$cart is also available in the module

I use a tmpl. snippet like

<?php foreach ($data->products as $product){
                    foreach (
$cart->products as $cproduct) {
                      if (
$product['product_sku'] == $cproduct->product_sku ) {
$image $cproduct->images[0]->displayMediaThumb (''FALSE);
                      }
                  } 
?>


but isn't ajax so only updates after a page refresh
if u use a dropdown cart etc no one will notice..  ;)