VirtueMart 2 > Templating & Layouts
Add To Cart From Category [Solved]
jiapei100:
Hi, Dear legel:
I'm using Joomla 2.5.6 + VirtueMart 2.0.6 .
I followed your way, and tried to modify the file "/components/com_virtuemart/views/productdetails/tmpl/default.php".
Unfortunately, there is no "<?php echo $this->product->virtuemart_product_id ?>", but there exists some "$this->product->virtuemart_product_id".
I did a replacement for all "$this->product" to "$product", but it just failed to display "add to cart" button.
I want to try your "copy the code" way now. Unfortunately, you didn't even mention where should this piece of code be copied to?
Still to this file, say /components/com_virtuemart/views/productdetails/tmpl/default.php ?
Where should I put this piece of code to? starting from which line? ending at which line?
BTW, which version of VirtueMart are you using?
Thank you very much.
Best Regards
Pei
--- Quote from: legal on September 17, 2011, 03:49:09 AM ---Ok I finally figure it out. Problem was when php want to call product ID and Name. If you copy all code from /components/com_virtuemart/views/productdetails/tmpl/default.php, this piece of code can't call product ID or Name (<?php echo $this->product->virtuemart_product_id ?>), what you have to do is very simple, just delete "this->" so you get this: <?php echo $product->virtuemart_product_id ?>
Or just copy the code bellow:
--- 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>
--- End code ---
Hope this will work for everybody
--- End quote ---
jiapei100:
Hi, chadgarber:
Unfortunately, VirtueMart 2.0.6 doesn't even have these lines:
--- Quote ---
--- Code: ---<?php // Product Details Button
echo JHTML::link($product->link, JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'),
array('title' => $product->product_name,'class' => 'product-detail\s'));
?>
</p>
--- End code ---
PASTE THE CODE HERE!!!!!!!!!!!!!!!!
--- Code: --- </div>
<div class="clear"></div>
</div>
</div>
<?php
$iBrowseProduct ++;
// Do we need to close the current row now?
--- End code ---
--- End quote ---
in file "/var/www/joomla/components/com_virtuemart/views/category/tmpl/default.php" .
So, for VirtueMart 2.0.6 users, what to do???
Best Regards
Pei
--- Quote from: chadgarber on January 18, 2012, 10:51:40 AM ---Nice. This did the trick. Thanks for the clarifications.
--- Quote from: lipixx on December 01, 2011, 15:39:16 PM ---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"),
http://stackoverflow.com/questions/1536660/jquery-click-event-handler-is-called-twice-for-a-checkbox
EXPLANATIONS ABOUT THE PROBLEMS OF THIS POST:
I don't understand why this feature is not active by default. As some people commented here it is a very useful option and it would be a check into the Virtuemart configuration
to enable/disable the fetaure.
Furthermore, I found difficulties reading this post. For this reason I will write this here:
The procedure that you must follow in order to display the "ADD TO CART" button and "QUANTITY" box, when you are viewing a page with virtuemart Categories listed is:
1. Copy with ctrl+c the code of the first post of this thread.
2. Edit the file: /var/www/joomla/components/com_virtuemart/views/category/tmpl/default.php
3. Insert the copied code between the following lines:
--- Code: ---<?php // Product Details Button
echo JHTML::link($product->link, JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'),
array('title' => $product->product_name,'class' => 'product-detail\s'));
?>
</p>
--- End code ---
PASTE THE CODE HERE!!!!!!!!!!!!!!!!
--- Code: --- </div>
<div class="clear"></div>
</div>
</div>
<?php
$iBrowseProduct ++;
// Do we need to close the current row now?
--- End code ---
4. Save and close. The buttons will appear.
5. If you try to click on + and - buttons, you will see that the quantity of the product is increasing/decreasing by 2. It's because the click event is passed to the "input" element, and also passed to another element. It makes that the function of clicking gets executed two times. In order to solve this, read the top of this post that deals with modificating the file vmprices.js.
MY TEMPLATE DESIGN PROBLEMS:
I am having problems with the button colors, aspect, etc. I would like to change the button to a smallest and less abusive button, but only in the Categories page. I tried to change the line in the default.php (the one that I modified some lines ago in this post) that says:
--- Code: ---<input type="submit" name="addtocart" class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
--- End code ---
Changing the class="addtocart-button" , to "addtocart-button-smaller", and creating a class into the .css file. The button appears as I want, but it does not run.... while I am writing these lines I see the problem. When I click the button the JQuery function that adds the products to the cart does not get executed, because the function is executed only for certain classes. So I see.. I have to modify vmprices.js and I suppose that I have to modify it adding:
addtocart-smaller = cart.find('input.addtocart-button-smaller'),
And adding a function for this:
addtocart-smaller.click(.... identical content of addtocart.click(...) });
Ok!
That's all for me ;)
--- End quote ---
--- End quote ---
srajca:
I had this working perfectly in VM 2.0.6 but now it's not working when I upgraded to VM 2.0.8. Any suggestions?
outthebox:
I used this code and it works beautifully... however I really need someone to help with a slight modification:
Using the code as is, the button is available to anonymous viewers - I need this disabled when unregistered viewers are browsing the store and visible to registered visitors.
I am using VM 2.0.8a on Joomla 2.5.6
Help with this would be greatly appreciated. Thanks in advance.
srajca:
@outthebox
could you please share your code with me since I cannot get mine to work after an update?
Thank you,
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version