I have just created a custom attribute (standard text field) on a simple product. I'd like to limit this field to 80 characters as it's to be used as an eBay title to integrate with eBay.

I only want to limit this field though, not all text fields.

Can someone advise how I can do this?


3 Answers 3


To my knowledge Magento does not allow the limiting of lengths for EAV attributes. For a varchar this gets stored in the table catalog_product_entity_varchar which has the definition value => varchar(255).

One option you could do is to add a backend model for this attribute. In this model you could write your own beforeSave function that will process the length of given value and trim it to be the desired length. The class should extend Mage_Eav_Model_Entity_Attribute_Backend_Abstract

public function beforeSave($object)
    $attrCode = $this->getAttribute()->getAttributeCode();
    if ($object->hasData($attrCode)) {
        $object->setData($attrCode, substr($object->getData($attrCode),0,50));
    return $this;

If you want to avoid any custom editing for each attribute, there is a module that builds this into Magento for you. It allows you to have a Limit or a Minimum number of Characters for any attribute. All editable at the "Edit Product Attribute" screen in Magento:



Try this

$string = $product->getData($attribute_code);

echo substr($string, 0, 80);

Your Answer

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

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