/** * Validate user input for option * * @throws Mage_Core_Exception * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) * @return Mage_Catalog_Model_Product_Option_Type_Default */ public function validateUserValue($values) { parent::validateUserValue($values); $option = $this->getOption(); $value = trim($this->getUserValue()); if (strlen($value) == 0 && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) { $this->setIsValid(false); Mage::throwException(Mage::helper('catalog')->__('Please specify the product\'s required option(s).')); } if (strlen($value) > $option->getMaxCharacters() && $option->getMaxCharacters() > 0) { $this->setIsValid(false); Mage::throwException(Mage::helper('catalog')->__('The text is too long')); } $this->setUserValue($value); return $this; }
/** * Validate user input for option * * @throws Mage_Core_Exception * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) * @return Mage_Catalog_Model_Product_Option_Type_Default */ public function validateUserValue($values) { parent::validateUserValue($values); $option = $this->getOption(); $value = $this->getUserValue(); if (empty($value) && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) { $this->setIsValid(false); Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s).')); } if (!$this->_isSingleSelection()) { $valuesCollection = $option->getOptionValuesByOptionId($value, $this->getProduct()->getStoreId())->load(); if ($valuesCollection->count() != count($value)) { $this->setIsValid(false); Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s).')); } } return $this; }