F
F
Feyvor2018-11-02 15:59:30
1C-Bitrix
Feyvor, 2018-11-02 15:59:30

How to convert one currency?

Good afternoon, please tell me how to solve this problem:
The main currency on the site is rubles, most of the goods are unloaded from 1c to $, then the conversion takes place with this line:

$price = CCurrencyRates::ConvertCurrency($ar_res["PRICE"], "USD", "RUB");

BUT, there are also some goods in rubles in 1s, respectively, this line also translates the ruble goods into $.
The question is how to transfer only $ goods, but at the same time not touch the ruble?
The code fragment where this operation takes place is also my attempt at a solution, which, unfortunately, did not lead to any result:
$db_res = CPrice::GetList(
        array(),
        array("PRODUCT_ID" => $PRODUCT_ID,"CATALOG_GROUP_ID" => $PRICE_TYPE_ID)
    );
  if ($ar_res = $db_res->Fetch())
  {	
    //print_r($ar_res);
      if ($ar_res["PRICE"] == 'RUB' || $ar_res["PRICE"] == 'RUB')
        $ar_res["PRICE"] = $price; 
      else
      	$price = CCurrencyRates::ConvertCurrency($ar_res["PRICE"], "USD", "RUB");
      
  }
  else
    $price = 0;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2018-11-05
@winer

Since you're only using currency conversion for output in the template, it's easier to set up the component itself correctly. He knows how to do it by standard means and only where necessary.
the catalog.element and catalog.section components have " CONVERT_CURRENCY "
=> "Y"
"CURRENCY_ID" => "RUB" parameters works through a complex directory component. Then these parameters will need to be set in the complex component and ensure that they are passed to catalog.element and catalog.section

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question