Hi
In the file: components/com_virtuemart/assets/js/vmprices.js
There is that function which seems to be triggered when we would like to update the product's cart form or part of it (like prices):
Virtuemart.product = function(carts) {
carts.each(function(){
var cart = jQuery(this),
quantityInput=cart.find('input[name="quantity[]"]'),
plus = cart.find('.quantity-plus'),
minus = cart.find('.quantity-minus'),
select = cart.find('select:not(.no-vm-bind)'),
radio = cart.find('input:radio:not(.no-vm-bind)'),
virtuemart_product_id = cart.find('input[name="virtuemart_product_id[]"]').val(),
quantity = cart.find('.quantity-input');
var Ste = parseInt(quantityInput.attr("step"));
//Fallback for layouts lower than 2.0.18b
if(isNaN(Ste)) { Ste = 1; }
this.action ="#";
plus
.off('click', Virtuemart.incrQuantity)
.on('click', {cart:cart}, Virtuemart.incrQuantity);
minus
.off('click', Virtuemart.decrQuantity)
.on('click', {cart:cart},Virtuemart.decrQuantity);
select
.off('change', Virtuemart.eventsetproducttype)
.on('change', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);
radio
.off('change', Virtuemart.eventsetproducttype)
.on('change', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);
quantity
.off('click blur submit', Virtuemart.quantityErrorAlert)
.on('click blur submit', Virtuemart.quantityErrorAlert)
.off('keyup', Virtuemart.eventsetproducttype)
.on('keyup', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);
var addtocart = cart.find('button[name="addtocart"], input[name="addtocart"], a[name="addtocart"]');
addtocart
.off('click submit',Virtuemart.addtocart)
.on('click submit',{cart:cart},Virtuemart.addtocart);
});
}
What missed here is that the user can click anything to change the product's state.
In my case i have a custom field using checkboxes which does not trigger the update function now.
I suppose that others would have a calendar which uses just divs or any other element since custom fields are very flexible.
I changed the function to be more generic including any type of custom field:
Virtuemart.product = function(carts) {
carts.each(function(){
var cart = jQuery(this),
quantityInput=cart.find('input[name="quantity[]"]'),
plus = cart.find('.quantity-plus'),
minus = cart.find('.quantity-minus'),
customfield = cart.find('[name^=customProductData]:not(.no-vm-bind)'),
virtuemart_product_id = cart.find('input[name="virtuemart_product_id[]"]').val(),
quantity = cart.find('.quantity-input');
var Ste = parseInt(quantityInput.attr("step"));
//Fallback for layouts lower than 2.0.18b
if(isNaN(Ste)) { Ste = 1; }
this.action ="#";
plus
.off('click', Virtuemart.incrQuantity)
.on('click', {cart:cart}, Virtuemart.incrQuantity);
minus
.off('click', Virtuemart.decrQuantity)
.on('click', {cart:cart},Virtuemart.decrQuantity);
customfield
.off('click', Virtuemart.eventsetproducttype)
.on('click', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);
quantity
.off('click blur submit', Virtuemart.quantityErrorAlert)
.on('click blur submit', Virtuemart.quantityErrorAlert)
.off('keyup', Virtuemart.eventsetproducttype)
.on('keyup', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);
var addtocart = cart.find('button[name="addtocart"], input[name="addtocart"], a[name="addtocart"]');
addtocart
.off('click submit',Virtuemart.addtocart)
.on('click submit',{cart:cart},Virtuemart.addtocart);
});
}
I hope to be useful
I like your idea, but I think we should use a class for that. Instead of a name. So we can controll better, what we want to bind, or not.
Agree. The class would be a cleaner solution.
I don't know how the 3rd party devs will comply with the use of certain classes in their layouts.
customfield = cart.find('[name^=customProductData]:not(.no-vm-bind)'),
Can you write a js which combines that with a class, lets say vm-recalculate?
I suppose something like that:
customfield = cart.find('[class=vm-recalculate]:not(.no-vm-bind)'),
But i think that you should 1st fix the script to work with existing plugins
yeh, I mean a combination of both