Komunikat o błędzie

  • User warning: The following module is missing from the file system: bueditor. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: field_validation_extras. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: field_validation_ui. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: geshifield. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: geshifilter. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: google_plusone. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: linkit. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: property_validation. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: taxonomy_menu. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: tweetbutton. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: wysiwyg. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • User warning: The following module is missing from the file system: field_validation. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1181 of /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/bootstrap.inc).
  • Notice: Undefined index: execute_responsive_theme w drupal_theme_initialize() (linia 100 z /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/theme.inc).
  • Notice: Trying to get property 'filename' of non-object w _drupal_theme_initialize() (linia 146 z /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/theme.inc).
  • Notice: Trying to get property 'name' of non-object w _theme_load_registry() (linia 335 z /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/theme.inc).
  • Notice: Undefined index: execute_responsive_theme w theme_get_setting() (linia 1440 z /usr/home/tomaszroot/domains/blog.tomlot.eu/public_html/includes/theme.inc).

Importer CSV kategorii i produktów do PrestaShop

Importer kategorii
[php]
try {
$db_server = 'localhost';
$db_name = 'localhost';
$db_user = 'localhost';
$db_passwd = 'localhost';

$db_pdo = new PDO(
"mysql:host=$db_server;dbname=$db_name",
$db_user,
$db_passwd,
[PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]
);

$db_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

# wyciągniecie kategorii głównych
$wynik = $db_pdo->query("
SELECT id, rozmiar, vat
FROM oferta
WHERE towar IS NULL AND vat = 0
ORDER BY id ASC;");

while ($wiersz = $wynik->fetch()) {
$tablicaGlowneKat[] = $wiersz;
}

// print_r($tablicaGlowneKat);

# lepsza widoczność
// $rekordy = count($tablicaGlowneKat);
// for ($i = 0; $i // printf("%d\t%s".PHP_EOL, $tablicaGlowneKat[$i]['id'], $tablicaGlowneKat[$i]['rozmiar']);
// }

# drukowanie kategorii pod plik CSV
$wynik = $db_pdo->query("
SELECT id, rozmiar, vat, tresckat
FROM oferta
WHERE towar IS NULL
ORDER BY id ASC;");

print "ID;NAZWA;PARENT CATEGORY;DESCRIPTION".PHP_EOL;

while ($wiersz = $wynik->fetch()) {

if ($wiersz['vat'] == 0) {
$wiersz['vat'] = NULL;
}

# podmiana ID na nazwy kategorii
foreach ($tablicaGlowneKat as $pozycja) {
if ($wiersz['vat'] == $pozycja['id']) {
$wiersz['vat'] = $pozycja['rozmiar'];
}
}

# formatowanie opisu
$szukaj = array('ó', ' ', ';');
$zamien = array('ó', ' ', '');
$opis = str_replace($szukaj, $zamien, $wiersz['tresckat']);
$opis = preg_replace("/\r|\n/", "", $opis);

$szukaj = array('', '', ',');
$zamien = array('', '', ' ');
$kat = str_replace($szukaj, $zamien, $wiersz['rozmiar']);
$katGlowna = str_replace($szukaj, $zamien,$wiersz['vat']);

$kat = trim($kat);
$katGlowna = trim($katGlowna);

printf("%d;%s;%s;%s".PHP_EOL, $wiersz['id'], $kat, $katGlowna, $opis);
}

$db_pdo = NULL;
} catch (PDOException $e) {
print "Błąd: ".$e->getMessage();
die();
}[/php]

Importer produktów
[php]
try {
$db_server = 'localhost';
$db_name = 'localhost';
$db_user = 'localhost';
$db_passwd = 'localhost';

$db_pdo = new PDO(
"mysql:host=$db_server;dbname=$db_name",
$db_user,
$db_passwd,
[PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]
);

$db_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

#wyciągnięcie kategorii
$wynik = $db_pdo->query("
SELECT id, rozmiar
FROM oferta
WHERE towar IS NULL
ORDER BY id ASC;");

while ($katWiersz = $wynik->fetch()) {
$kat[] = $katWiersz;
}

# wyciągniecie produktów
# towar - tytuł
# tresc - opis prod
# cena
# wartoscir - kategorie
# tak - (nie)dostępny 0|1
# zdjęcia z katalogu /img1
$wynik = $db_pdo->query("
SELECT id, towar, tresc, cena, wartoscir, tak
FROM oferta
WHERE kategoria2 = 'sta' OR kategoria2 = 'pro'");

print "ID;TYTUŁ;OPIS;CENA;AKTYWNY;ZDJECIA;KATEGORIE".PHP_EOL;

while ($wiersz = $wynik->fetch()) {

$katProd = explode(' ', $wiersz['wartoscir']);

# formatowanie opisu
$szukaj = array('ó', ' ', ';');
$zamien = array('ó', ' ', '');
$opis = str_replace($szukaj, $zamien, $wiersz['tresc']);
$opis = preg_replace("/\r|\n/", "", $opis);

# drukowanie rekordów
print $wiersz['id'].";";
print $wiersz['towar'].";";
print $opis.";";
print $wiersz['cena'].";";

if ($wiersz['tak'] == 'tak') {
$dostepny = 1;
} else {
$dostepny = 0;
}
print $dostepny.";";

$urlRoot = "https://www.galanteria-drewniana.com/img1/";
$tabUrl = [$urlRoot.$wiersz['id'].".jpg",$urlRoot.$wiersz['id'].".m.jpg",$urlRoot.$wiersz['id'].".a.jpg"];

foreach ($tabUrl as $url) {
$headers = @get_headers($url);
if ($headers && strpos( $headers[0], '200')) {
print $url.",";
}
}
print ";";

# formatowanie kategorii
$szukaj = array('', '', ',');
$zamien = array('', '', ' ');

# podmiana ID na nazwy kategorii
foreach ($katProd as $pozycja) {
foreach ($kat as $katWiersz) {
if ($pozycja == $katWiersz['id']) {
$pozycja = $katWiersz['rozmiar'];
$pozycja = str_replace($szukaj, $zamien, $pozycja);
print $pozycja.",";
}
}
}
print PHP_EOL;
}
$db_pdo = NULL;

} catch (PDOException $e) {
print "Błąd: ".$e->getMessage();
die();
}
[/php]

Uruchomienie importerów
[code]php kategorie.php > kategorie.csv[/code]
[code]php produkty.php > produkty.csv[/code]

Zastosowanie: 

Importer kategorii i produktów z autotrskiego sklepu do plików CSV do PrestaShop

Wiedza: 
Praktyczna