Exemplo n.º 1
0
 /**
  * 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();
     $dateValid = true;
     if ($this->_dateExists()) {
         if ($this->useCalendar()) {
             $dateValid = isset($value['date']) && preg_match('/^[0-9]{1,4}.+[0-9]{1,4}.+[0-9]{1,4}$/', $value['date']);
         } else {
             $dateValid = isset($value['day']) && isset($value['month']) && isset($value['year']) && $value['day'] > 0 && $value['month'] > 0 && $value['year'] > 0;
         }
     }
     $timeValid = true;
     if ($this->_timeExists()) {
         $timeValid = isset($value['hour']) && isset($value['minute']) && is_numeric($value['hour']) && is_numeric($value['minute']);
     }
     $isValid = $dateValid && $timeValid;
     if ($isValid) {
         $this->setUserValue(array('date' => isset($value['date']) ? $value['date'] : '', 'year' => isset($value['year']) ? intval($value['year']) : 0, 'month' => isset($value['month']) ? intval($value['month']) : 0, 'day' => isset($value['day']) ? intval($value['day']) : 0, 'hour' => isset($value['hour']) ? intval($value['hour']) : 0, 'minute' => isset($value['minute']) ? intval($value['minute']) : 0, 'day_part' => isset($value['day_part']) ? $value['day_part'] : '', 'date_internal' => isset($value['date_internal']) ? $value['date_internal'] : ''));
     } elseif (!$isValid && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
         $this->setIsValid(false);
         if (!$dateValid) {
             Mage::throwException(Mage::helper('catalog')->__('Please specify date required option(s)'));
         } elseif (!$timeValid) {
             Mage::throwException(Mage::helper('catalog')->__('Please specify time required option(s)'));
         } else {
             Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)'));
         }
     } else {
         $this->setUserValue(null);
         return $this;
     }
     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 = trim($this->getUserValue());
     if (strlen($value) == 0 && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) {
         $this->setIsValid(false);
         Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)'));
     }
     if (strlen($value) > $option->getMaxCharacters() && $option->getMaxCharacters() > 0) {
         $this->setIsValid(false);
         Mage::throwException(Mage::helper('catalog')->__('Length of text is too long'));
     }
     $this->setUserValue($value);
     return $this;
 }
Exemplo n.º 3
0
 /**
  * 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());
     // Check requires option to have some value
     if (strlen($value) == 0 && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
         $this->setIsValid(false);
         Mage::throwException(Mage::helper('catalog')->__('Please specify the product\'s required option(s).'));
     }
     // Check maximal length limit
     $maxCharacters = $option->getMaxCharacters();
     if ($maxCharacters > 0 && Mage::helper('core/string')->strlen($value) > $maxCharacters) {
         $this->setIsValid(false);
         Mage::throwException(Mage::helper('catalog')->__('The text is too long'));
     }
     $this->setUserValue($value);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * 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($this->_getWrongConfigurationMessage());
                     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($this->_getWrongConfigurationMessage());
             }
             return '';
         }
     } else {
         $result = parent::getOptionSku($optionValue, $skuDelimiter);
     }
     return $result;
 }
 /**
  * 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 don\'t 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 don\'t 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;
 }
Exemplo n.º 6
0
 /**
  * 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)->getSku()) {
                 $skus[] = $optionSku;
             }
         }
         $result = implode($skuDelimiter, $skus);
     } elseif ($this->_isSingleSelection()) {
         $result = $option->getValueById($optionValue)->getSku();
     } else {
         $result = parent::getOptionSku($optionValue, $skuDelimiter);
     }
     return $result;
 }