Jump to content
Sign in to follow this  
RobAnderson

Contribution: Friendly Pricing v1.0

Recommended Posts

Hi there,

 

I have just added my very first contribution: Friendly Pricing v1.0

 

Description

 

This contribution allows you to specify a friendly price for a product even though it may not be the default pricing currency. For example, let's say you want to sell some products targeted to a local market in one currency and want your prices to be friendly to your customers, e.g. 9.95 EURO. At the same time, you want to sell other products to a different market with friendly prices in a different currency, e.g. US $9.95.

 

Now with the way OSC is currently set up, you can only specify friendly prices in the default currency. If a customer chooses another currency, then currency rates are applied and the prices get ugly, e.g. 12.67 EURO (and it will vary from day to day as the exchange rates change).

 

So, what this contribution does is enable you to specify for each product a friendly currency other than the default. This is administered in the products page (categories.php) in the admin section.

 

Friendly pricing works in perfectly with existing exchange rates and provided you have installed the currency in the admin section, you can specify a friendly price using that currency. If you subsequently delete the currency, prices will revert back to the default currency.

 

Support has been built in for specials and all orders, reports and invoices have been modified to keep track of orders that may include a mixture of default and friendly pricing.

 

Comments

 

I am new to PHP programming (a pragmatist, not a purist), so I'm sure there may be more elegant ways to achieve the same results. If you can improve on my humble beginnings, then please contribute in this forum!

 

Thank you,

Rob Anderson

Share this post


Link to post
Share on other sites

Maybe I got that wrong in your description, but can my problem be solved with your contrib?

 

I have a shop that uses Swiss Francs as the basic currency. Now I also want to sell products to european countries. That's why I'm using EURO as a second currency. For most products, the automatic conversion made by OSC is fine for me, but for some other products I also have a fixed EURO price besides having a fixed Swiss Francs price. Let's take a book for example. The book sells in Switzerland for 29.90, and the fixed Euro price is 19.90.

 

If I enter 39.90 in the price field and as friendly price, in the catalog it shows me the ugly price like 32.88 if I use Swiss Francs as currency. Any suggestions?

 

Thx

Martin

Share this post


Link to post
Share on other sites

Hi Martin, I don't think that the Friendly Pricing contribution will help in this case. If I understand you correctly, you are after the ability to set fixed prices for the same product in two currencies.

 

What my contribution allows you to do is choose which currency you wish to fix the price in on a product by product basis, e.g. one product could have a fixed price of 29.90 Swiss Francs and another could have a fixed price of 19.90 Euro. However, having done this, the price will still vary from one currency to another (as you've discovered). What it doesn't allow you to do though, is create two fixed prices for the same product!

 

Having said that, there may be one way around it with my contribution, and that would be to create a duplicate product and assign one a fixed price in one currency, e.g. 29.90 Swiss Francs and the other a fixed price in a different currency, e.g. 19.90 Euro.

 

The only problem I can see with this is that this may cause confusion and people may wonder whether the products are actually the same as the relative prices would be different. You also open yourself up to the vagaries of currency changes, but I'm sure you're already aware of that.

 

Sorry, that's about all I can suggest, except to keep looking for other contibutions that may have the functionality you're after (multiple-shops?).

 

Cheers, Rob

Share this post


Link to post
Share on other sites

Thx Rob for your reply. It seems like your friendly pricing mod can't help me, great contrib though!

 

Is there any contribution out there which will help to solve my problem? That is:

 

For certain products (not for all) I will need to be able to set two fixed prices for the main currency which is Swiss Francs and for the other currency which is Euro. If there is only one currency set in admin, the amount will be automatically calculated using the exchange rate.

 

Any suggestions?

 

Thanks

Martin

Share this post


Link to post
Share on other sites
Is there any contribution out there which will help to solve my problem? That is:

 

For certain products (not for all) I will need to be able to set two fixed prices for the main currency which is Swiss Francs and for the other currency which is Euro. If there is only one currency set in admin, the amount will be automatically calculated using the exchange rate.

 

Any suggestions?

 

Thanks

Martin

Hi Martin, I can see what you're trying to do now and it makes perfect sense. However, I don't know of any contributions that allow that although I do know of some other people with the same requirements, e.g. moonfish (Dani).

 

Looks like you might need to create a contribution that adds in this functionality. Time to learn PHP? ;-)

 

Best of luck, Rob

Share this post


Link to post
Share on other sites

Hi Martin,

 

I'm Dani (Moonfish). As Rob said before, I'm also looking for the same solution to prices problem like you.

 

Have you found any solution? Meanwhile, I have set two different stores to two different currencies :o(

 

Thanks in advance for your support.

Best wishes,

Dani

Share this post


Link to post
Share on other sites

:D :D :D

 

I also needed what Moonfish and Martin needed, and I think I have a kludge worked out.

 

I just whipped this up tonight with no previous PHP or OSC experience, but it seems to be working -- i.e., when people switch currencies, they see that product's fixed price for that currency. I have no idea if this will work in conjunction with specials or any other features like that, but I haven't really altered too much, so here's hoping...

 

Anyway, here's what I did, in a nutshell:

 

1. Add a table to your OSC database. I called mine fixed_prices. It should have three columns: product_id, code, and products_price (and make sure that last one is called products_price, or this won't work!). This is where you'll input the product-currency price combinations. So for instance, for one of my products, whose product_id is 28, I entered two rows:

28, USD, 160

28, CDN, 200

 

2. Modify the database_tables.php file to recognize this database. I added this line under all the other "define" lines:

define('TABLE_FIXED_PRICES', 'fixed_prices');

 

3. Modify the product_info.php page so that when the product info is looked up, it looks up the price from fixed_prices, based on the product_id and currency code. The original line was this:

$product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");

 

I altered it to this (alterations in bold):

$product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, fp.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_FIXED_PRICES . " fp where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and fp.product_id = p.products_id and fp.code = '" . $HTTP_GET_VARS['currency'] . "'");

 

And that's it! I have both US and CDN configured as currencies, just like usual, with rates of 1.0.

 

Let me know if this works for you, or if you have any ideas to improve it, etc.

Share this post


Link to post
Share on other sites

:blink: Oops! Just noticed one little bug from my previous post, but it's easy to fix.

 

When the person initially comes into your store, they're using the default currency (the first currency on the list, I guess -- I can't find a default currency setting, wouldn't that be nice...?), and the currency variable isn't in the URL for us to pick up. So it ends up as a null value. What I did to fix this was allowed the code column in the fixed_prices table to have null values, and entered a third row for my product with the price for my first currency:

28, null, 200

Share this post


Link to post
Share on other sites

NOTE: This contribution does not work with the Step-By-Step Manual Order Entry contribution found here http://www.oscommerce.com/community/contri...ch,manual+order

 

Anyone made the necessary code changes to make this contribution work? I started it, but there is just so many. Since you have the ability to add new products to an existing order....

Edited by rcmdesign

Share this post


Link to post
Share on other sites

If anyone is interested, I have modified edit_orders.php to allow you to add products in their proper friendly pricing, and it calculates the total in the proper amount also. PM me if you need it....

Share this post


Link to post
Share on other sites

I need may be something different. I have USD as base currency, and rubles as default currency. So I enter prices in USD, and, since the exchange rate is like 29,21, I get ugly prices in rubles. like 2349, 41 rub.

 

What I need is to round prices in rubles. So, for example, price in rubles would be 2350 rub.

 

Does your contribution do this work?

Share this post


Link to post
Share on other sites
I need may be something different. I have USD as base currency, and rubles as default currency. So I enter prices in USD, and, since the exchange rate is like 29,21, I get ugly prices in rubles. like 2349, 41 rub.

 

What I need is to round prices in rubles. So, for example, price in rubles would be 2350 rub.

 

Does your contribution do this work?

Hi Vladamir, I'm not sure if I entirely understand your question.

 

If your default currency is rubles, and you are using the Friendly Pricing contribution with base currencies in USD, then yes, the ruble values will float with the currency.

 

However, if you want nicely rounded prices in rubles, why not then just revert back to the default currency (rubles) for those products? Of course, if you do this, then the USD value will float with the currency - you can't have it both ways! (unless there is a contribution that allows currencies to be de-coupled, which could be very confusing for customers).

 

Hope this helps, if not, please post more specific info and I'll try to help.

 

Regards,

Rob Anderson :)

Share this post


Link to post
Share on other sites

Great job Rob!

 

I've got a little question. There is a file \catalog\account_history.php included in your contribution. However, it's just a copy of the standard one. Did you forget to include a modified version of this file or the file can be omitted?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

Oh, one more thing. I get the following error when I try to add/modify some product:

 

1064 - You have an error in your SQL syntax near 'where c.code = config.configuration_value and config.configuration_value = 'USD'' at line 1

 

Select c.title from currencies c INNER JOIN configuration config where c.code = config.configuration_value and config.configuration_value = 'USD'

 

Any clue what could be wrong?

Share this post


Link to post
Share on other sites

Well, I replaced "INNER JOIN ... WHERE" with "INNER JOIN ... ON" and the error has gone. Weird. It seems only admin\categories.php is affected by this issue.

Share this post


Link to post
Share on other sites

Looks like I spent hours installing this contribution for nothing more what I had before. Yes, there's a drop down menu but whenever you set a friendly price for one currency, the other one still changes with some UNfriendly amount. Plus looks like this thread is dead from some time now ... <_<

Share this post


Link to post
Share on other sites
Great job Rob!

 

I've got a little question. There is a file \catalog\account_history.php included in your contribution. However, it's just a copy of the standard one. Did you forget to include a modified version of this file or the file can be omitted?

 

Thanks in advance.

 

Micheal, I noticed the same thing, is it relevant ? Any news on how this contrib. is working for you ?

Edited by JayWill

Share this post


Link to post
Share on other sites

Friendy Price seems to be exactly what I'm looking for. Can it be used with SPPC (Separate pricing per costumer) and if so, how do I merge them?

Edited by Fredrik.r

Share this post


Link to post
Share on other sites
:blink: Oops! Just noticed one little bug from my previous post, but it's easy to fix.

 

When the person initially comes into your store, they're using the default currency (the first currency on the list, I guess -- I can't find a default currency setting, wouldn't that be nice...?), and the currency variable isn't in the URL for us to pick up. So it ends up as a null value. What I did to fix this was allowed the code column in the fixed_prices table to have null values, and entered a third row for my product with the price for my first currency:

28, null, 200

 

Hi, thanx for your post, that helped me much and now it's my turn I hope :thumbsup:

 

First of all, I found that there is more files to edit,

here is my list of files to change p.product_price in fp.product_price:

 

advanced_search_result.php

index.php

products_new.php

product_reviews.php

product_reviews_info.php

product_reviews_write.php

specials.php

admin\categories.php

admin\special.categories.php

admin\inculdes\classes\shopping_cart.php (*product_price, not p.product_price)

admin\inculdes\function\general.php

includes\boxes\specials.php

includes\classes\shopping_cart.php (*product_price, not p.product_price)

includes\modules\news_products.php

 

I found how to avoid this "little bug" without making null value in fixed_table because I think it's not a good solution. Simply change your code part :

 

fp.code = '" . $HTTP_GET_VARS['currency'] . "'

 

with this :

 

fp.code = '" . $currency . "'

 

Well, I have not finish all my job now but I guess that can already help..

 

Bye

Share this post


Link to post
Share on other sites

hi all,

 

this contrib is just what i need, but given that i run a heavily modded shop i can't just copy the files over the existing ones - it would just mess up everything.

does anyone have a line-by-line install instructions file?

i've tried using a comparison program but the results just don't make sense to me - i'm not a programmer.

if anyone can help please post the file here or e-mail it to me at:

dasruud at gmail dot com

thanks,

 

das

Share this post


Link to post
Share on other sites
What my contribution allows you to do is choose which currency you wish to fix the price in on a product by product basis, e.g. one product could have a fixed price of 29.90 Swiss Francs and another could have a fixed price of 19.90 Euro. However, having done this, the price will still vary from one currency to another (as you've discovered).

Cheers, Rob

 

Hi Rob,

I would like to ask you some question about this contribution, I would like to be sure to understand the function:

 

My store buy some items in Dollars, some items in Yen and others in Euro.

Our standard currency is Euro.

 

Due to the critical situation of money change, I am looking for a contribution that permit to select the buy-currency I want for each item of the catalog.

If I buy an item with USD, i need to select USD as fixed value in the price field when I create the catalog item.

The same thing for Euro and Yen.

In this way I can work with exchange rates without modify the products related prices also if the fixed currency is not the default one.

 

Do you think I can do this operation with your contribution?

Do this contribution works with Specials and Products Attributes related to the fixed currency of a product?

Share this post


Link to post
Share on other sites

Hi,

 

I followed exactly the instructions... but i don't see any option in catalog section to select my friendly currency.

 

Could you please help me?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

hello,

 

i have been using this cont. since first day. i have updated to 2.3.1 just now. the currency.php produces an error.

 

old one

<?php

/*

$Id: currencies.php,v 1.16 2003/06/05 23:16:46 hpdl Exp $

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

Copyright © 2003 osCommerce

Released under the GNU General Public License

*/

////

// Class to handle currencies

// TABLES: currencies

class currencies {

var $currencies;

// class constructor

function currencies() {

$this->currencies = array();

$currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);

while ($currencies = tep_db_fetch_array($currencies_query)) {

$this->currencies[$currencies['code']] = array('title' => $currencies['title'],

'symbol_left' => $currencies['symbol_left'],

'symbol_right' => $currencies['symbol_right'],

'decimal_point' => $currencies['decimal_point'],

'thousands_point' => $currencies['thousands_point'],

'decimal_places' => $currencies['decimal_places'],

'value' => $currencies['value']);

}

}

// class methods

function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {

global $currency;

if (empty($currency_type)) $currency_type = $currency;

if ($calculate_currency_value == true) {

$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

// if the selected currency is in the european euro-conversion and the default currency is euro,

// the currency will displayed in the national currency and euro currency

if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {

$format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';

}

if (DEFAULT_CURRENCY == 'TRL') {

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) .' ' . $this->currencies[$currency_type]['symbol_right'];

} else {

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

}

}

return $format_string;

}

function is_set($code) {

if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) {

return true;

} else {

return false;

}

}

function get_value($code) {

return $this->currencies[$code]['value'];

}

function get_decimal_places($code) {

return $this->currencies[$code]['decimal_places'];

}

// Display prices taking into account friendly pricing

function display_price($products_price, $products_tax, $currency_id, $quantity = 1) {

return $this->format(tep_add_tax($products_price, $products_tax) * $quantity / tep_friendly_pricing($currency_id));

}

}

?>

new one,

<?php

/*

$Id$

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

Copyright © 2008 osCommerce

Released under the GNU General Public License

*/

////

// Class to handle currencies

// TABLES: currencies

class currencies {

var $currencies;

// class constructor

function currencies() {

$this->currencies = array();

$currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);

while ($currencies = tep_db_fetch_array($currencies_query)) {

$this->currencies[$currencies['code']] = array('title' => $currencies['title'],

'symbol_left' => $currencies['symbol_left'],

'symbol_right' => $currencies['symbol_right'],

'decimal_point' => $currencies['decimal_point'],

'thousands_point' => $currencies['thousands_point'],

'decimal_places' => $currencies['decimal_places'],

'value' => $currencies['value']);

}

}

// class methods

function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {

global $currency;

if (empty($currency_type)) $currency_type = $currency;

if ($calculate_currency_value == true) {

$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

} else {

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

}

return $format_string;

}

function calculate_price($products_price, $products_tax, $quantity = 1) {

global $currency;

return tep_round(tep_add_tax($products_price, $products_tax), $this->currencies[$currency]['decimal_places']) * $quantity;

}

function is_set($code) {

if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) {

return true;

} else {

return false;

}

}

function get_value($code) {

return $this->currencies[$code]['value'];

}

function get_decimal_places($code) {

return $this->currencies[$code]['decimal_places'];

}

 

function display_price($products_price, $products_tax, $quantity = 1) {

return $this->format($this->calculate_price($products_price, $products_tax, $quantity));

}

}

?>

 

how can we adopt?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×