Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Connect POS to Magento using Cron Job

Featured Replies

Hi,

 

I'm trying to connect a POS System to a Magento webshop, so the products etc will be automatically updated. I know this is possible by using a Cron Job php file. It would work fine using task manager to export and the Cron job to import.

Now i bumped into a problem..

The table names don't match, so it wouldn't accept the import file. For example, in the POS System the SKU is named by "artnr" and in Magento it's named by "SKU".

 

I have no idea where to start with this and was wondering if someone can help me in to the right direction to let the names be automatically changed.

Can this be added in the Cron Job or does it has to be something else ?

 

This is the Cron Job file:

<?
// ONLY WORK VIA CRON OR SSH: /usr/bin/php -f /var/www/magento/cron_import.php
if ($_SERVER["SERVER_ADDR"] != $_SERVER["REMOTE_ADDR"]){
        exit ("can only run locally");
}


$profileId = $argv[1];
if (! isset($profileId)){
   exit ("\nPlease specify a profile id. You can find it in the admin panel->Import/Export->Profiles.\nUsage: \n\t\t  php -f $argv[0] PROFILE_ID\n\t example: php -f $argv[0] 7\n");
}

$logFileName= 'import-log.log';  
$recordCount = 0;

require_once 'app/Mage.php';
ob_implicit_flush();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

Mage::log("Starting import",null,$logFileName);  
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
Mage::getSingleton('admin/session')->setUser($userModel);
#echo "got singleton\n"; 
if ($profileId) {
   $profile->load($profileId);
   if (!$profile->getId()) {
      Mage::getSingleton('adminhtml/session')->addError('ERROR: Could not load profile');
   }
}

Mage::register('current_convert_profile', $profile);

#echo "running profile\n";
$profile->run();
##echo "done\n";

$batchModel = Mage::getSingleton('dataflow/batch');
if ($batchModel->getId()) {
   #echo "getId ok\n";
   if ($batchModel->getAdapter()) {
      #echo "getAdapter ok\n";
      $batchId = $batchModel->getId(); 
      $batchImportModel = $batchModel->getBatchImportModel();
      $importIds = $batchImportModel->getIdCollection();  
      $batchModel = Mage::getModel('dataflow/batch')->load($batchId);      
      $adapter = Mage::getModel($batchModel->getAdapter());
      foreach ($importIds as $importId) {
         #echo "importing $importId\n";
         $recordCount++;
         try{
            $batchImportModel->load($importId);
            if (!$batchImportModel->getId()) {
               $errors[] = Mage::helper('dataflow')->__('WARNING: Skip undefined row');
               continue;
            }
            $importData = $batchImportModel->getBatchData();
            try {
               $adapter->saveRow($importData);
            } catch (Exception $e) {
               Mage::log($e->getMessage(),null,$logFileName);          
               continue;
            }      
            if ($recordCount%10 == 0) {
               Mage::log($recordCount . ' products imported',null,$logFileName);
            }
         } catch(Exception $ex) {
            Mage::log('File ' . $recordCount . ', SKU ' . $importData['sku']. ' - ERROR: ' . $ex->getMessage(),null,$logFileName);        
         }
      }
      foreach ($profile->getExceptions() as $e) {
         Mage::log($e->getMessage(),null,$logFileName);          
      }
   }
}
#printf("OK\n");
Mage::log("Completed!",null,$logFileName);
?>

Thanks in advance!

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.