0
You have no items in your shopping cart.

0

You can download the zip with the php sample file in it here
http://www.commerceextensions.com/docs/cron_job_example.zip

email with any questions to scottbolasevich@gmail.com
01<?php
02 require_once 'app/Mage.php';
03umask(0);
04 ini_set("memory_limit","1024M");
05//$_SERVER['SERVER_PORT']='443';
06Mage::app();
07$profileId = 7; //put your profile id here
08 
09$logFileName= "import.log";
10$recordCount = 0;
11// This won't work if Logging settings is disabled
12// To activate it go to System->Configuration->Developer
13Mage::log("Import Started",null,$logFileName);
14$profile = Mage::getModel('dataflow/profile');
15 
16$userModel = Mage::getModel('admin/user');
17$userModel->setUserId(0);
18Mage::getSingleton('admin/session')->setUser($userModel);
19 
20if ($profileId) {
21    $profile->load($profileId);
22    if (!$profile->getId()) {
23        Mage::getSingleton('adminhtml/session')->addError('The profile you are trying to save no longer exists');
24    }
25}
26 
27Mage::register('current_convert_profile', $profile);
28 
29$profile->run();
30 
31$batchModel = Mage::getSingleton('dataflow/batch');
32if ($batchModel->getId()) {
33    if ($batchModel->getAdapter()) {
34        $batchId = $batchModel->getId();
35        $batchImportModel = $batchModel->getBatchImportModel();
36        $importIds = $batchImportModel->getIdCollection();
37        $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
38        $adapter = Mage::getModel($batchModel->getAdapter());
38        $adapter->setBatchParams($batchModel->getParams());
39        foreach ($importIds as $importId) {
40            $recordCount++;
41            try{
42                $batchImportModel->load($importId);
43                if (!$batchImportModel->getId()) {
44                    $errors[] = Mage::helper('dataflow')->__('Skip undefined row');
45                    continue;
46                }
47 
48                $importData = $batchImportModel->getBatchData();
49                try {
50                    $adapter->saveRow($importData);
51                } catch (Exception $e) {
52                    Mage::log($e->getMessage(),null,$logFileName);
53                    continue;
54                }
55 
56                if ($recordCount%20 == 0) {
57                    Mage::log($recordCount . ' - Completed!!',null,$logFileName);
58                }
59            } catch(Exception $ex) {
60                Mage::log('Record# ' . $recordCount . ' - SKU = ' . $importData['sku']. ' - Error - ' . $ex->getMessage(),null,$logFileName);
61            }
62        }
63        foreach ($profile->getExceptions() as $e) {
64            Mage::log($e->getMessage(),null,$logFileName);
65        }
66 
67    }
68}
69 
70Mage::log("Import Completed",null,$logFileName);
71 
72// Catalog Rewrites
73try {
74    Mage :: getSingleton( 'catalog/url' ) -> refreshRewrites();
75}
76catch ( Exception $e ) {
77    Mage::log($e -> getMessage(),null,$logFileName);
78}
79// LAYERED NAV
80    try {
81        $flag = Mage::getModel('catalogindex/catalog_index_flag')->loadSelf();
82        if ($flag->getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_RUNNING) {
83            $kill = Mage::getModel('catalogindex/catalog_index_kill_flag')->loadSelf();
84            $kill->setFlagData($flag->getFlagData())->save();
85        }
86 
87        $flag->setState(Mage_CatalogIndex_Model_Catalog_Index_Flag::STATE_QUEUED)->save();
88        Mage::getSingleton('catalogindex/indexer')->plainReindex();
89        Mage::log('Layered Navigation Indices were refreshed successfully', null, $logFileName);
90    }
91    catch (Mage_Core_Exception $e) {
92        Mage::log($e -> getMessage(). "\n",null,$logFileName);
93    }
94    catch (Exception $e) {
95        Mage::log('Error while refreshed Layered Navigation Indices. Please try again later', null,$logFileName);
96    }
97 ?>