Hi,
I need to use this method in my custom component that works with Virtuemart 2 to add a product to cart :
<input type="submit" url='<?php echo JRoute::_("index.php?option=com_virtuemart&view=cart&task=addJS&format=json"); ?>' title="Add to Cart" value="Add to Cart" id="btn_addtocart" class="bttn right" name="addtocart">
<script>
jQuery("[name=addtocart]").click(function(e){
e.preventDefault();
var url = $(this).attr('url');
jQuery.ajax({
type:"POST",
url: url,
async:false,
data:'quantity=2&virtuemart_product_id=218',
success: function(html){
alert('OK');
}
});
location.reload();
});
</script>
Could someone tell me if it's possible to add a custom field value like CustomPlugin Textinput with this method?
I know the form method but I would prefer to use it with the method above
<input class="vmcustom-textinput" type="text" value="test" maxlength="100" name="customPlugin[221][textinput][comment]">
<input type="hidden" value="221" name="customPrice[0][3]" />
Thanks !
you can add it to the string e.g. then the data will be quantity=2&virtuemart_product_id=218&your_var=5
but then you have to do something with it where it's posted
Thanks for you answer.
Quote from: GJC Web Design on July 11, 2014, 10:56:35 AM
but then you have to do something with it where it's posted
Could you tell me a bit more about doing something with it?
In fact, I think I really need to use a form to add custom filed. Could you tell me what's the minimum informations I need to add to cart? Here is my code but it doesn't work :
<form method="post" class="product" action="index.php" id="addtocartproduct218">
<span class="quantity-box">
<input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>
<span class="addtocart-button">
<input type="submit" name="addtocart" class="addtocart-button" value="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'); ?>" title="<?php echo JText::_('COM_VIRTUEMART_CART_ADD_TO'); ?>" />
</span>
<input type="hidden" class="pname" value="Montre Configurée">
<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="218" />
</form>
I've just found the solution :
<script>
jQuery("[name=addtocart]").click(function(e){
e.preventDefault();
var url = $(this).attr('url');
jQuery.ajax({
type:"POST",
url: url,
async:false,
data:'quantity=1&virtuemart_product_id=218&customPlugin[221][textinput][comment]=test&customPrice[0][3]=221',
success: function(html){
alert('OK');
}
});
location.reload();
});
</script>