0

I need my users not able to edit attributes, but they can view the attributes.

2
  • 1
    best way is to create separate user and role and not to assign editing attributes to that user..... Jan 31, 2018 at 13:10
  • Hey, can you please accept an anwer, if you found a solution?
    – sv3n
    Oct 22, 2018 at 21:10

2 Answers 2

3

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:

  1. create custom module
  2. 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>
    
  3. 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>
    
  4. 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');
        }
    }
    
  5. add config section to make it a bit flexible ...


Download: https://github.com/sreichel/magento-StackExchange_LockAttributes

13
  • will it make attribute readonly for a particular user role?
    – Piyush
    Jan 31, 2018 at 11:32
  • No, its not role based.
    – sv3n
    Jan 31, 2018 at 11:33
  • 1
    Not tried, but I guess you can use catalog_product_attribute_edit_action then.
    – sv3n
    Jan 31, 2018 at 11:39
  • 1
    @zus can you please give some feedback here first? Those this answer your question?
    – sv3n
    Feb 28, 2018 at 12:00
  • 1
    Thanks @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
    – artgrohe
    Jul 13, 2018 at 12:42
2

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.