Skip to content

Instantly share code, notes, and snippets.

@kossoff
Created September 22, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kossoff/0e5cbcf892913a57b723 to your computer and use it in GitHub Desktop.
Save kossoff/0e5cbcf892913a57b723 to your computer and use it in GitHub Desktop.
Drupal 7. Обновление/добавление цен для товаров из CSV-файла. Ключ - уникальный title.
<?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);
$csvFile = file('data.csv');
foreach ($csvFile as $line) {
$data = str_getcsv($line, ';');
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'hardware')
->propertyCondition('title', $data[4])
// ->propertyCondition('status', 1)
->range(0,1)
->execute();
if (!empty($entities['node'])) {
$node = node_load(array_shift(array_keys($entities['node'])));
$node->field_price_eu[$node->language][0]['value'] = str_replace (',', '.', $data[11]);
$node->status = 1;
node_save ($node);
print $node->title . ' - ' . $node->field_price_eu[$node->language][0]['value'] . '<br>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment