1

I would like to disable a field in magento admin at default level.

The reason for this is I have built a bespoke stock integration which will overwrite the default values regularly.

I will populate the fields at "store view" level.

Things I have tried:

$installer->updateAttribute('catalog_product', 'name', 'readonly', 1);
$installer->updateAttribute('catalog_product', 'name', 'is_readonly', 1);
$installer->updateAttribute('catalog_product', 'name', 'disabled', 1);
$installer->updateAttribute('catalog_product', 'name', 'is_disabled', 1);

I understand that if this is possible I may not be able to make new products within Magento. I am ok with this due to the fact all sku's should be imported from our stock management.

2

1 Answer 1

3

This question / answers pointed me in the right direction:

https://stackoverflow.com/questions/6384120/magento-read-only-and-hidden-product-attributes

This function:

public function lockAttributes($observer) {
  $event = $observer->getEvent();
  $product = $event->getProduct();
  $product->lockAttribute('attribute_code');
}

in this observer:

catalog_product_edit_action

Then use the product object to find the store id:

$event = $observer->getEvent();
$product = $event->getProduct();
if ($product->getStoreId() == 0) {
  $product->lockAttribute('name');
}

This will only disable the attribute at the default store level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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