Mage_Adminhtml_Catalog_Product_AttributeController Class Reference

Inheritance diagram for Mage_Adminhtml_Catalog_Product_AttributeController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 preDispatch ()
 indexAction ()
 newAction ()
 editAction ()
 validateAction ()
 saveAction ()
 deleteAction ()

Protected Member Functions

 _initAction ()
 _isAllowed ()

Protected Attributes

 $_entityTypeId


Detailed Description

Definition at line 35 of file AttributeController.php.


Member Function Documentation

_initAction (  )  [protected]

Definition at line 46 of file AttributeController.php.

00047     {
00048         if($this->getRequest()->getParam('popup')) {
00049             $this->loadLayout('popup');
00050         } else {
00051             $this->loadLayout()
00052                 ->_setActiveMenu('catalog/attributes')
00053                 ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog'))
00054                 ->_addBreadcrumb(Mage::helper('catalog')->__('Manage Product Attributes'), Mage::helper('catalog')->__('Manage Product Attributes'))
00055             ;
00056         }
00057         return $this;
00058     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 253 of file AttributeController.php.

00254     {
00255         return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/attributes');
00256     }

deleteAction (  ) 

Definition at line 224 of file AttributeController.php.

00225     {
00226         if ($id = $this->getRequest()->getParam('attribute_id')) {
00227             $model = Mage::getModel('catalog/entity_attribute');
00228 
00229             // entity type check
00230             $model->load($id);
00231             if ($model->getEntityTypeId() != $this->_entityTypeId) {
00232                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('You cannot delete this attribute'));
00233                 $this->_redirect('*/*/');
00234                 return;
00235             }
00236 
00237             try {
00238                 $model->delete();
00239                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Product attribute was successfully deleted'));
00240                 $this->_redirect('*/*/');
00241                 return;
00242             }
00243             catch (Exception $e) {
00244                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00245                 $this->_redirect('*/*/edit', array('attribute_id' => $this->getRequest()->getParam('attribute_id')));
00246                 return;
00247             }
00248         }
00249         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Unable to find an attribute to delete'));
00250         $this->_redirect('*/*/');
00251     }

editAction (  ) 

Definition at line 72 of file AttributeController.php.

00073     {
00074         $id = $this->getRequest()->getParam('attribute_id');
00075         $model = Mage::getModel('catalog/entity_attribute');
00076 
00077         if ($id) {
00078             $model->load($id);
00079 
00080             if (! $model->getId()) {
00081                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('This attribute no longer exists'));
00082                 $this->_redirect('*/*/');
00083                 return;
00084             }
00085 
00086             // entity type check
00087             if ($model->getEntityTypeId() != $this->_entityTypeId) {
00088                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('You cannot edit this attribute'));
00089                 $this->_redirect('*/*/');
00090                 return;
00091             }
00092         }
00093 
00094         // set entered data if was error when we do save
00095         $data = Mage::getSingleton('adminhtml/session')->getAttributeData(true);
00096         if (! empty($data)) {
00097             $model->setData($data);
00098         }
00099 
00100         Mage::register('entity_attribute', $model);
00101 
00102         $this->_initAction()
00103             ->_addBreadcrumb($id ? Mage::helper('catalog')->__('Edit Product Attribute') : Mage::helper('catalog')->__('New Product Attribute'), $id ? Mage::helper('catalog')->__('Edit Product Attribute') : Mage::helper('catalog')->__('New Product Attribute'))
00104             ->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_edit')->setData('action', $this->getUrl('*/catalog_product_attribute/save')))
00105             ->_addLeft($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_edit_tabs'))
00106             ->_addJs(
00107                 $this->getLayout()->createBlock('adminhtml/template')
00108                     ->setIsPopup((bool)$this->getRequest()->getParam('popup'))
00109                     ->setTemplate('catalog/product/attribute/js.phtml')
00110             )
00111             ->renderLayout();
00112     }

indexAction (  ) 

Definition at line 60 of file AttributeController.php.

00061     {
00062         $this->_initAction()
00063             ->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute'))
00064             ->renderLayout();
00065     }

newAction (  ) 

Definition at line 67 of file AttributeController.php.

00068     {
00069         $this->_forward('edit');
00070     }

preDispatch (  ) 

Controller predispatch method

Returns:
Mage_Adminhtml_Controller_Action

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 40 of file AttributeController.php.

00041     {
00042         parent::preDispatch();
00043         $this->_entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
00044     }

saveAction (  ) 

Todo:
need specify relations for properties

Clear translation cache because attribute labels are stored in translation

Definition at line 134 of file AttributeController.php.

00135     {
00136         if ($data = $this->getRequest()->getPost()) {
00137             $redirectBack   = $this->getRequest()->getParam('back', false);
00138             $model = Mage::getModel('catalog/entity_attribute');
00139             /* @var $model Mage_Catalog_Model_Entity_Attribute */
00140 
00141             if ($id = $this->getRequest()->getParam('attribute_id')) {
00142 
00143                 $model->load($id);
00144 
00145                 // entity type check
00146                 if ($model->getEntityTypeId() != $this->_entityTypeId) {
00147                     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('You cannot update this attribute'));
00148                     Mage::getSingleton('adminhtml/session')->setAttributeData($data);
00149                     $this->_redirect('*/*/');
00150                     return;
00151                 }
00152 
00153                 $data['attribute_code'] = $model->getAttributeCode();
00154                 $data['is_user_defined'] = $model->getIsUserDefined();
00155                 $data['frontend_input'] = $model->getFrontendInput();
00156             }
00157 
00158             if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
00159                 $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
00160             }
00161 
00162             $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
00163             if ($defaultValueField) {
00164                 $data['default_value'] = $this->getRequest()->getParam($defaultValueField);
00165             }
00166 
00167             if(!isset($data['apply_to'])) {
00168                 $data['apply_to'] = array();
00169             }
00170 
00171             /**
00172              * @todo need specify relations for properties
00173              */
00174             if (isset($data['frontend_input']) && $data['frontend_input'] == 'multiselect') {
00175                 $data['backend_model'] = 'eav/entity_attribute_backend_array';
00176             }
00177 
00178             $model->addData($data);
00179 
00180 
00181             if (!$id) {
00182                 $model->setEntityTypeId($this->_entityTypeId);
00183                 $model->setIsUserDefined(1);
00184             }
00185 
00186 
00187             if($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) {
00188                 // For creating product attribute on product page we need specify attribute set and group
00189                 $model->setAttributeSetId($this->getRequest()->getParam('set'));
00190                 $model->setAttributeGroupId($this->getRequest()->getParam('group'));
00191             }
00192 
00193             try {
00194                 $model->save();
00195                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Product attribute was successfully saved'));
00196 
00197                 /**
00198                  * Clear translation cache because attribute labels are stored in translation
00199                  */
00200                 Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
00201                 Mage::getSingleton('adminhtml/session')->setAttributeData(false);
00202                 if ($this->getRequest()->getParam('popup')) {
00203                     $this->_redirect('adminhtml/catalog_product/addAttribute', array(
00204                         'id'       => $this->getRequest()->getParam('product'),
00205                         'attribute'=> $model->getId(),
00206                         '_current' => true
00207                     ));
00208                 } elseif ($redirectBack) {
00209                     $this->_redirect('*/*/edit', array('attribute_id' => $model->getId(),'_current'=>true));
00210                 } else {
00211                     $this->_redirect('*/*/', array());
00212                 }
00213                 return;
00214             } catch (Exception $e) {
00215                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00216                 Mage::getSingleton('adminhtml/session')->setAttributeData($data);
00217                 $this->_redirect('*/*/edit', array('_current' => true));
00218                 return;
00219             }
00220         }
00221         $this->_redirect('*/*/');
00222     }

validateAction (  ) 

Definition at line 114 of file AttributeController.php.

00115     {
00116         $response = new Varien_Object();
00117         $response->setError(false);
00118 
00119         $attributeCode  = $this->getRequest()->getParam('attribute_code');
00120         $attributeId    = $this->getRequest()->getParam('attribute_id');
00121         $attribute = Mage::getModel('catalog/entity_attribute')
00122             ->loadByCode($this->_entityTypeId, $attributeCode);
00123 
00124         if ($attribute->getId() && !$attributeId) {
00125             Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Attribute with the same code already exists'));
00126             $this->_initLayoutMessages('adminhtml/session');
00127             $response->setError(true);
00128             $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
00129         }
00130 
00131         $this->getResponse()->setBody($response->toJson());
00132     }


Member Data Documentation

$_entityTypeId [protected]

Definition at line 38 of file AttributeController.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:10 2009 for Magento by  doxygen 1.5.8