[SOLVED] "Add to cart" directly from the product list of a category

Started by 187bundy, April 17, 2012, 23:45:41 PM

Previous topic - Next topic

187bundy

Hello !

In the default configuration of Virtuemart, if you want to buy a product, you've to navigate this way :

1. Click on one specific category from homepage
2. Click on "pruduct details" of one of the products
3. Click on "add to cart" button.

... What I'm trying to do is to delete the "products details" page and go directly from the products list to the cart :

1. Click on one specific category from homepage
2. Click on "add to cart" button of one of the products

I hope I'm being clear...  :o

Any adeas ?
F


=>>>>> I found my solution from http://forum.virtuemart.net/index.php?topic=90961.0

In order to do this, you have to open com_virtuemart-modifié\views\category\tmpl\default.php and add the following code :

<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
   <?php // Product custom_fields
   if (!empty($this->product->customfieldsCart)) {  ?>
   <div class="product-fields">
      <?php foreach ($this->product->customfieldsCart as $field)
      { ?><div style="display:inline-block;" 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 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><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($this->product->customsChilds)) {  ?>
      <div class="product-fields">
         <?php foreach ($this->product->customsChilds as $field) {  ?>
            <div style="display:inline-block;" 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><br/ >
            <?php
         } ?>
      </div>
   <?php } ?>

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



THEN, to fix the bug you'll notice, do this :

In order to solve the +2 -2 problem, you must edit the file located under:

/var/www/joomla/components/com_virtuemar/assets/js/vmprices.js

And change the following two lines that you can find at the top of the file:

Change:

                      plus   = cart.find('.quantity-plus'),
                      minus  = cart.find('.quantity-minus'),

with:
                      plus   = cart.find('.quantity-plus').unbind("click"),
                      minus  = cart.find('.quantity-minus').unbind("click"),

iMacvador

do you have a solution to add that button on all products... i did the changes but could see the add to cart only on the last product of list...



forgot about everything you maybe need to know...

i'm with Joomla 2.5.4 VM 2.0.6 using a yootheme template...