Created
September 22, 2015 18:34
-
-
Save kossoff/0e5cbcf892913a57b723 to your computer and use it in GitHub Desktop.
Drupal 7. Обновление/добавление цен для товаров из CSV-файла. Ключ - уникальный title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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