I'd like to offer help, but man this is grueling stuff. It's very hard for me to understand what each of these lines are accomplishing. A lot of it seems to be checking to make sure the entries are both numeric and not negative.
Also, anything we give you here runs the risk of not aligning well with the rest of the WorldPay code. So this is where I would turn to WorldPay support. What you want to implement is a relatively simple discount scheme, and I'd assume that they have some basic support and instructions somewhere - they are certainly a big enough operation.
The needed logic seems clear enough. The total purchase price is
unitprice + ((quantity-1)*unitprice/2)
The rest of the code seems to be involved with guaranteeing the integrity of the price and quantity variables.
Thanks, but I already tried WorldPay and gor this response :-
"We don't offer support for this code as it can be a lengthy process to correct a simple error."
Do you know what language the function has been written in? Do you know of any web resources which would be able to help?
The bit you need to change is the
a += (b * c);
This might not be a solution but it gets away from focusing on the code and techie stuff. A couple of low-tech folks I know offer volume discounts as separate items or products.
Product A 1 copy at $500
Product B 2 copies at $750
Product C 3 copies at $1,000
Might be a simple to implment fix.
hmm. It seems that "x" is an element and shouldn't be able to simply be put into the function without "var x=document.getelementbyid(text1)". I think you may have missed something out.
|The bit you need to change is the |
a += (b * c);
That's true. With absolutely no guarantee, and suggesting you test any code that you create before putting it into production, I can say I would try this change as a first shot:
a += (b + b*(c-1)/2)
As and added comment, one thing that concerns me here is why the existing code uses the += operator when the variable a "should" be zero. It seems to me that a simple = would do the job. So there may be some logic behind the existing code that I just don't see.
What I have done is amend the code as follows :-
This seems to resolve part of the problem and does calculate the correct discount for the first item on the page. However, I have 5 items and implementing this code results in a zero value being returned if any of the other 4 items are selected.
One step forward ....
Good luck to you. Just keep playing with the code in logical ways and pin down what all the parts are doing.
I can see you'll hit a snag if the other items don't use the same discount scheme.
I also note that you used the plain = operator. Experiment with the += operator. That may play into the problem you already found.
Looks like it should be:
or with a,b,c:
Thanks for the help. In the end I went to [forums.webdeveloper.com...] and paid somebody $50 US to sort it out for me. Seems to have done the trick and does exactly what was needed.