Google

NukeCoder


View next topic
View previous topic
Post new topic   Reply to topic
Author Message
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 11:34 am
Reply with quote

Gotcha,

I want to show estimated prices for different currencies. It is not a hard function to write when you know exactly what currencies you working with, but prolly difficult if you don't.

Anyway, I doubt I can deploy such a function without you. Any thoughts? Maybe I could write the function and stick it in the index.php? Oh, I feel a headache coming Sad
 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sat Jan 10, 2009 12:30 pm
Reply with quote

Just use a template plugin Smile
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 12:32 pm
Reply with quote

Yeah, I think I can make that work. Just need to put some thought into it.
 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 2:09 pm
Reply with quote

I know you can pass one value, but can you pass two?

Code:
{conversion currency_symbol=$currency_symbol item_cost=$item.item_cost}


I might have to pass item_id and then grab all the other info.
 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 2:21 pm
Reply with quote

I changed it to just pass one variable from the .tpl. After clearing templates_c I get,

Code:
[01-10-09 01:20:22 pm][256](Line:1095) Smarty error: [in default/shop/main.tpl line 89]: syntax error: unrecognized tag 'conversion' (Smarty_Compiler.class.php, line 590) [/home/ped99/public_html/includes/smarty/libs/Smarty.class.php]


I feel like I am forgetting a step.


Code:
{conversion item_id=$item.item_id}


function.conversion.php (rough draft anyway)

Code:

function smarty_function_conversion($params, &$smarty){
require("mainfile.php");
global $db;
$item_id = intval($params['item_id']);
$sql = "SELECT item_cost, item_currency_symbol FROM shop_items WHERE item_id = '".$item_id."'";
$query = $db->sql_query($sql);
$row = $db->sql_fetchrow($query);
$item_cost = $row['item_cost'];
$currency_symbol = $row['item_currency_symbol'];
  if($currency_symbol == '£'){
     $converted = '$'.$item_cost * 2;
  }elseif($currency_symbol == '$'){
     $converted = '£'.$item_cost / 2;
  }
  $conversion =  '('.$currency_symbol.$item_cost.') ('.$converted.')';
return $conversion;
 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sat Jan 10, 2009 7:05 pm
Reply with quote

You are making it harder then it needs to be, also, if the item is discounted, the price will be way off. No need for mainfile, or any db queries in this function either. I would also pull the current exchange rate from somewhere instead of assuming 2 to 1.

In the template:
Code:
$item.item_currency_symbol {conversion item_cost=$item.item_cost item_currency=$item.item_currency}


in function.conversion.php
php:
 // make sure this file is in the tpl_plugins folder
function smarty_function_conversion($params, &$smarty){
  if(
$params['item_currency'] == 'USD') {
     
// do conversion
  
} elseif ($params['item_currency'] == 'GBP') {
     
// do conversion
  
}
  return 
$converted_currency;
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 7:10 pm
Reply with quote

My first function looked very similar to that, but as far as getting exchange rates. It much harder to find some place that keeps them updated for free.

I did notice the problem with the special discount, that one is gonna be tricky if not impossible.

I will keep playing with it soon as I finish working on www.clan-themes.co.uk/search.php

btw, I always make it harder than it needs to be jeez..
 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Jan 10, 2009 7:26 pm
Reply with quote

What is this usually caused by

Code:
[01-10-09 06:25:48 pm][256](Line:1095) Smarty error: [in default/shop/main.tpl line 89]: syntax error: unrecognized tag 'conversion' (Smarty_Compiler.class.php, line 590) [/home/ped99/public_html/includes/smarty/libs/Smarty.class.php]


My function is in the plugins folder.
 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sat Jan 10, 2009 7:43 pm
Reply with quote

It basically isn't finding that function so and that could be for many reasons. File permissions, spelling, wrong folder, wrong filename or function name format, etc.
 
View user's profile Send private message Visit poster's website
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Mon Jan 12, 2009 9:24 am
Reply with quote

Did you ever figure it out floppy?
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Mon Jan 12, 2009 10:46 am
Reply with quote

Didn't really play with it anymore yesterday. I changed the variable name to make sure it wasn't a conflict with another plugin.

Like you said, it is treating it as if it can't be found. However, my gturl (well your) function is working fine. I think CT is still running on 2.07 if that would make any difference.
 
View user's profile Send private message Visit poster's website MSN Messenger
Guardian




Joined: Dec 09, 2006
Posts: 335

PostPosted: Wed Jan 14, 2009 5:16 am
Reply with quote

http://www.phpclasses.org/browse/package/5090.html

_________________
Code Authors Nuke Reviews 
View user's profile Send private message
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Tue Jan 20, 2009 5:41 pm
Reply with quote

Thanks Guardian, the current problem is it doesn't recognize any file as a plugin. I am not sure why yet.
 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Tue Jan 20, 2009 6:45 pm
Reply with quote

I am an idiot. Gotcha gave me the answer and I just didn't realize it. "tpl_plugins". I had my mind set that it was still plugins cause all the old files were still there. I think I thought that was a 2.08 change.

Ok, on with the mod.
 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Tue Jan 20, 2009 9:18 pm
Reply with quote

http://www.clan-themes.co.uk/article363-clan-themes-shop-will-now-display-currency-conversions.html

Gotcha, do I need to do any other pages? I modified main.tpl and item.tpl. I do forsee one problem. The basic price and special price need to be added to the class. For instance, if Google can't convert it would return an error.

Things to think about.
 
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 5 Hours
Forums ©