VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: coramba on May 30, 2012, 12:53:41 PM

Title: Include an Add to Cart and Qty button to products in category list
Post by: coramba on May 30, 2012, 12:53:41 PM
Please assist I have Joomla 2.5 and Virtuemart 2.0.6

I am trying to - Include an Add to Cart and Qty button to products in category list - so customers can add to cart  - without going to product details.

I have read the post regarding this.. but cannot get anywhere with it...


Can anyone  - Please advise how I can do this and which file I may have to edit.


Many thanks
:)
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: Tikkiro on May 31, 2012, 17:11:45 PM
I'm looking to do exactly the same thing - could you provide info on the post you mentioned finding before?
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: jenkinhill on June 01, 2012, 10:56:17 AM
See http://forum.virtuemart.net/index.php?topic=90961.0
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: coramba on June 04, 2012, 09:44:44 AM
I have read the posts

See http://forum.virtuemart.net/index.php?topic=90961.0

And copied the code - followed the instructions...BUT... nothing changes...

There seems to be lots of following posts which fix error and add more changes...  I got totally confused..

Can anyone please post a step by step procedure at to how I can get

Include an Add to Cart and Qty button to products in category list

Thanks in advance
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: gxHL on June 04, 2012, 11:22:33 AM
go to components/com_virtuemart/views/category/tmpl/default.php

Find
<p>
               <?php // Product Details Button
               
echo JHTML::link($product->linkJText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'product-details'));
               
?>

               </p>


Add after one of these
Quote from: legal on September 17, 2011, 11:58:46 AM
And here is just add to cart button without everything else:


<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="addtocart-bar">
<?php // Display the quantity box ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

<div class="clear"></div>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>


And here is the code for add to cart button with quantity chooser:
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="addtocart-bar">

<?php // Display the quantity box ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input  type="text" class="quantity-input" name="quantity[]" value="1" />
</span>
<span class="quantity-controls">
<input type="button" class="quantity-controls quantity-plus" />
<input type="button" class="quantity-controls quantity-minus" />
</span>
<?php // Display the quantity box END ?>

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

<div class="clear"></div>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>


This is all explained in the second page of the thread :) .
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: Tikkiro on June 07, 2012, 16:32:13 PM
Great - that's me sorted with it at least :)
Many thanks again.
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: Thomas Kuschel on June 08, 2012, 11:08:09 AM
thank you too! Works great, should be on default with a new VM installation. - I just implemented the "cart button without everything else", but made an extra class for the <span class="addtocart-button"> , now called <span class="addtocart-button2">, and added some stuff in the vmsite-ltr.css to decrease the button in that view. VoilĂ !
Thomas
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: coramba on June 13, 2012, 11:44:10 AM
Got it working on my Template... Thanks

However when I click on ADD to CART button  - the add to cart POP-UP does not appear and I have to refresh to see what it has added item to cart?   it there some other code I need to amend...

Please advise if possible...

Thanks
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: dcross02 on August 04, 2012, 01:10:55 AM
This worked perfectly, except the Add to Cart button has no text on it. It's just a blank button. How do I get it to read "Add to Cart"?
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: benstapleton on August 20, 2012, 11:42:18 AM
Just want to add a quick reply to say that this has been very helpful. Thanks a lot! :)
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: Sid. on August 27, 2012, 14:27:40 PM
I agree, this has been quite a helpful post.  However, what if we have a product with Custom Fields including Cart Variants?  I added the following code just above the comment to "// Add the button".


<?php // Product custom_fields
if (!empty($product->customfieldsCart)) { ?>

    <div class="product-fields">
<?php foreach ($product->customfieldsCart as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title?></strong></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php
}
?>

    </div>
<?php
}
/* Product custom Childs
 * to display a simple link use $field->virtuemart_product_id as link to child product_id
 * custom_value is relation value to child
 */

if (!empty($product->customsChilds)) {
    ?>

    <div class="product-fields">
    <?php foreach ($product->customsChilds as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->field->custom_title?></strong></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

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


So the full snippet that was included on my "category" template page is:


<!-- add to cart -->
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>" style="float:right;">
<div class="addtocart-bar">
<?php // Display the quantity box ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Product custom_fields
if (!empty($product->customfieldsCart)) { ?>

    <div class="product-fields">
<?php foreach ($product->customfieldsCart as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title?></strong></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php
}
?>

    </div>
<?php
}
/* Product custom Childs
 * to display a simple link use $field->virtuemart_product_id as link to child product_id
 * custom_value is relation value to child
 */

if (!empty($product->customsChilds)) {
    ?>

    <div class="product-fields">
    <?php foreach ($product->customsChilds as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->field->custom_title?></strong></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

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

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

<div class="clear"></div>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form><!-- end add to cart -->
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: tblock on September 18, 2012, 06:12:40 AM
I also have the same issue as dcross2 above.  The solution works, but there is no text on my add to cart button in category view.
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: coramba on September 30, 2012, 05:58:47 AM

PLEASE ADVISE - 

Finally go it to work - had to apply the changes to my template, not the VM component but the html/com_virtuemart/ files from the template where you'll find the overriders.

BUT for some reason  the "new" ADD TO CART button in category list Has NO title-- is is small blank rectangle..

There seems to be NO title


<input class="addtocart-button" type="submit" title="Add to Cart" value="Add to Cart" name="addtocart">   (add to cart in product view)

<input class="addtocart-button" type="submit" title="" value="" name="addtocart">  (add to cart in category view)


Can someone assist with fix

Many Thanks
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: kaseynova on October 04, 2012, 06:42:52 AM
I used this code and it works perfectly with my custom field for downloadable products. But I want to make one more adjustment and can't figure out where I can do this. On the details page, cart page and the email that is sent to customer, the name of the actual pdf file is shown such as "downloadbook.pdf". That than display the name of that file, I want it to display the title of the product. Can you steer me in the right direction?
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: anaffelici on October 18, 2012, 18:40:35 PM
Quote from: Sid. on August 27, 2012, 14:27:40 PM
I agree, this has been quite a helpful post.  However, what if we have a product with Custom Fields including Cart Variants?  I added the following code just above the comment to "// Add the button".


<?php // Product custom_fields
if (!empty($product->customfieldsCart)) { ?>

    <div class="product-fields">
<?php foreach ($product->customfieldsCart as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title?></strong></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php
}
?>

    </div>
<?php
}
/* Product custom Childs
 * to display a simple link use $field->virtuemart_product_id as link to child product_id
 * custom_value is relation value to child
 */

if (!empty($product->customsChilds)) {
    ?>

    <div class="product-fields">
    <?php foreach ($product->customsChilds as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->field->custom_title?></strong></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

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


So the full snippet that was included on my "category" template page is:


<!-- add to cart -->
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>" style="float:right;">
<div class="addtocart-bar">
<?php // Display the quantity box ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Product custom_fields
if (!empty($product->customfieldsCart)) { ?>

    <div class="product-fields">
<?php foreach ($product->customfieldsCart as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title?></strong></span>
<?php if ($field->custom_tip)
    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>

<span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
    </div><br />
    <?php
}
?>

    </div>
<?php
}
/* Product custom Childs
 * to display a simple link use $field->virtuemart_product_id as link to child product_id
 * custom_value is relation value to child
 */

if (!empty($product->customsChilds)) {
    ?>

    <div class="product-fields">
    <?php foreach ($product->customsChilds as $field) { ?>
    <div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><strong><?php echo JText::_($field->field->custom_title?></strong></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

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

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

<div class="clear"></div>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form><!-- end add to cart -->


Hi Sid,

Could you help with some doubts?

1. If a shopper just click in the add to cart button (in a product with child), the parent product goes to the cart. I changed in custom fields " parent not orderable"  but it's still available.
2. If a shopper choose a child, he's redirect to the detail product page, it would be nice if he could choose an option and  after clicks in the add to cart button without leave the category page.

Tks

Title: Include an Add to Cart and Qty button to products in category list
Post by: PetreZo on November 07, 2012, 16:45:35 PM
Hello everybody!

I have the same problem. In category list view I have many products but without the add to cart button, just image and description. My problem is that I would like to add the Add to cart button together with the Custom Fields, because at each product I have 4-5 different prices.
You can see what I am talking about on the following link:

http://img14.picoodle.com/i5b7/petrez/hjk9_ea6_u51f2.jpg

Somebody can help me? Thanks.
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: chriskabisch on March 06, 2013, 20:20:39 PM
I am trying to display add to cart button in category view with custom fields including cart child variants.

1. When I add the hack from this thread the custom field cart child variants do not display.

2. When I have the add to cart button by itself, it adds the parent to the cart.

3. If I just add the custom field hack it will display, but I cannot add to cart.

4. I found a hack from a custom template forum thread and it actually displays the custom fields however when I add a product to the cart it adds the product twice.

Here is the additional code:

<?php // Add To Cart Button
if (!VmConfig::get('use_as_catalog'0) and !empty($product->prices)) {?>

<div class="FlexibleWebaddtocart-area">

<form method="post" class="product js-recalculate" action="index.php" >
<?php // Product custom_fields
if (!empty($product->customfieldsCart)) {  ?>

<div class="FlexibleWeb-product-fields">
<?php foreach ($product->customfieldsCart as $field)
?>


                        <div style="text-align:left;" class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title?></b></span>
<?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>

                            <span class="product-field-display"><?php echo $field->display ?></span>

<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
</div>
<?php
}
?>

</div>
<?php }
 /* Product custom Childs
  * to display a simple link use $field->virtuemart_product_id as link to child product_id
  * custom_value is relation value to child
  */
 
if (!empty($product->customsChilds)) {  ?>

<div class="product-fields">
<?php foreach ($product->customsChilds as $field) {  ?>
<div style="display:inline-block;float:right; padding:3px;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title?></b></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

</div>
<?php
?>

</div>
<?php ?>

<div class="Flexibleaddtocart-bar">

<?php // Display the quantity box ?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls 'addtocart-button'//$button_cls = 'addtocart_button';
$button_name 'addtocart'//$button_cls = 'addtocart_button';
 
 
// Display the add to cart button
$stockhandle VmConfig::get('stockhandle','none');
if(($stockhandle=='disableit' or $stockhandle=='disableadd') and ($product->product_in_stock $product->product_ordered)<1){
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
$button_name 'notifycustomer';
}
vmdebug('$stockhandle '.$stockhandle.' and stock '.$product->product_in_stock.' ordered '.$product->product_ordered);
?>

<span class="addtocart-button">
<?php if ($button_cls == "notify-button") { ?>
                            <span class="outofstock"><?php echo JText::_('COM_VIRTUEMART_CART_PRODUCT_OUT_OF_STOCK'); ?></span>

                            <?php } else {?>
                            <input type="submit" name="<?php echo $button_name ?>"  class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />




                            <?php ?>
</span>

<div class="clear"></div>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />

<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>


</div>
<?php }  // Add To Cart Button END ?>



I'm close but not smart enough to figure it out.

Any help would be appreciated, thanks in advance.
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: mhuebler on October 28, 2013, 20:41:43 PM
anybody have a actualy solution to display the custom child variants with add to card button on the category page, please ?
Title: Re: Include an Add to Cart and Qty button to products in category list
Post by: AH on October 28, 2013, 22:56:49 PM
This is working if you have done what madking's solution suggested, not if you have used files from somewher in the thread! 

These are the steps:

1 Create a folder rootOfYourSite/templates/yourTemplate/html/com_virtuemart/category

Copy into this:-


2 default.php from com_virtuemart/views/category/tmpl 
3 default_addtocart.php from components/com/virtuemart/views/productdetails/tmpl

4 Rename default_addtocart.php to something sensible e.g. addtocartCategory.php  works for me

5 In the new file addtocartCategory.php replace $this->product with $product

6 Now go to the copied  default.php (the browse view for a category) and add the new add to cart template (button etc.) in the position you want
Do this somewhere between

// Show Products  and <!-- end of product -->

Using the code

<?php include 'addtocartCategory.php'?>


The category add to cart should then perform the same as the product add to cart.