Skip to content

Instantly share code, notes, and snippets.

@kossoff
Created September 22, 2015 18:26
Show Gist options
  • Save kossoff/24b25834b54dfc23e52a to your computer and use it in GitHub Desktop.
Save kossoff/24b25834b54dfc23e52a to your computer and use it in GitHub Desktop.
Для Drupal 7. Меняем значение поля price_ru в соответсвии с курсом евро с сайта ЦБ РФ. Исходная цена = price_eu
<?php
header('Content-Type: text/html; charset=UTF-8');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/module.inc';
require_once DRUPAL_ROOT . '/includes/unicode.inc';
require_once DRUPAL_ROOT . '/includes/file.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$CBRadress = 'http://www.cbr.ru/scripts/XML_daily.asp';
$xmlStr = file_get_contents($CBRadress); // берем XML с курсами с сайта ЦБ
if (empty($xmlStr)) {
print 'Unable to open ' . $CBRadress;
return;
}
$xml = new SimpleXMLElement($xmlStr);
$euro = $xml->xpath("//*[@ID='R01239']/Value")[0]->__toString(); // разбираем XML, получаем курс рубля к евро
$nodes = node_load_multiple(array(), array('type' => 'hardware')); // загружаем все ноды типа hardware
foreach ($nodes as $node){
// price_ru = округленный price_eu по текущему курсу
$node->field_price_ru[$node->language][0]['value'] = round ( $euro * $node->field_price_eu[$node->language][0]['value']);
node_save($node);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment