everyone. I need to calculate price in my store by formula: price = ((cost in other currency) * (currency rate) + (fixed markup)) * (markup in percents) or (manual price) if set. I found a few payable addons, that could help, but all of them can have only one type of markup for one product. So it looks like I need to extend core functionality by my own. Is there other possibilities? If no, could you advise me something to get started?

Essentially i would like to add different currency prices and allow them to be converted by my base currency. e.g shirt=$20 i must be able to add it as $20(creating an attribute called _foreign_price) on the csv as $ and once uploaded it should convert that price of the shirt to pounds. Is this possible?


You could try the following event-observer based approach, config.xml:



public function catalogProductPrepareSave($observer){
    $product = $observer->getEvent()->getProduct();
    $cost = $product->getCost();
    $foreign_price = $product->getForeignPrice();
    $foreign_currency = $product->getForeignCurrency(); //for example USD
    $markup = $product->getMarkup();
    $usd = $this->getXchange($foreign_currency); //we're using USD as the example
    $product->setPrice($cost * $usd * $markup);

 * Method which uses the Yahoo finance API to get current value x-rates
public function getXchange($currency){
    if ($currency == 'USD'){
        $from = $currency;
        $to = "desired currency"; //example: AUD
        $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';
        $handle = @fopen($url, 'r');
        if ($handle) {
            $result = fgets($handle, 4096);
        $allData = explode(',',$result);
        $xchange_value = $allData[1];
        return $xchange_value;

This means that each time you save a product, the pricing calculation will take effect. You will need to implement your own attributes (i.e foreign_price, foreign_currency, markup etc) and make sure that these attributes are included in the product model.

You will need to put security precautions into place to ensure that pricing is never miscalculated or too low, but that's up to you. I've given you a broad overview of a real-world example that could do what you've outlined. The rest is up to you.

By the way:

I've used an example of event-observer, it would be much more practical to implement this in a function which you can set up to run via cron so that your products are constantly up-to-date with the current rate of exchange. You would basically use the function outlined above in a loop on your product collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.