How to lock a product attribute in backend

Magento

Sometimes, for example when products are imported/updated in magento database by outside process, we not want that magento admin user to be able to change some attributes, like sku for example that could interfere with that process.

For acomplish this we can lock any product attribute by using lockAttribure method located in Mage_Catalog_Model_Abstract class.

 

An locked attribute is visible in backend but is not editable, and his value cannot be saved. If we want to lock an attribute on edit we can made a methos like bellow and call that method on edit event.

 

    public function lockSku($product){
       $product->lockAttribute('sku');  
    } 

 

If we want to lock attribute only on creating product action or all the time (update/insert/view), can be used same method but called in other part of execution flow.

Also if we want at some point in execution process to unlock some specific attribute we have method unlockAttribute available, used in same way as lockAttribute method but with opposite effect.


Add comment
 
 
 

Comments