In Magento, when creating a new product, you can manually type in a SKU number. Later, you could decide to change this SKU number to a different number. Is there a way to disallow this in Magento? Once a SKU number is assigned, I want that to always be the SKU — I don’t want to allow my users to assign a different SKU instead.
Share
I can think of two approaches: event observer and a custom attribute backend model for the SKU attribute, the latter being the more thorough solution.
For the event observer it is possible to observe compare the value for the SKU property, see if it is changed, and set it to the original with a warning message. This should suffice unless the SKU attribute is saved using
saveAttribute(), etc.It is also possible to do the same logic in an EAV attribute backend model, which can easily be assigned to the attribute via a setup script. However, in the case of the SKU attribute, it already has a backend model,
Mage_Catalog_Model_Product_Attribute_Backend_Sku[link]. It would be quite easy to rewrite thevalidate()method using standard Magento class rewrites, add the desired value protection logic, and then call the parent method – making the solution quite portable.And, whereas the backend model is used regardless of save via
save()orsaveAttribute(), this will ensure that all saves via the admin backend will be processed according to your logic.