N
N
Natalia2020-07-23 12:17:35
1C-Bitrix
Natalia, 2020-07-23 12:17:35

How to display the price in the detailed description?

Please, tell me how to write the price {=this.catalog.price.4} in the HTML of the detailed product description. How to write it?
It is necessary that in the detailed description it goes something like this: You can buy this product at a price of.... rub.
Help plz!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-07-27
@Naly

In the detailed description, write text text text ... You can buy this product at the price of #PRICE_1# rub. .... text text text
#PRICE_1# is a macro, in which 1 is the ID of the desired price type (here, if desired, a symbolic price code can also be used)
If on the example of simple goods, the code looks something like this

if($arResult['DETAIL_TEXT']) {
  $arPrices = $aSearch = $aReplace = array();

  preg_match_all('/#PRICE_\d#/', $arResult['DETAIL_TEXT'], $matches);
  
  if($matches[0]) {
    $iterator = \Bitrix\Catalog\PriceTable::getList([
      'select' => ['CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'],
      'filter' => ['PRODUCT_ID' => $arResult['ID']]
    ]);

    while($row = $iterator->fetch()) {
      $arPrices[$row['CATALOG_GROUP_ID']] = CCurrencyLang::CurrencyFormat($row['PRICE'], $row['CURRENCY']);
    }
    
    $aSearch = $matches[0];
    
    foreach($aSearch as $key => $str) {
      $priceId = str_replace(['#', 'PRICE_'], '', $str);
      $aReplace[$key] = $arPrices[$priceId];
    }
    
    $arResult['DETAIL_TEXT'] = str_replace($aSearch, $aReplace, $arResult['DETAIL_TEXT']);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question