Jump to content

Import functions


Recommended Posts

How can i catch the errors of these functions.

 

When running on the backend you can see if something fails but since php I do not know how I can catch those error messages or that the operation has been a success.

function loadProductsPost() {
	$_POST = array (
		'tab' => 'AdminImport',
		'skip' => '1',
		'csv' => 'productos.csv',
		'forceIDs' => '0',
		'match_ref' => '1',
		'convert' => '',
		'entity' => '1',
		'separator' => ';',
		'multiple_value_separator' => ',',
		'iso_lang' => 'es',
		'import' => 'Importar datos CSV',
		'type_value' =>
		array (
			0 => 'category',
			1 => 'name',
			2 => 'description_short',
			3 => 'reference',
			4 => 'ean13',
			5 => 'weight',
			6 => 'wholesale_price',
			7 => 'price_tex',
			8 => 'ecotax',
			9 => 'manufacturer',
			10 => 'image',
		),
	);
}
 
$import = New AdminImportController();
 
loadProductsPost();
 
$import->productImport();
 
//______________________________________CATEGORIAS
function loadCategoriesPost() {
	$_POST = array (
		'tab' => 'AdminImport',
		'skip' => '1',
		'csv' => 'categorias.csv',
		'forceIDs' => '1',
		'convert' => '',
		'entity' => '0',
		'separator' => ';',
		'multiple_value_separator' => ',',
		'iso_lang' => 'es',
		'import' => 'Importar datos CSV',
		'type_value' =>
		array (
			0 => 'id',
			1 => 'active',
			2 => 'name',
			3 => 'parent',
			4 => 'is_root_category',
			5 => 'description',
			6 => 'meta_title',
			7 => 'meta_keywords',
			8 => 'meta_description',
			9 => 'link_rewrite',
			10 => 'image',
		),
	);
}
 
$import = New AdminImportController();
 
loadCategoriesPost();
 
$import->categoryImport();
Link to comment
Share on other sites

on top page pastle this:

<?php error_reporting(0); 
$old_error_handler = set_error_handler("userErrorHandler");
 
function userErrorHandler ($errno, $errmsg, $filename, $linenum,  $vars) 
{
$time=date("d M Y H:i:s"); 
// Get the error type from the error number 
$errortype = array (1    => "Error",
2    => "Warning",
4    => "Parsing Error",
8    => "Notice",
16   => "Core Error",
32   => "Core Warning",
64   => "Compile Error",
128  => "Compile Warning",
256  => "User Error",
512  => "User Warning",
1024 => "User Notice");
$errlevel=$errortype[$errno];
 
//Write error to log file (CSV format) 
$errfile=fopen("errors.csv","a"); 
fputs($errfile,"\"$time\",\"$filename: 
$linenum\",\"($errlevel) $errmsg\"\r\n"); 
fclose($errfile);
 
if($errno!=2 && $errno!=8) {
//Terminate script if fatal error
die("A fatal error has occurred. Script execution has been aborted");
} 
}
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...