/** * Validate SKU * * @param array $field Feild info * * @return array */ protected function validateSku(array $field) { $result = array(true, null); try { $product = $this->getEntity(); $validator = new \XLite\Core\Validator\SKU($product ? $product->getProductId() : null); $validator->validate($field['widget']->getValue()); } catch (\Exception $e) { $result = array(false, $e->getMessage()); } return $result; }
/** * Check field validity * * @return boolean */ protected function checkFieldValidity() { $result = parent::checkFieldValidity(); if ($result && $this->getValue()) { $validator = new \XLite\Core\Validator\SKU($this->getProductId()); try { $validator->validate($this->getValue()); } catch (\XLite\Core\Validator\Exception $exception) { $message = static::t($exception->getMessage(), $exception->getLabelArguments()); $result = false; $this->errorMessage = \XLite\Core\Translation::lbl(($exception->getPublicName() ? static::t($exception->getPublicName()) . ': ' : '') . $message, array('name' => $this->getLabel())); } } return $result; }