I am working on a project (and actually finished) that selects price quotes based on user input. I already wrote the code and it works great. This is written in javascript / jQuery, using events and functions more similar to this (for example, I just wrote for this question, not the actual code):
$('input[name=quantity]').change(function(){
var product = $('input[name=product]').val();
setBasePrice(this.value,product);
});
function setBasePrice(quantity,product){
var basePrice = quantity * getTierPrice(quantity,product);
$('.basePrice').empty().val(basePrice);
};
function getTierPrice(quantity,product){
};
There are many more working parts, but I wrote this to illustrate how it stacks up. It just seems verbose and a lot of moving parts. When the time comes to upgrade it, it’s a pain.
, - ? javascript , - . , , , , , , , .
, , . , :
Things I'm expecting
= zip code (number)
= product (string)
= quantity (number)
- Need to verify number is between x and y (e.g. - 100 to 10000)
= artwork colors (number)
- Need to verify number is between x and y (e.g. - 0 to 6)
Things I'm calculating
= base price (number)
- Depends on the product selected
- Depends on the quantity entered (6 tiers of pricing based on quantity)
e.g. - "Product 1" quantity of 101 to 200 = $9, quantity of 201 to 300 = $7, etc
= screen charge (number)
- Depends on the number of artwork colors entered
- Depends on the quantity entered (uses same tier as when calculating base price)
e.g. - "Product 1" quantity of 101 to 200 add 1.00 per artwork color
- Gets rolled into the base price
e.g. - base price = base price + (artwork colors*quantity);
= shipping cost (hits url via ajax to fetch rate, returns number)
- Depends on zip code entered
- Depends on product selected (each product has different weight)
Things I need to output
= final price
= shipping cost
= base price
, , YUI? , , ? , , . , . , .. .