Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ONLY WORK VIA CRON OR SSH: /usr/bin/php -f /var/www/magento/cron_import.php */
- /* http://www.magentocommerce.com/boards/viewthread/35865/ */
- $profileId = 7;
- $logFileName= 'import-profile-7.log';
- $recordCount = 0;
- require_once '../app/Mage.php';
- Mage::app('admin');
- Mage::log("Starting",null,$logFileName);
- /** @var Mage_Dataflow_Model_Profile $profile */
- $profile = Mage::getModel('dataflow/profile');
- if ($profileId) {
- $profile->load($profileId);
- if (!$profile->getId()) {
- Mage::throwException('ERROR: Incorrect Profile for id ' . $profileId);
- }
- }
- Mage::register('current_convert_profile', $profile);
- $profile->run();
- /** @var Mage_Dataflow_Model_Batch $batchModel */
- $batchModel = Mage::getSingleton('dataflow/batch');
- if ( ($batchId = $batchModel->getId()) ) {
- if ($batchModel->getAdapter()) {
- /** @var Mage_Dataflow_Model_Batch_Import $batchImportModel */
- $batchImportModel = $batchModel->getBatchImportModel();
- $importIds = $batchImportModel->getIdCollection();
- /** @var Mage_Dataflow_Model_Batch $batchModel */
- $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
- /** @var Mage_Customer_Model_Convert_Adapter_Customer $adapter */
- $adapter = Mage::getModel($batchModel->getAdapter());
- foreach ($importIds as $importId) {
- $recordCount++;
- try{
- $batchImportModel->load($importId);
- if (!$batchImportModel->getId()) {
- $errors[] = Mage::helper('dataflow')->__('WARNING: Skip undefined row');
- continue;
- }
- $importData = $batchImportModel->getBatchData();
- try {
- $adapter->saveRow($importData);
- if( array_key_exists('is_subscribed', $importData) )
- {
- /** @var Mage_Newsletter_Model_Subscriber $subscription */
- $subscription = Mage::getModel('newsletter/subscriber');
- /*
- * Theoretically this should work, but the code sets
- * "importMode()" but does not really do anything with
- * it, so chances are email is sent.
- * You may want to disable email communications
- * while running mass imports.
- */
- $subscription->subscribeCustomer($adapter->getCustomer());
- }
- } catch (Exception $e) {
- Mage::log($e->getMessage(),null,$logFileName);
- continue;
- }
- if ($recordCount % 50 == 0) {
- Mage::log($recordCount . ' completados',null,$logFileName);
- }
- } catch(Exception $ex) {
- Mage::log('Fila ' . $recordCount . ', SKU ' . $importData['sku']. ' - ERROR: ' . $ex->getMessage(),null,$logFileName);
- }
- }
- foreach ($profile->getExceptions() as $e) {
- Mage::log($e->getMessage(),null,$logFileName);
- }
- }
- }
- printf("OKn");
- Mage::log("Completed",null,$logFileName);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement