News:

Looking for documentation? Take a look on our wiki

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

PetreZo

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.

chriskabisch

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.

mhuebler

anybody have a actualy solution to display the custom child variants with add to card button on the category page, please ?

AH

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

Joomla 4.4.5
php 8.1