Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

product id to be used in currency class


HairyJim

Recommended Posts

I was thinking of changing the display_price function to accept the product id but I am wondering if there is perhaps a better way of doing this?

 

All I want to be able to do is query the products table from within the currency class and I need the product_id to be able to do this accuratly.

 

Anyone got thoughts on this?

Link to comment
Share on other sites

I was thinking of changing the display_price function to accept the product id but I am wondering if there is perhaps a better way of doing this?

 

All I want to be able to do is query the products table from within the currency class and I need the product_id to be able to do this accuratly.

 

Anyone got thoughts on this?

 

the currencies class is there to display any number in the right currency format with/without tax and as such has nothing to do with products.

What are you trying to do ?

Treasurer MFC

Link to comment
Share on other sites

the currencies class is there to display any number in the right currency format with/without tax and as such has nothing to do with products.

What are you trying to do ?

 

HI,

 

Once again you reply to my posts - are you the only user :thumbsup:

 

I do not wish to use the currency conversion.

 

Basically I want my products to have three prices; GBP, EUR and USD.

 

When the user changes currency I want the system to choose the price from the table not return the GBP * Exchange rate.

Link to comment
Share on other sites

HI,

 

Once again you reply to my posts - are you the only user  :thumbsup:

 

I do not wish to use the currency conversion.

 

Basically I want my products to have three prices; GBP, EUR and USD.

 

When the user changes currency I want the system to choose the price from the table not return the GBP * Exchange rate.

 

well, then I would make a separate function called

get_product_price ($products_id)

 

in that function you query the products table for the price given the current currency setting, so either your retrieve the USD price or the EUR price, etc.

Then you have that function return the $currency->display_price($the_retrieved_price) result.

 

 

the display_price function in the class currencies:

 

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

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

}

 

calls the format function in the same class. That function has more parameters:

 

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

 

so you could change the function display_price to :

 

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

return $this->format(tep_add_tax($products_price, $products_tax) * $quantity, false);

}

 

which would prevent the exchange rate calculation.

 

And last in your common code you can just state :

 

echo 'Price: ' . get_price($products_id);

 

 

ofcourse you could add all this to the class itself but that would eliminate the meaning of using classes (separation of function) and would result in much more messy and more difficult to maintain code. Certainly if that class is used in many locations for a variety of reasons and purposes.

Treasurer MFC

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...