예제 #1
0
 /**
  * export Profile
  *
  * @param Flagbit_MEP_Model_Profile $profile
  */
 public function exportProfile(Flagbit_MEP_Model_Profile $profile, $catchErrors = true)
 {
     $exportFile = null;
     try {
         /** @var $appEmulation Mage_Core_Model_App_Emulation */
         $appEmulation = Mage::getSingleton('core/app_emulation');
         //Start environment emulation of the specified store
         $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($profile->getStoreId(), Mage_Core_Model_App_Area::AREA_ADMINHTML);
         // Initialize frontend translations
         Mage::getSingleton('core/translate')->init('frontend', true);
         // destination File
         $exportFile = $this->_getExportPath($profile) . DS . $profile->getFilename();
         if (file_exists($exportFile)) {
             unlink($exportFile);
         }
         // disable flat Tables
         Mage::app()->getConfig()->setNode('catalog/frontend/flat_catalog_product', 0, true);
         // add additional Logfile for the current Profile
         Mage::helper('mep/log')->addAdditionalLogfile('mep-' . $profile->getId() . '.log');
         /* @var $export Flagbit_MEP_Model_Export */
         $export = Mage::getModel('mep/export');
         $export->setData('id', $profile->getId());
         $export->setEntity("catalog_product");
         $export->setFileFormat("twig");
         $export->setExportFilter(array());
         $export->setDestination($exportFile);
         $export->export();
         try {
             // bypass MySQL server has gone away errors
             $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         Mage::helper('mep/log')->err($e, $this);
         Mage::logException($e);
         if (!$catchErrors) {
             throw $e;
         }
     }
     return $exportFile;
 }
예제 #2
0
 /**
  * Recalculate quantity of products matching the profile and save the value in the database
  *
  * @param Flagbit_MEP_Model_Profile $profile
  *
  * @return void
  */
 private function _recalculateProducts($profile)
 {
     $export = Mage::getModel('mep/export');
     $export->setData('id', $profile->getId());
     $export->setEntity("catalog_product");
     $export->setExportFilter(array());
     $count = $export->countItems();
     // save value to the database
     $profile->setProductCount($count);
     $profile->save();
 }