本文整理汇总了PHP中Varien_File_Csv::setEnclosure方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Csv::setEnclosure方法的具体用法?PHP Varien_File_Csv::setEnclosure怎么用?PHP Varien_File_Csv::setEnclosure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Csv
的用法示例。
在下文中一共展示了Varien_File_Csv::setEnclosure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runUpdate
protected function runUpdate()
{
$this->setData('script_started_at', Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()));
$this->setData('script_finished_at', Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()));
$messages = array();
$this->setData('messages', $messages);
$website = $this->getRequest()->getParam('website');
$store = $this->getRequest()->getParam('store');
$testmode = $this->getRequest()->getParam('testmode', 0);
$sku = $this->getRequest()->getParam('sku');
$limit = (int) $this->getRequest()->getParam('limit', 0);
$offset = (int) $this->getRequest()->getParam('offset', 0);
if ($limit > 100) {
$limit = 100;
}
$store_code = Mage_Core_Model_Store::DEFAULT_CODE;
if ($store != "") {
$store_code = $store;
}
$this->setData('is_feed', false);
try {
$Generator = Mage::getModel('googlebasefeedgenerator/generator', array('store_code' => $store_code));
$messages[] = array('msg' => 'Store ' . Mage::app()->getStore($store_code)->getName(), 'type' => 'info');
/* @var $Generator RocketWeb_GoogleBaseFeedGenerator_Model_Generator*/
if ($testmode) {
if ($limit > $Generator->getConfigVar('button_max_products')) {
$limit = $Generator->getConfigVar('button_max_products');
}
$this->setTestMode(true);
$Generator->setTestMode(true);
if ($sku) {
$Generator->setTestSku($sku);
$this->setTestSku($sku);
} elseif ($offset >= 0 && $limit > 0) {
$Generator->setTestOffset($offset);
$this->setTestOffset($offset);
$Generator->setTestLimit($limit);
$this->setTestLimit($limit);
} else {
Mage::throwException(sprintf("Invalid parameters for test mode: sku %s or offset %s and limit %s", $sku, $offset, $limit));
}
$messages[] = array('msg' => 'Test mode.', 'type' => 'info');
} else {
$this->setTestMode(false);
}
if (!$Generator->getConfigVar('is_turned_on')) {
$messages[] = array('msg' => 'Can\'t generate feed. It\'s disabled from config option: RocketWeb Extensions > Google Base Feed Generator > Settings > Enabled.', 'type' => 'error');
$this->setData('messages', $messages);
return;
}
if (!$this->getTestMode()) {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->setStoreId(Mage::app()->getStore($store_code)->getStoreId());
$count = $collection->getSize();
if ($count > $Generator->getConfigVar('button_max_products')) {
Mage::throwException(sprintf("Too many products. Detected %d products more than the limit allowed of %d.", $count, $Generator->getConfigVar('button_max_products')));
}
}
// Generate feed - costly process.
$Generator->run();
if ($Generator->getCountProductsExported() > 0) {
$this->setData('is_feed', true);
}
} catch (Exception $e) {
$messages[] = array('msg' => 'Error:<br />' . $e->getMessage(), 'type' => 'error');
}
$count_products = 0;
$count_skipped = 0;
if (isset($Generator) && is_object($Generator) && $Generator instanceof RocketWeb_GoogleBaseFeedGenerator_Model_Generator) {
$count_products = $Generator->getCountProductsExported();
$count_skipped = $Generator->getCountProductsSkipped();
}
$feed_data = array();
if ($this->getIsFeed() && $sku != "" && $count_products > 0 && file_exists($Generator->getFeedPath())) {
/* tsv file */
$csv = new Varien_File_Csv();
$csv->setDelimiter("\t");
$csv->setEnclosure('~');
// dummy enclosure
$rows = $csv->getData($Generator->getFeedPath());
$i = 0;
foreach ($rows as $row) {
if ($i == 0) {
$i++;
continue;
}
$feed_data[] = array_combine($rows[0], $row);
$i++;
}
}
$this->setFeedData($feed_data);
$messages[] = array('msg' => sprintf("The feed was generated.<br />%d items were added %d products were skipped.", $count_products, $count_skipped), 'type' => 'info');
$this->setData('messages', $messages);
$this->setData('script_finished_at', Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()));
}
示例2: runUpdate
/**
* Run the generators
*/
protected function runUpdate()
{
$this->setData('script_started_at', Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()));
$this->setData('script_finished_at', Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()));
$messages = array();
$this->setData('messages', $messages);
$store = $this->getRequest()->getParam('store');
$testmode = $this->getRequest()->getParam('testmode', 0);
$sku = $this->getRequest()->getParam('sku');
$limit = (int) $this->getRequest()->getParam('limit', 0);
$offset = (int) $this->getRequest()->getParam('offset', 0);
if ($limit > 100) {
$limit = 100;
}
$store_code = Mage_Core_Model_Store::DEFAULT_CODE;
if ($store != "") {
$store_code = $store;
}
$this->setData('is_feed', false);
$this->setData('log_messages', array());
try {
try {
$store_id = Mage::app()->getStore($store_code)->getStoreId();
} catch (Exception $e) {
Mage::throwException(sprintf('Store with code \'%s\' doesn\'t exists.', $store_code));
}
$Generator = Mage::getSingleton('googlebasefeedgenerator/tools')->addData(array('store_code' => $store_code))->getGenerator($store_id);
$messages[] = array('msg' => 'Store ' . Mage::app()->getStore($store_code)->getName(), 'type' => 'info');
/**
* @var $Generator RocketWeb_GoogleBaseFeedGenerator_Model_Generator
*/
if ($testmode) {
if ($limit > $Generator->getConfigVar('button_max_products', 'file')) {
$limit = $Generator->getConfigVar('button_max_products', 'file');
}
$this->setTestMode(true);
$Generator->setTestMode(true);
if ($sku) {
$Generator->setTestSku($sku);
$this->setTestSku($sku);
} elseif ($offset >= 0 && $limit > 0) {
$Generator->setTestOffset($offset);
$this->setTestOffset($offset);
$Generator->setTestLimit($limit);
$this->setTestLimit($limit);
} else {
Mage::throwException(sprintf("Invalid parameters for test mode: sku %s or offset %s and limit %s", $sku, $offset, $limit));
}
$messages[] = array('msg' => 'Test mode.', 'type' => 'info');
} else {
$this->setTestMode(false);
}
if (!$Generator->getConfig()->isEnabled($Generator->getStoreId())) {
$messages[] = array('msg' => 'Extension is disabled, cannot generate feed.', 'type' => 'error');
$this->setData('messages', $messages);
return;
}
if (!$this->getTestMode()) {
$collection = $Generator->getCollection();
$count = $collection->getSize();
if ($count > $Generator->getConfigVar('button_max_products', 'file')) {
Mage::throwException(sprintf("Too many products to generate a full feed through web server. Detected %d products more than the limit allowed of %d. <br />Magento Cron will generate the feed over night. If you need to generate the feed right now, run the shell script \"php shell/gsf_generate.php\" in a sever console.", $count, $Generator->getConfigVar('button_max_products', 'file')));
}
}
// Generate feed - costly process.
$Generator->run();
if ($Generator->getCountProductsExported() > 0) {
$this->setData('is_feed', true);
}
} catch (Exception $e) {
$messages[] = array('msg' => 'Error:<br />' . $e->getMessage(), 'type' => 'error');
}
$count_products = 0;
$count_skipped = 0;
if (isset($Generator) && is_object($Generator) && $Generator instanceof RocketWeb_GoogleBaseFeedGenerator_Model_Generator) {
$count_products = $Generator->getCountProductsExported();
$count_skipped = $Generator->getCountProductsSkipped();
}
$feed_data = array();
if ($this->getIsFeed() && $sku != "" && $count_products > 0 && file_exists($Generator->getFeedPath())) {
/* tsv file */
$csv = new Varien_File_Csv();
$csv->setDelimiter("\t");
$csv->setEnclosure('~');
// dummy enclosure
$rows = $csv->getData($Generator->getFeedPath());
$i = 0;
foreach ($rows as $row) {
if ($i == 0) {
$i++;
continue;
}
$feed_data[] = array_combine($rows[0], $row);
$i++;
}
}
$this->setFeedData($feed_data);
//.........这里部分代码省略.........