[Pro] Cost Calculations?

Hi All
I’m probably asking the impossible (again) but I have been posed with a request from a client and I need to know if it is at all possible with Freeway.

My client designs murals printed on wallpaper and his designs can be printed at any size and priced per square metre.

When a customer chooses a design, they then enter the size they require length x height. i.e. [2.4] x [1.7]

The script then has to calculate the area and multiply by the cost per sq m, so if the cost per sq m is £40, the total cost would be £163.20 and this then appears in the cost field before then adding to the basket.

Deos anyone know of a way of doing this, especially using Mals-e.

As usual, any help and input is very much appreciated.

Cheers

Tim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Is the wallpaper not printed at a specific width?

It would be very strange to have variable widths.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The wallpaper can be printed to any size you require. The width of the actual paper is a fixed width, but the design may be printed across several rolls of paper, much like how billboards are printed. Therefore, if you wanted a design to cover a 4m long wall, it would be printed onto perhaps 3 rolls of paper whereas if it was for a 6m wide wall, it would be printed across 5 rolls. Each one is printed to order.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This is very easy to do in JavaScript, but hopelessly insecure. What type of cart are you using? Maybe there’s a way to do this where people can’t rob you quite so easily.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Would it not then be easier to sell it by the roll! With a price per roll depending on the design.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter: The intention is to use Mals and PayPal for the cart and payment. Really, the script is only to calculate a quantity of square metres and have Mals use that value as the quantity for the cart. It would be great if Mals would accept a quantity to 2 decimal places. To be honest I haven’t tried that yet so I don’t know if it can’t! Who was it that wrote that Actions for Mals?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Oh yes, it was Tim Plumb wasn’t it


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Seriously though would it not be easier (and more secure) for the customer to enter his height and length into a javascript calculator which will then calculate the number of rolls required.

The customer then buys that number of rolls.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Give each of your form inputs an ID using the Item / Extended dialog
or the Classify Action, and apply Protaculous to the page so you get
all the Prototype niceties. Let’s assume you have given them the
following: length, width, and total_cost.

Click on the top Function Body button in Protaculous, and paste in the
following:

var f = $(document.forms[0]);
var updater = function(elm,values){
	vars = values.toQueryParams();
	 $('total_cost').setValue(
		(Math.round(
			vars['length'] *
			vars['width'] *
			40 * 100) / 100).toFixed(2));
}
new Form.Observer(f,0.3,updater);

This makes the following assumptions:

  1. You have only one form on your page.
  2. You have set the form fields to have precisely these IDs (and
    Freeway doesn’t set IDs on form fields by itself, so you have done
    this step by hand or by Action).
  3. Your Pounds per square meter number is 40 (set in the 8th line).

When I enter the dimensions you noted, I get the price you quoted.

So this gives you a price for the dimensions. But you need to send the
square meters number back to your cart. If you know the name of that
form element (and have set an ID on it as well) then you can extend
the function above to read like this:

var f = $(document.forms[0]);
var updater = function(elm,values){
	vars = values.toQueryParams();
	var area = vars['length'] * vars['width'];
	$('total_cost').setValue(
		(Math.round(area *
		40 * 100) / 100).toFixed(2));
	$('total_area').setValue(area);
}
new Form.Observer(f,0.3,updater);

In this example, I have given that form field the ID of total_area. So
this would pass the total area calculated back to the cart, along with
the height and width. The area would be multiplied by the price per
meter2 at the cart side of things, so you would have a double-check.
(Never accept the customer’s version of the total price!)

Walter

On May 14, 2010, at 1:36 PM, DillyDog wrote:

Hi All
I’m probably asking the impossible (again) but I have been posed
with a request from a client and I need to know if it is at all
possible with Freeway.

My client designs murals printed on wallpaper and his designs can be
printed at any size and priced per square metre.

When a customer chooses a design, they then enter the size they
require length x height. i.e. [2.4] x [1.7]

The script then has to calculate the area and multiply by the cost
per sq m, so if the cost per sq m is £40, the total cost would be
£163.20 and this then appears in the cost field before then adding
to the basket.

Deos anyone know of a way of doing this, especially using Mals-e.

As usual, any help and input is very much appreciated.

Cheers

Tim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Brilliant as ever Walter!

customer to enter his height and length into a javascript calculator which will then calculate the number of rolls required.

I see the flaw in my plan - there is no fixed length of roll as it depends on the height of the wall.

Never mind - Walter to the rescue. And of course this can be easily adapted for many scenarios.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

WOW! I want to have Walter’s babies!

I can’t wait to try this, but I now have to wait 'till Monday. I shall let you know how it goes.

Cheers Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Just a quick observation - this gives the total_area result to many decimal places.

Can I suggest that the line

$('total_area').setValue(area);

should be

$('total_area').setValue((area).toFixed(2));

Or does that screw up the double-check?

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I have no idea what the double-check would be. You would have to look at the cart expects and what it can deliver on the calculation side. It may be that two decimals is all you need, and then this would certainly make the form look neater.

My thought initially was that this area value would actually populate a hidden form field that would be sent to the cart, and while the customer would see the price as calculated by the function, the cart would just get an SKU and an area out to 9 decimal places if it could handle it. The customer wouldn’t be looking at it, so why not be precise, eh?

For further form element fun, set the total_cost field to disabled using the Extended dialog. Click new, then enter Name: disabled and Value: disabled in the fields. The JavaScript will still be able to update the value, but the customer won’t be able to change the numbers at all.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter,
Could you possibly send me a sample page with the required form elements.

I’m afraid I’m having a little trouble getting my non-coding head around this. I assume I will need fields for height, length, total cost and a button for calculate. I’m not sure where the calculate button comes in to the equation.

I have set up a Mals-e account for this site and I also don’t quite understand how the Mals form elements come into play.

Many thanks

Tim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

fields for height, length, total cost and a button for calculate. I’m not sure where the calculate button comes in to the equation.

There is no ‘Calculate’ button because the script does an auto calculation for you. It actually observes the height and length fields and updates total cost when the others change.

Example here http://www.deltadzine.net/test/calculator.html

Tell us your email address and I will send you a FW page - remember the FWT site obfuscates email addresses. Post as yourname(at)yourdomain.com

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

tim (at) tandjdigital (dot) co (dot) uk
Thanks David.

Will this also show me how it integrates into Mals? i.e. do I still use the Mals Actions to create a Buy button? And can I put all this in a table without any problems?

Cheers

Tim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Visit the link again http://www.deltadzine.net/test/calculator.html for a download linkl - you might need to refresh.

No this wont show you how to integrate. This will give you the correct amount and it is up to you to target your Mals input amount field from the script.

In the example the 2 fields that display the cost and the area have IDs of total_cost and total_area

If you then give the Mals quantity field the correct ID (total_area) then it will autopopulate with the result of the calculation from the width and length fields. In theory!

Try it and let us know how you get on.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi D

Well, I’ve got the script working, but getting it to integrate with Mals is proving to be somewhat tricky.

As soon as I place a Buy button on the page, either in the table with the rest of the fields, or on its own, the script stops working.

Any ideas?

Tim


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Tim - post a link to your page so we can see the code.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter did say

This makes the following assumptions:

You have only one form on your page.

So there must be a tweak required.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options