I want to set up a cron job and do scheduled imports from a particular .csv file that I will upload/update via ftp.
I wonder if there is an easy way to set up a product import for X-Cart 5 using linux console command?
I want to set up a cron job and do scheduled imports from a particular .csv file that I will upload/update via ftp.
I wonder if there is an easy way to set up a product import for X-Cart 5 using linux console command?
There is not default way to do import via linux console. But you can create simple console script and run it via cron.
Example of code(only concept, not solution for your case):
#!/usr/bin/env php
<?php
if ('cli' != PHP_SAPI) {
exit (1);
}
require_once __DIR__ . DIRECTORY_SEPARATOR . 'top.inc.php';
XLite::getInstance()->run(true);
// Initialize importer
// See all possible options in classes/XLite/Logic/Import/Importer.php __construct()
$importer = new \XLite\Logic\Import\Importer(
array(
'warningsAccepted' => true,
'delimiter' => ',',
'ignoreFileChecking' => true,
'files' => array(
'/full/path/to/xcart/var/import/products.csv',
'/full/path/to/xcart/var/import/categories.csv'
)
)
);
// Verifiaction step
while ($importer->getStep()->valid()) {
$importer->getStep()->current()->process();
$importer->getStep()->next();
}
// Check warnings & errors after verification and save to log file
if($importer->hasWarnings()) {
$warnings = \XLite\Core\Database::getRepo('XLite\Model\ImportLog')
->findBy(array('type' => \XLite\Model\ImportLog::TYPE_WARNING));
\XLite\Logger::logCustom('import_warnings', var_export($warnings, true));
//Clear warning messages
\XLite\Core\Database::getRepo('XLite\Model\ImportLog')
->deleteByType(\XLite\Model\ImportLog::TYPE_WARNING);
}
if($importer->hasErrors()) {
$errors = \XLite\Core\Database::getRepo('XLite\Model\ImportLog')
->findBy(array('type' => \XLite\Model\ImportLog::TYPE_ERROR));
\XLite\Logger::logCustom('import_errors', var_export($errors, true));
}
// Import/proccess quick data for products/resize images
// This loop wont'b executed if ($importer->hasWarnings() == true && warningsAccepted == false)
// or ($importer->hasErrors() == true)
while ($importer->isNextStepAllowed()) {
$importer->getOptions()->step = $importer->getOptions()->step + 1;
$importer->getOptions()->position = 0;
while ($importer->getStep()->valid()) {
$importer->getStep()->current()->process();
$importer->getStep()->next();
}
}
Also you can use scheduled task in X-Cart 5. To use it you should create your own module with class witch will extends abstract class classes/XLite/Core/Task/Base/Periodic.php
You can find example of code in file classes/XLite/Module/CDev/XMLSitemap/Core/Task/GenerateSitemap.php
Run tasks registered in X-Cart 5: php console.php --target=cron