News:

Support the VirtueMart project and become a member

Main Menu

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

Started by coramba, May 30, 2012, 12:53:41 PM

Previous topic - Next topic

coramba

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
:)

Tikkiro

I'm looking to do exactly the same thing - could you provide info on the post you mentioned finding before?

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

coramba

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

gxHL

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 :) .
VM 2.0.10 J 2.5.7

Tikkiro

Great - that's me sorted with it at least :)
Many thanks again.

Thomas Kuschel

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

coramba

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

dcross02

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"?

benstapleton

Just want to add a quick reply to say that this has been very helpful. Thanks a lot! :)

Sid.

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

tblock

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.

coramba


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

kaseynova

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?

anaffelici

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