I've got a 3rd party extension that implements the following:
For certain products the customer is sent from the product details page to a special page as an extra step. This works perfectly from the category and list views, but not from the product details page. The correct custom URL is posted to, but it uses AJAX instead of a real POST, so it doesn't actually display the page. I need to fix or workaround that.
According to docs and forums this can be achieved by passing bindSubmit=false to the init of validate-product.js.
Here's what I tried. It doesn't seem to have any effect at all.
# addtocart.phtml <?php $postOrAjaxBool = $_product->getSpecificSomething() ? 'false' : 'false'; ?>
<script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/js/validate-product": { "bindSubmit": <?=$postOrAjaxBool?> } } } </script>
# Rendered HTML <div class="product-add-form"> <form data-product-sku="some product" action="https://dev.someurl/modulename/cart/edit/product/4311/" method="post" id="product_addtocart_form" novalidate="novalidate"> <input type="hidden" name="product" value="4311"> <input type="hidden" name="selected_configurable_option" value=""> <input type="hidden" name="related_product" id="related-products-field" value=""> <input type="hidden" name="item" value="4311"> <input name="form_key" type="hidden" value="yakkitysmack"> <!-- thisoneisused addtocart.phtml bindsubmit = true --> <div class="box-tocart"> <div class="field qty"> SNIP </div> </div> <div class="actions"> <button type="submit" title="Bewerken" class="action primary tocart" id="product-addtocart-button"> <span>Bewerken</span> </button> SNIP </div> </div> </form> </div>
No for the actual questions:
Why doesn't this work?
Is validate-product indeed the right way to go at it or am I missing something?
Solved! Go to Solution.
I worked around this by not running the x-magento-init at all for the applicable products.
Apparently the bindSubmit works differently than expected:
bindSubmit = true means the page reloads and shows any validation or success messages.
bindSubmit = false does not reload the page.
But it's always an AJAX request.
I probably bypassed the validation that way, but I'll try to reanable that by adding the init for Magento_Catalog/product/view/validation.
I worked around this by not running the x-magento-init at all for the applicable products.
Apparently the bindSubmit works differently than expected:
bindSubmit = true means the page reloads and shows any validation or success messages.
bindSubmit = false does not reload the page.
But it's always an AJAX request.
I probably bypassed the validation that way, but I'll try to reanable that by adding the init for Magento_Catalog/product/view/validation.