News:

Support the VirtueMart project and become a member

Main Menu

Add to cart submit button with custom value

Started by spinoops, July 11, 2014, 09:12:24 AM

Previous topic - Next topic

spinoops

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 !

GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

spinoops

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>

spinoops

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>