magento pdf打印分类产品,选择分类,打印分类下的产品为pdf格式
选择筛选属性,点击分类 即可下载pdf,pdf包含产品数据
app\code\More\Pdfproduct\controllers CategoryController.php
<?php
class More_Pdfproduct_CategoryController extends Mage_Core_Controller_Front_Action {
protected function _initCategoryLayout()
{
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$this->loadLayoutUpdates();
$this->generateLayoutXml()->generateLayoutBlocks();
$this->renderLayout();
}
public function viewAction()
{
$categoryId = (int) $this->getRequest()->getParam('id', false);
if ($categoryId) {
$this->_initCategoryLayout();
}
elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
}
public function printAction()
{
$categoryId = (int) $this->getRequest()->getParam('id', false);
if ($categoryId) {
$this->_initCategoryLayout();
$root = $this->getLayout()->getBlock('root');
$html = $root->toHtml();
$category = Mage::getModel('catalog/category')->load($categoryId);
Mage::helper('pdfproduct/print')->PDFFrontendStreamToBrowser($html,$category->getUrl_key());
}
elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
}
public function saveAction()
{
$categoryId = (int) $this->getRequest()->getParam('id', false);
if ($categoryId) {
$this->_initCategoryLayout();
$root = $this->getLayout()->getBlock('root');
$html = $root->toHtml();
$category = Mage::getModel('catalog/category')->load($categoryId);
Mage::helper('pdfproduct/print')->PDFFrontendSaveFile($html,$category->getUrl_key());
$this->getResponse()->setRedirect($this->_getRefererUrl());
return;
}
elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
}
}
|