/** * 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; }
/** * Return SKU for selected option * * @param string $optionValue Prepared for cart option value * @param string $skuDelimiter Delimiter for Sku parts * @return string */ public function getOptionSku($optionValue, $skuDelimiter) { $option = $this->getOption(); if (!$this->_isSingleSelection()) { $skus = array(); foreach (explode(',', $optionValue) as $value) { if ($optionSku = $option->getValueById($value)) { $skus[] = $optionSku->getSku(); } else { if ($this->getListener()) { $this->getListener()->setHasError(true)->setMessage(Mage::helper('catalog')->__('Some of the products below do not have all the required options. Please remove them and add again with all the required options.')); break; } } } $result = implode($skuDelimiter, $skus); } elseif ($this->_isSingleSelection()) { if ($result = $option->getValueById($optionValue)) { return $result->getSku(); } else { if ($this->getListener()) { $this->getListener()->setHasError(true)->setMessage(Mage::helper('catalog')->__('Some of the products below do not have all the required options. Please remove them and add again with all the required options.')); } return ''; } } else { $result = parent::getOptionSku($optionValue, $skuDelimiter); } return $result; }