00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Adminhtml entity sets controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 00035 class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Controller_Action 00036 { 00037 public function indexAction() 00038 { 00039 $this->_setTypeId(); 00040 00041 $this->loadLayout(); 00042 $this->_setActiveMenu('catalog/sets'); 00043 00044 $this->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')); 00045 $this->_addBreadcrumb(Mage::helper('catalog')->__('Manage Attribute Sets'), Mage::helper('catalog')->__('Manage Attribute Sets')); 00046 00047 $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_toolbar_main')); 00048 $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_grid')); 00049 00050 $this->renderLayout(); 00051 } 00052 00053 public function editAction() 00054 { 00055 $this->_setTypeId(); 00056 $attributeSet = Mage::getModel('eav/entity_attribute_set') 00057 ->load($this->getRequest()->getParam('id')); 00058 00059 if (!$attributeSet->getId()) { 00060 $this->_redirect('*/*/index'); 00061 return; 00062 } 00063 00064 Mage::register('current_attribute_set', $attributeSet); 00065 00066 $this->loadLayout(); 00067 $this->_setActiveMenu('catalog/sets'); 00068 $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); 00069 00070 $this->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')); 00071 $this->_addBreadcrumb(Mage::helper('catalog')->__('Manage Product Sets'), Mage::helper('catalog')->__('Manage Product Sets')); 00072 00073 $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main')); 00074 00075 $this->renderLayout(); 00076 } 00077 00078 public function setGridAction() 00079 { 00080 $this->_setTypeId(); 00081 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_grid')->toHtml()); 00082 } 00083 00084 public function saveAction() 00085 { 00086 $this->_setTypeId(); 00087 $response = new Varien_Object(); 00088 $response->setError(0); 00089 00090 $modelSet = Mage::getModel('eav/entity_attribute_set') 00091 ->setId($this->getRequest()->getParam('id')) 00092 ->setEntityTypeId(Mage::registry('entityType')); 00093 00094 if( $this->getRequest()->getParam('gotoEdit') ) { 00095 $modelSet = Mage::getModel('eav/entity_attribute_set'); 00096 $modelSet->setAttributeSetName($this->getRequest()->getParam('attribute_set_name')) 00097 ->setEntityTypeId(Mage::registry('entityType')); 00098 } else { 00099 $data = Zend_Json_Decoder::decode($this->getRequest()->getPost('data')); 00100 $modelSet->organizeData($data); 00101 } 00102 00103 try { 00104 $modelSet->validate($modelSet->getAttributeSetName()); 00105 $modelSet->save(); 00106 if( $this->getRequest()->getParam('gotoEdit') == 1 ) { 00107 $modelSet->initFromSkeleton($this->getRequest()->getParam('skeleton_set')) 00108 ->save(); 00109 00110 $this->_redirect('*/*/edit', array('id' => $modelSet->getId())); 00111 $this->_getSession()->addSuccess($this->__('Attribute set successfully saved.')); 00112 } else { 00113 $this->_getSession()->addSuccess($this->__('Attribute set successfully saved.')); 00114 // $this->_initLayoutMessages('adminhtml/session'); 00115 // $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); 00116 $response->setUrl($this->getUrl('*/*/edit', array('id' => $modelSet->getId()))); 00117 //$this->_redirect('*/*/'); Why? there is Ajax. 00118 } 00119 } 00120 catch (Exception $e) { 00121 $this->_getSession()->addError($e->getMessage()); 00122 if( $this->getRequest()->getParam('gotoEdit') == 1 ) { 00123 $this->_redirectReferer(); 00124 } else { 00125 $this->_initLayoutMessages('adminhtml/session'); 00126 $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); 00127 $response->setError(1); 00128 } 00129 } 00130 if( $this->getRequest()->getParam('gotoEdit') != 1 ) { 00131 $this->getResponse()->setBody($response->toJson()); 00132 } 00133 } 00134 00135 public function addAction() 00136 { 00137 $this->_setTypeId(); 00138 00139 $this->loadLayout(); 00140 $this->_setActiveMenu('catalog/sets'); 00141 00142 $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_toolbar_add')); 00143 00144 $this->renderLayout(); 00145 } 00146 00147 public function deleteAction() 00148 { 00149 $setId = $this->getRequest()->getParam('id'); 00150 try { 00151 Mage::getModel('eav/entity_attribute_set') 00152 ->setId($setId) 00153 ->delete(); 00154 00155 $this->_getSession()->addSuccess($this->__('Attribute set was successfully removed.')); 00156 $this->getResponse()->setRedirect($this->getUrl('*/*/')); 00157 } catch (Exception $e) { 00158 $this->_getSession()->addError($this->__('Error while deleting this set.')); 00159 $this->_redirectReferer(); 00160 } 00161 } 00162 00163 protected function _setTypeId() 00164 { 00165 Mage::register('entityType', 00166 Mage::getModel('catalog/product')->getResource()->getTypeId()); 00167 } 00168 00169 protected function _isAllowed() 00170 { 00171 return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/sets'); 00172 } 00173 }