I have a separate product – id 2256, I would like to make it possible to add it through ajax in the template – i.e. there should be a separate button on the page – what is the best way to do this, then if Success adding, i need show div with some information, can you guide me?
my solution do not work:
<form action="/checkout/cart/add/uenc/[form_key]/product/2256/" method="post" id="product_addtocart_form" data-role=tocart-form>
<input type="hidden" name="product" value="1" tabindex="0">
<input name="form_key" type="hidden" value="[form_key]" tabindex="0">
<button class="action tocart primary" type="submit" title="Add to Cart" tabindex="0">
<span>Add to Cart</span>
</button>
</form>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"bindSubmit": true
}
}
}
</script>