I need my users not able to edit attributes, but they can view the attributes.
2 Answers
If you are talking about attribute when editing products read here: Read-Only Product Backend attribute
Edit: to make based on usesr permissions you can try this:
- create custom module
add new ACL permission in
adminhtml.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <acl> <resources> <admin> <children> <catalog> <children> <products> <children> <edit_locked_attributes translate="title" module="stackexchange_lockattributes"> <title>Edit Locked Attributes</title> <sort_order>100</sort_order> </edit_locked_attributes> </children> </products> </children> </catalog> </children> </admin> </resources> </acl> </config>
Add an observer to
config.xml
<events> <catalog_product_edit_action> <observers> <lock_attributes> <type>singleton</type> <class>stackexchange_lockattributes/observer</class> <method>lockProductAttributes</method> </lock_attributes> </observers> </catalog_product_edit_action> </events>
Observer.php
class StackExchange_LockAttributes_Model_Observer { /** * Make product attributes uneditable * * @param Varien_Event_Observer $observer * @return void */ public function lockProductAttributes(Varien_Event_Observer $observer) { if (!$this->_isAllowed()) { /* @var Mage_Catalog_Model_Product $product */ $product = $observer->getProduct(); $attributes = explode(',', Mage::getStoreConfig('catalog/backend/lock_attributes', $product->getStoreId())); if (count($attributes)) { foreach ($attributes as $attributeCode) { $product->lockAttribute($attributeCode); } } } } /** * Check admin permissions for locked attributes */ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('catalog/products/edit_locked_attributes'); } }
add config section to make it a bit flexible ...
Download: https://github.com/sreichel/magento-StackExchange_LockAttributes
-
-
-
1Not tried, but I guess you can use
catalog_product_attribute_edit_action
then.– sv3nJan 31, 2018 at 11:39 -
1@zus can you please give some feedback here first? Those this answer your question?– sv3nFeb 28, 2018 at 12:00
-
1Thanks @sv3n you helped me alot! Great work! (I know that "thank you" answers are not wanted, but I had to;) you can delete it if you want– artgroheJul 13, 2018 at 12:42
You can write observer for admin edit action of attributes and allow to save only if the current admin login user is "Superadmin".
You can use:
catalog_product_attribute_update_before
event for this purpose.
Just go through Magento docs regarding events and observers.