89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
|
|
$main_class = 'Import_XMLfeed_New';
|
|
|
|
class Import_XMLfeed_New extends Window
|
|
{
|
|
use DatabaseCommunication;
|
|
|
|
protected $template = 'window/import.xml_feed_new.tpl';
|
|
|
|
public function handle()
|
|
{
|
|
if (getVal('Submit') || getVal('execute') || getVal('synchronize_try')) {
|
|
$feedUrl = $this->getFeedFile();
|
|
$execute = getVal('execute');
|
|
|
|
if (!empty($_FILES['xsltFile']['size'])) {
|
|
$xslt = new XSLTProcessor();
|
|
$xslt->importStylesheet(simplexml_load_file($_FILES['xsltFile']['tmp_name']));
|
|
|
|
if (!$xslt->transformToUri(simplexml_load_file($feedUrl), $_FILES['xsltFile']['tmp_name'])) {
|
|
$this->returnError('Chyba aplikovani XSLT transformace');
|
|
}
|
|
|
|
$feedUrl = $_FILES['xsltFile']['tmp_name'];
|
|
}
|
|
|
|
$params = $this->getImportParams();
|
|
$params['source'] = $feedUrl;
|
|
$params['sourceFile'] = $feedUrl;
|
|
|
|
$import = \KupShop\KupShopBundle\Util\Compat\ServiceContainer::getService(\KupShop\AdminBundle\Util\AutomaticImport::class);
|
|
$import->setData($params);
|
|
|
|
if (!$import->process(!$execute)) {
|
|
$this->returnError("Chyba importu: {$import->error}");
|
|
}
|
|
|
|
$smarty = createSmarty(true, true);
|
|
$smarty->assign(Window::get_vars());
|
|
if (!$execute) {
|
|
$smarty->assign([
|
|
'data' => $this->getData(),
|
|
'ID' => $this->getID(),
|
|
'import' => $import,
|
|
'import_type' => $params['add_new'],
|
|
'view' => $this,
|
|
'all' => getVal('all'),
|
|
]);
|
|
$smarty->assign($import->getDebugData());
|
|
$smarty->display('window/import.dump.tpl');
|
|
exit;
|
|
} else {
|
|
$smarty = createSmarty(true, true);
|
|
$smarty->assign(Window::get_vars());
|
|
$smarty->assign([
|
|
'ID' => $this->getID(),
|
|
'import' => $import,
|
|
'view' => $this,
|
|
]);
|
|
$smarty->assign($import->getDebugData());
|
|
$smarty->assign(['updatedProducts' => $import->updatedCreatedProducts]);
|
|
$smarty->display('window/import.result.tpl');
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getFeedFile()
|
|
{
|
|
return getVal('feedUrl');
|
|
}
|
|
|
|
public function getImportParams()
|
|
{
|
|
global $cfg;
|
|
|
|
return [
|
|
'type' => AutomaticImport::TYPE_XML,
|
|
'id' => -1,
|
|
'id_supplier' => -1,
|
|
'transformation' => file_get_contents("{$cfg['Path']['shared_version']}admin/templates/import/xmlFeed.xslt"),
|
|
'modify_in_store' => 1,
|
|
'pair' => 1,
|
|
'add_new' => 1,
|
|
];
|
|
}
|
|
}
|