Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-02-16 22:09:38

ricoschette
Member
From: Estonia
Registered: 2005-09-17
Posts: 176

Put calculator inside TXP

I have new website on TXP now and ready to launch very soon.

One more thing I have to do is to put a calculator on the website.
This calc is for adding up following costs:
1. Price of a product (in eBay in Euros)
2. Transportation from Germany
3. Weight
And the results are displayed both in Euros and in another currency.

So, I guess little thingy for php-mastering-people :)
Old website runs on CakePHP I think and this calc is built in with the order form.
I browsed the webserver and it was there, all php…

Now, I wonder how to create similar at my website?
I’ve looked for scripts on the web, but haven’t found anything similar yet.

Last edited by ricoschette (2008-02-18 20:28:28)

Offline

#2 2008-02-16 22:23:56

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Put calculator inside TXP

If you provide the conversion factors for those three things, it’d be easy to create a calculator. As far as running a PHP form in TXP, see this.

Offline

#3 2008-02-16 22:28:22

ricoschette
Member
From: Estonia
Registered: 2005-09-17
Posts: 176

Re: Put calculator inside TXP

Thank you!

Offline

#4 2008-02-18 20:56:54

ricoschette
Member
From: Estonia
Registered: 2005-09-17
Posts: 176

Re: Put calculator inside TXP

I don’t know if this information is useful, but I found these files from web server (old website’s CakePHP folders):

Last edited by ricoschette (2008-02-18 20:57:13)

Offline

#5 2008-02-18 22:10:47

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Put calculator inside TXP

ricoshette, how do you calculate a price? “price of a product + transportation + weight” (from your email) doesn’t make sense. If you provide a number (factor) for the following, then we can get somewhere.

  • Transportation – how much do you charge?
  • Weight – how much per kilogram (or whatever unit)?

Offline

#6 2008-02-19 00:15:10

ricoschette
Member
From: Estonia
Registered: 2005-09-17
Posts: 176

Re: Put calculator inside TXP

Well, it’s pretty simple actually.
Transportation costs are there with the eBay product.
Now, cost to my country from Germany depends on weight.
For that there’s a long list in a file (‘order_controller.php’), just see it.

For example let’s take random product from eBay.de: Ipod Classic 80GB
1. It costs 160,90 EUR = “price of a product”
2. The transportation costs 7,90 EUR (inside of Germany borders) = “transportation”
3. Weight is 140 g = 0,2kg perhaps?

Now, the weight costs should be written were are lines:

if($weight <= 2){$package_price = 125; }
elseif($weight <= 5){$package_price = 250; }
etc…

This calc should display two outcomes: price in Euros (EUR) and Estonian Crowns (EEK) (1/15.685)
There’s line like that should give these 2 outcomes:

//EEK
$totalPriceEek = $local_package_price + $package_price + 15.685*1.1*$Order_price + 15.685*$Order_transport_price;
//EUR
$totalPrice = $totalPriceEek/15.685;

Damn, it all sounds pretty complicated. But I’m sure it’s not.
If you need more php files from old website, I’d be more than happy to give them.

Tnx

Last edited by ricoschette (2008-02-19 00:15:45)

Offline

#7 2008-02-19 01:31:51

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Put calculator inside TXP

It actually seems like you’ve got it. Just wrap it in <txp:php> and extract custom field values.

<txp:hide>Inside an article form:</txp:hide>
<txp:php>
$weight = $thisarticle['weight']; //weight = custom field
$package_price = $thisarticle['price']; //price = custom field
$transportation = 7.90; //could be a custom field

//price code
</txp:php>

Last edited by jm (2008-02-19 01:32:57)

Offline

#8 2008-02-19 10:50:14

ricoschette
Member
From: Estonia
Registered: 2005-09-17
Posts: 176

Re: Put calculator inside TXP

And it’s working. :)
Just take a look at the link at the first post.

Oh yes, I used javascript, not php.

Last edited by ricoschette (2008-02-19 12:29:39)

Offline

Board footer

Powered by FluxBB