Beispiel #1
0
 /**
  * Prepare the feed file and returns its path
  *
  * @param array $productsData
  * @param int $storeId
  * @return string
  */
 public function prepareFeed(array $productsData, $storeId)
 {
     $mId = $this->getVendorConfig('merchant_id', $storeId);
     $company = $this->getVendorConfig('company', $storeId);
     if (!$mId || !$company) {
         Mage::throwException(Mage::helper('productfeed')->__('LinkShare Merchant ID and Company Name must be set.'));
     }
     Varien_Profiler::start('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
     $content = implode(self::DELIMITER, array('HDR', $mId, $company, Mage::getModel('core/date')->date('Y-m-d/H:i:s'))) . self::EOL;
     foreach ($productsData as $row) {
         $content .= $row . self::EOL;
     }
     $filename = $mId . '_nmerchandis' . Mage::getModel('core/date')->date('Ymd') . '.txt';
     $filepath = $this->getFeedStorageDir() . $filename;
     try {
         $ioAdapter = new Varien_Io_File();
         $ioAdapter->setAllowCreateFolders(true);
         $ioAdapter->createDestinationDir($this->getFeedStorageDir());
         $ioAdapter->cd($this->getFeedStorageDir());
         $ioAdapter->streamOpen($filename);
         $ioAdapter->streamWrite($content);
         Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
         return $filepath;
     } catch (Exception $e) {
         Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
         Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage()));
     }
 }
Beispiel #2
0
 /**
  * Prepare the feed file and returns its path
  *
  * @param array $productsData
  * @param int $storeId
  * @return string
  */
 public function prepareFeed(array $productsData, $storeId)
 {
     $mId = $this->getVendorConfig('merchant_id', $storeId);
     if (!$mId) {
         Mage::throwException(Mage::helper('productfeed')->__('Rakuten Seller ID must be set.'));
     }
     $filename = 'rakuten_product_' . Mage::getModel('core/date')->date('Ymd') . '.txt';
     $filepath = $this->getFeedStorageDir() . $filename;
     try {
         $ioAdapter = new Varien_Io_File();
         $ioAdapter->setAllowCreateFolders(true);
         $ioAdapter->createDestinationDir($this->getFeedStorageDir());
         $ioAdapter->cd($this->getFeedStorageDir());
         $ioAdapter->streamOpen($filename);
         $ioAdapter->streamWrite(implode(self::DELIMITER, $this->getHeaders()) . "\n");
         foreach ($productsData as $productId => $row) {
             array_unshift($row, $mId);
             $this->prepareRow($row, $productId);
             $ioAdapter->streamWrite(implode(self::DELIMITER, $row) . "\n");
             // because a CSV enclosure is not supported
         }
         return $filepath;
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage()));
     }
 }
 /**
  * Set base dir
  *
  * @access public
  * @author Marius Strajeru <*****@*****.**>
  */
 public function __construct()
 {
     $this->_baseDir = Mage::getBaseDir('var') . DS . 'modulecreator' . DS . 'package';
     $io = new Varien_Io_File();
     $io->setAllowCreateFolders(true);
     $io->createDestinationDir($this->_baseDir);
     $this->addTargetDir($this->_baseDir);
 }
 /**
  * Write xml nfe in folder
  *
  * @return true
  */
 public function write()
 {
     // load template array, fill data and convert to XML
     $this->_init()->_addCustomer()->_addItens()->_addOtherInfo()->_toXML();
     $io = new Varien_Io_File();
     $io->setAllowCreateFolders(true);
     $io->createDestinationDir($this->_path);
     $return = $io->write($this->_path . $this->_getFileName(), $this->_stringFinalXML);
     return true;
 }
Beispiel #5
0
 /**
  * Publish the specified feed file.
  *
  * @param string $filepath
  * @param array $params
  * @return Grommet_ProductFeed_Model_Feed_Publisher_File
  */
 public function publish($filepath, array $params = array())
 {
     if (empty($params['destination_path'])) {
         throw new Mage_Core_Exception('Invalid parameters - destination_path must be set.');
     }
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->setAllowCreateFolders(true);
     $ioAdapter->createDestinationDir(pathinfo($params['destination_path'], PATHINFO_DIRNAME));
     $writeResult = $ioAdapter->cp($filepath, $params['destination_path']);
     if (!$writeResult) {
         throw new Mage_Core_Exception('Unable to write file ' . $params['destination_path'] . ' to FTP.');
     }
     return $this;
 }
Beispiel #6
0
 /**
  * Submit refunds back to LinkShare for reimbursement.
  *
  * @param int $storeId
  * @return Grommet_ProductFeed_Model_Vendor_LinkShare_Refund
  */
 public function processDailyRefunds($storeId)
 {
     $rows = array();
     $ordersProcessed = array();
     // add credit memos to the feed
     $creditmemos = $this->_getCreditMemos($storeId);
     if (count($creditmemos)) {
         foreach ($creditmemos as $creditmemo) {
             $rows = array_merge($rows, $this->creditmemoToFeed($creditmemo));
             $ordersProcessed[] = $creditmemo->getOrderId();
         }
     }
     // add cancelations to the feed
     $orders = $this->_getOrders($storeId, $ordersProcessed);
     if (count($orders)) {
         foreach ($orders as $order) {
             $rows = array_merge($rows, $this->orderToFeed($order));
         }
     }
     if (count($rows)) {
         $mId = $this->getVendorConfig('merchant_id', $storeId);
         if (!$mId) {
             Mage::throwException(Mage::helper('productfeed')->__('LinkShare Merchant ID must be set.'));
         }
         $content = '';
         foreach ($rows as $row) {
             $content .= implode(self::DELIMITER, array_values($row)) . self::EOL;
         }
         $filename = $mId . '_trans' . Mage::getModel('core/date')->date('Ymd') . '.txt';
         $filepath = $this->getFeedStorageDir() . $filename;
         try {
             $ioAdapter = new Varien_Io_File();
             $ioAdapter->setAllowCreateFolders(true);
             $ioAdapter->createDestinationDir($this->getFeedStorageDir());
             $ioAdapter->cd($this->getFeedStorageDir());
             $ioAdapter->streamOpen($filename);
             $ioAdapter->streamWrite($content);
         } catch (Exception $e) {
             Mage::throwException(Mage::helper('productfeed')->__('Could not write refund file to path: %s, %s', $filepath, $e->getMessage()));
         }
         $publisher = $this->getPublisher();
         $publisher->publish($filepath, $this->getPublishParams($storeId));
     }
     return $this;
 }
 /**
  * Prepare the feed file and returns its path
  *
  * @param array $productsData
  * @param int $storeId
  * @return string
  */
 public function prepareFeed(array $productsData, $storeId)
 {
     $filename = 'mediaforge_' . Mage::getModel('core/date')->date('Ymd') . '.csv';
     $filepath = $this->getFeedStorageDir() . $filename;
     try {
         $ioAdapter = new Varien_Io_File();
         $ioAdapter->setAllowCreateFolders(true);
         $ioAdapter->createDestinationDir($this->getFeedStorageDir());
         $ioAdapter->cd($this->getFeedStorageDir());
         $ioAdapter->streamOpen($filename);
         $ioAdapter->streamWriteCsv($this->_fields, self::DELIMITER);
         foreach ($productsData as $row) {
             $ioAdapter->streamWriteCsv($row, self::DELIMITER);
         }
         return $filepath;
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage()));
     }
 }
Beispiel #8
0
 /**
  * Prepare the feed file and returns its path
  *
  * @param array $productsData
  * @param int $storeId
  * @return string
  */
 public function prepareFeed(array $productsData, $storeId)
 {
     Varien_Profiler::start('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
     $filename = $this->getVendorCode() . '_' . Mage::getModel('core/date')->date('Ymd') . '.json';
     $filepath = $this->getFeedStorageDir() . $filename;
     try {
         $ioAdapter = new Varien_Io_File();
         $ioAdapter->setAllowCreateFolders(true);
         $ioAdapter->createDestinationDir($this->getFeedStorageDir());
         $ioAdapter->cd($this->getFeedStorageDir());
         $ioAdapter->streamOpen($filename);
         $ioAdapter->streamWrite(json_encode($productsData));
         Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
         return $filepath;
     } catch (Exception $e) {
         Varien_Profiler::stop('productfeed_' . $this->getVendorCode() . '::' . __FUNCTION__);
         Mage::throwException(Mage::helper('productfeed')->__('Could not write feed file to path: %s, %s', $filepath, $e->getMessage()));
     }
 }
Beispiel #9
0
 protected function _copy($file)
 {
     $ioAdapter = new Varien_Io_File();
     if (!$ioAdapter->fileExists($file)) {
         Mage::throwException(Mage::helper('dataflow')->__('File "%s" does not exist.', $file));
     }
     $ioAdapter->setAllowCreateFolders(true);
     $ioAdapter->createDestinationDir($this->getBatchModel()->getIoAdapter()->getPath());
     return $ioAdapter->cp($file, $this->getBatchModel()->getIoAdapter()->getFile(true));
 }