Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <?php
  2. /* ONLY WORK VIA CRON OR SSH: /usr/bin/php -f /var/www/magento/cron_import.php */
  3. /* http://www.magentocommerce.com/boards/viewthread/35865/ */
  4. $profileId = 7;
  5. $logFileName= 'import-profile-7.log';
  6. $recordCount = 0;
  7.  
  8. require_once '../app/Mage.php';
  9.  
  10. Mage::app('admin');
  11. Mage::log("Starting",null,$logFileName);
  12.  
  13. /** @var Mage_Dataflow_Model_Profile $profile */
  14. $profile = Mage::getModel('dataflow/profile');
  15.  
  16. if ($profileId) {
  17. $profile->load($profileId);
  18. if (!$profile->getId()) {
  19. Mage::throwException('ERROR: Incorrect Profile for id ' . $profileId);
  20. }
  21. }
  22.  
  23. Mage::register('current_convert_profile', $profile);
  24.  
  25. $profile->run();
  26.  
  27. /** @var Mage_Dataflow_Model_Batch $batchModel */
  28. $batchModel = Mage::getSingleton('dataflow/batch');
  29. if ( ($batchId = $batchModel->getId()) ) {
  30. if ($batchModel->getAdapter()) {
  31. /** @var Mage_Dataflow_Model_Batch_Import $batchImportModel */
  32. $batchImportModel = $batchModel->getBatchImportModel();
  33. $importIds = $batchImportModel->getIdCollection();
  34. /** @var Mage_Dataflow_Model_Batch $batchModel */
  35. $batchModel = Mage::getModel('dataflow/batch')->load($batchId);
  36. /** @var Mage_Customer_Model_Convert_Adapter_Customer $adapter */
  37. $adapter = Mage::getModel($batchModel->getAdapter());
  38. foreach ($importIds as $importId) {
  39. $recordCount++;
  40. try{
  41. $batchImportModel->load($importId);
  42. if (!$batchImportModel->getId()) {
  43. $errors[] = Mage::helper('dataflow')->__('WARNING: Skip undefined row');
  44. continue;
  45. }
  46. $importData = $batchImportModel->getBatchData();
  47. try {
  48. $adapter->saveRow($importData);
  49. if( array_key_exists('is_subscribed', $importData) )
  50. {
  51. /** @var Mage_Newsletter_Model_Subscriber $subscription */
  52. $subscription = Mage::getModel('newsletter/subscriber');
  53. /*
  54. * Theoretically this should work, but the code sets
  55. * "importMode()" but does not really do anything with
  56. * it, so chances are email is sent.
  57. * You may want to disable email communications
  58. * while running mass imports.
  59. */
  60. $subscription->subscribeCustomer($adapter->getCustomer());
  61. }
  62. } catch (Exception $e) {
  63. Mage::log($e->getMessage(),null,$logFileName);
  64. continue;
  65. }
  66. if ($recordCount % 50 == 0) {
  67. Mage::log($recordCount . ' completados',null,$logFileName);
  68. }
  69. } catch(Exception $ex) {
  70. Mage::log('Fila ' . $recordCount . ', SKU ' . $importData['sku']. ' - ERROR: ' . $ex->getMessage(),null,$logFileName);
  71. }
  72. }
  73. foreach ($profile->getExceptions() as $e) {
  74. Mage::log($e->getMessage(),null,$logFileName);
  75. }
  76. }
  77. }
  78. printf("OKn");
  79. Mage::log("Completed",null,$logFileName);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement