5

A simple question with no hits on Google.

What are the characters that are allowed in a SKU? The entire UTF-8 character set?

4

Diving into the core code... The validation starts at Mage_Catalog_Model_Product_Attribute_Backend_Sku and simply checks the length to make sure it's less than 64 characters long...

/**
 * Validate SKU
 *
 * @param Mage_Catalog_Model_Product $object
 * @throws Mage_Core_Exception
 * @return bool
 */
public function validate($object)
{
    $helper = Mage::helper('core/string');

    if ($helper->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
        Mage::throwException(
            Mage::helper('catalog')->__('SKU length should be %s characters maximum.', self::SKU_MAX_LENGTH)
        );
    }
    return parent::validate($object);
}

Then proceeds to call through to its parent's method... That only checks for uniqueness and requiredness of the attribute.

/**
 * Validate object
 *
 * @param Varien_Object $object
 * @throws Mage_Eav_Exception
 * @return boolean
 */
public function validate($object)
{
    $attrCode = $this->getAttribute()->getAttributeCode();
    $value = $object->getData($attrCode);
    if ($this->getAttribute()->getIsRequired() && $this->getAttribute()->isValueEmpty($value)) {
        return false;
    }

    if ($this->getAttribute()->getIsUnique()
        && !$this->getAttribute()->getIsRequired()
        && ($value == '' || $this->getAttribute()->isValueEmpty($value)))
    {
        return true;
    }

    if ($this->getAttribute()->getIsUnique()) {
        if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) {
            $label = $this->getAttribute()->getFrontend()->getLabel();
            throw Mage::exception('Mage_Eav',
                Mage::helper('eav')->__('The value of attribute "%s" must be unique', $label)
            );
        }
    }

    return true;
}

So apparently, to the Magento Core team, anything goes for a SKU so long as it's under 64 characters, non-null, and unique. I suppose the underlying database type is also a consideration as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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