spree-contrib-variants / spree_product_customizations

A newer version of half of spree_flexi_variants (only the product customizations functionality)
BSD 3-Clause "New" or "Revised" License
4 stars 3 forks source link

Backend validation for area calculator #11

Open nooysters opened 8 years ago

nooysters commented 8 years ago

There doesn't seem to be any backend validation for the area calculator. I am able to use letters for instance. It will default to the minimum area price but it still makes for a confusing customer experience. I am happy to add validation but am not sure which model to edit. Any guidance appreciated.

sfcgeorge commented 8 years ago

I don't think there's a specific model as it monkeypatches stuff, so I don't think you'll be able to do anything as simple as validates_numericality_of :width for example. The validation should probably go with the calculator logic, and there is a method in there for checking whether it's valid: https://github.com/spree-contrib-variants/spree_product_customizations/blob/master/app/models/spree/calculator/product_area.rb#L48

Now I have no idea what happens if it's not valid—does it give the user a nice error? I'm not super optimistic but I think that's your starting point. If it doesn't make a nice error you could try doing something with the variant passed in but I don't think that will help as if I remember correctly it's a new blank Variant not the actual LineItem being edited—which I think is silly but it's too late to change how Spree works now.

Anyway feel free to let me know progress, it's a good idea :)

nooysters commented 8 years ago

When it fail the calculator validation i just uses the base price regardless of area. I will play with it and see what I can do. Thanks for the tips!