00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_UrlrewriteController extends Mage_Adminhtml_Controller_Action
00035 {
00036
00037
00038
00039
00040
00041 protected function _initRegistry()
00042 {
00043
00044 Mage::register('current_urlrewrite', Mage::getModel('core/url_rewrite')
00045 ->load($this->getRequest()->getParam('id', 0))
00046 );
00047 $productId = $this->getRequest()->getParam('product', 0);
00048 $categoryId = $this->getRequest()->getParam('category', 0);
00049 if (Mage::registry('current_urlrewrite')->getId()) {
00050 $productId = Mage::registry('current_urlrewrite')->getProductId();
00051 $categoryId = Mage::registry('current_urlrewrite')->getCategoryId();
00052 }
00053
00054 Mage::register('current_product', Mage::getModel('catalog/product')->load($productId));
00055 Mage::register('current_category', Mage::getModel('catalog/category')->load($categoryId));
00056
00057 return $this;
00058 }
00059
00060
00061
00062
00063
00064 public function indexAction()
00065 {
00066 $this->loadLayout();
00067 $this->_setActiveMenu('catalog/urlrewrite');
00068 $this->_initRegistry();
00069 $this->_addContent(
00070 $this->getLayout()->createBlock('adminhtml/urlrewrite')
00071 );
00072 $this->renderLayout();
00073 }
00074
00075
00076
00077
00078
00079 public function editAction()
00080 {
00081 $this->loadLayout();
00082 $this->_setActiveMenu('catalog/urlrewrite');
00083 $this->_initRegistry();
00084 $this->_addContent($this->getLayout()->createBlock('adminhtml/urlrewrite_edit'));
00085 $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00086 $this->renderLayout();
00087 }
00088
00089
00090
00091
00092
00093 public function productGridAction()
00094 {
00095 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/urlrewrite_product_grid')->toHtml());
00096 }
00097
00098
00099
00100
00101
00102 public function categoriesJsonAction()
00103 {
00104 $id = $this->getRequest()->getParam('id', null);
00105 $this->getResponse()->setBody(Mage::getBlockSingleton('adminhtml/urlrewrite_category_tree')
00106 ->getTreeArray($id, true, 1)
00107 );
00108 }
00109
00110
00111
00112
00113
00114 public function saveAction()
00115 {
00116 $this->_initRegistry();
00117
00118 if ($data = $this->getRequest()->getPost()) {
00119 try {
00120
00121 $model = Mage::registry('current_urlrewrite');
00122
00123 $model->setIdPath($this->getRequest()->getParam('id_path'))
00124 ->setTargetPath($this->getRequest()->getParam('target_path'))
00125 ->setOptions($this->getRequest()->getParam('options'))
00126 ->setDescription($this->getRequest()->getParam('description'))
00127 ->setRequestPath($this->getRequest()->getParam('request_path'))
00128 ;
00129 if (!$model->getId()) {
00130 $model->setIsSystem(0);
00131 }
00132 if (!$model->getIsSystem()) {
00133 $model->setStoreId($this->getRequest()->getParam('store_id', 0));
00134 }
00135
00136
00137 $category = Mage::registry('current_category')->getId() ? Mage::registry('current_category') : null;
00138 if ($category) {
00139 $model->setCategoryId($category->getId());
00140 }
00141 $product = Mage::registry('current_product')->getId() ? Mage::registry('current_product') : null;
00142 if ($product) {
00143 $model->setProductId($product->getId());
00144 }
00145 if ($product || $category) {
00146 $catalogUrlModel = Mage::getSingleton('catalog/url');
00147 $model->setIdPath($catalogUrlModel->generatePath('id', $product, $category));
00148 $model->setTargetPath($catalogUrlModel->generatePath('target', $product, $category));
00149 }
00150
00151
00152 $model->save();
00153 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__(
00154 'Urlrewrite has been successfully saved'
00155 ));
00156 $this->_redirect('*/*/');
00157 return;
00158 }
00159 catch (Exception $e) {
00160 Mage::getSingleton('adminhtml/session')
00161 ->addError($e->getMessage())
00162 ->setUrlrewriteData($data)
00163 ;
00164
00165 }
00166 }
00167 $this->_redirectReferer();
00168 }
00169
00170
00171
00172
00173
00174 public function deleteAction()
00175 {
00176 $this->_initRegistry();
00177
00178 if (Mage::registry('current_urlrewrite')->getId()) {
00179 try {
00180 Mage::registry('current_urlrewrite')->delete();
00181 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__(
00182 'Urlrewrite has been successfully deleted'
00183 ));
00184 }
00185 catch (Exception $e) {
00186 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00187 $this->_redirectReferer();
00188 return;
00189 }
00190 }
00191 $this->_redirect('*/*/');
00192 }
00193
00194
00195
00196
00197
00198
00199 protected function _isAllowed()
00200 {
00201 return Mage::getSingleton('admin/session')->isAllowed('catalog/urlrewrite');
00202 }
00203 }