VirtueMart Forum

VirtueMart 2 + 3 + 4 => Frontend Modules => Topic started by: jordantsap on April 01, 2016, 12:47:08 PM

Title: Show product image and total product number in cart module
Post by: jordantsap on April 01, 2016, 12:47:08 PM
Hello to all.
I use joomla 3.5.0 and VirtueMart 3.0.14.
I want to customize the cart module so that i can display the product image and the total products.
I've searched a lot in component and module but my knowledge is not enough to do this.
Can somebody help?
Title: Re: Show product image and total product number in cart module
Post by: GJC Web Design on April 01, 2016, 23:39:53 PM
there are plenty of 3rd party cart modules that already do this.. why re-invent the wheel?
Title: Re: Show product image and total product number in cart module
Post by: AH on April 02, 2016, 10:31:59 AM
because you then dont need to rely on third party plugins ;-)

The way I have sorted this is to edit one core file and do one template override

The core file
/components/com_virtuemart/helpers/cart.php


// UPDATE CART / DELETE FROM CART
$data->products[$i]['quantity'] = $product->quantity;
$data->totalProduct += $product->quantity ;
//Quorvia provide image to minicart
$data->products[$i]['image']= $product->images[0]->displayMediaThumb ('', FALSE);

edit by Milbo, added to core!

And in the template
templates/YOURTEMPLATE/html/mod_virtuemart_cart/default.php


<?php // no direct access
defined('_JEXEC') or die('Restricted access');

//dump ($cart,'mod cart');
// Ajax is displayed in vm_cart_products
// ALL THE DISPLAY IS Done by Ajax using "hiddencontainer" 
?>


<!-- Virtuemart 2 Ajax Card -->
<div class="vmCartModule <?php echo $params->get('moduleclass_sfx'); ?>" id="vmCartModule<?php echo $params->get('moduleid_sfx'); ?>">
<?php
if ($show_product_list) {
?>

<div class="hiddencontainer" style=" display: none; ">
<div class="vmcontainer">
<div class="product_row">
<?php //new image ?>
<div class="image"></div>
<span class="quantity"></span>&nbsp;x&nbsp;<span class="product_name"></span>

<?php if ($show_price and $currencyDisplay->_priceConfig['salesPrice'][0]) { ?>
<div class="subtotal_with_tax" style="float: right;"></div>
<?php ?>
<div class="customProductData"></div><br>
</div>
</div>
</div>
<div class="vm_cart_products">
<div class="vmcontainer">

<?php
foreach ($data->products as $product){
?>
<div class="product_row">
<?php //new image ?>
<div class="image"><?php echo $product['image'?></div>
<span class="quantity"><?php echo  $product['quantity'?></span>&nbsp;x&nbsp;<span class="product_name"><?php echo  $product['product_name'?></span>
<?php if ($show_price and $currencyDisplay->_priceConfig['salesPrice'][0]) { ?>
  <div class="subtotal_with_tax" style="float: right;"><?php echo $product['subtotal_with_tax'?></div>
<?php ?>
<?php if ( !empty($product['customProductData']) ) { ?>
<div class="customProductData"><?php echo $product['customProductData'?></div><br>

<?php ?>

</div>
<?php }
?>

</div>
</div>
<?php ?>

<div class="total" style="float: right;">
<?php if ($data->totalProduct and $show_price and $currencyDisplay->_priceConfig['salesPrice'][0]) { ?>
<?php echo $data->billTotal?>
<?php ?>
</div>

<div class="total_products"><?php echo  $data->totalProductTxt ?></div>
<div class="show_cart">
<?php if ($data->totalProduct) echo  $data->cart_show?>
</div>
<div style="clear:both;"></div>
<div class="payments-signin-button" ></div>
<noscript>
<?php echo vmText::_('MOD_VIRTUEMART_CART_AJAX_CART_PLZ_JAVASCRIPT'?>
</noscript>
</div>


Title: Re: Show product image and total product number in cart module
Post by: jordantsap on April 04, 2016, 11:33:36 AM
Thanks for the reply AH.
I found the "// UPDATE CART / DELETE FROM CART" coding
But where do i have to add the "//Quorvia provide image to minicart"?
Title: Re: Show product image and total product number in cart module
Post by: Studio 42 on April 04, 2016, 13:00:35 PM
CHeck the code provided for templates/YOURTEMPLATE/html/mod_virtuemart_cart/default.php
but remove this line <?php new image ?> or you get a php error.
Title: Re: Show product image and total product number in cart module
Post by: GJC Web Design on April 04, 2016, 17:09:54 PM
guess AHa meant //new image
Title: Re: Show product image and total product number in cart module
Post by: AH on April 04, 2016, 17:28:49 PM
Yes I did ;-)

I changed the code above
Title: Re: Show product image and total product number in cart module
Post by: prokops on May 02, 2016, 14:54:49 PM
Jackpot, thanks AH!

What can we do to make this core? Or maybe make this a plugin ? Hacking core files is not sustainable :)

Thanks for the fix posted.

cheers,
Title: Re: Show product image and total product number in cart module
Post by: Studio 42 on May 02, 2016, 15:58:37 PM
This don't need any core hacks, only change/buy a module that can do more as core cart one.
I wondering that AH provide such a core hack, but why not, if you want not update VM or note all you code changes.
Title: Re: Show product image and total product number in cart module
Post by: AH on May 02, 2016, 17:35:34 PM
QuoteHacking core files is not sustainable

Then don't do it!


QuoteI wondering that AH provide such a core hack, but why not, if you want not update VM or note all you code changes.

Studio - Agreed - You would have to test this change with every update to this file in VM.

I am not a fan of adjusting core files - but I am also not a fan of adding third party modules that create dependencies for what is essentially a small requirement/change.